diff --git a/colab/search/fixtures/__init__.py b/colab/search/fixtures/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/search/fixtures/__init__.py diff --git a/colab/search/fixtures/test_data.json b/colab/search/fixtures/test_data.json new file mode 100644 index 0000000..e6d0f96 --- /dev/null +++ b/colab/search/fixtures/test_data.json @@ -0,0 +1,208 @@ +[ +{ + "fields": { + "logo": "", + "description": "", + "last_imported_index": 0, + "name": "ListA", + "email": "listA@example.com" + }, + "model": "super_archives.mailinglist", + "pk": 1 +}, +{ + "fields": { + "logo": "", + "description": "", + "last_imported_index": 0, + "name": "ListB", + "email": "listB@example.com" + }, + "model": "super_archives.mailinglist", + "pk": 2 +}, +{ + "fields": { + "logo": "", + "description": "", + "last_imported_index": 0, + "name": "ListC", + "email": "listC@example.com" + }, + "model": "super_archives.mailinglist", + "pk": 3 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_A", + "mailinglist": 1, + "score": 31, + "latest_message": 3 + }, + "model": "super_archives.thread", + "pk": 1 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_B", + "mailinglist": 2, + "score": 0, + "latest_message": 4 + }, + "model": "super_archives.thread", + "pk": 3 +}, +{ + "fields": { + "spam": false, + "subject_token": "Thread_1_on_List_C", + "mailinglist": 3, + "score": 0, + "latest_message": 5 + }, + "model": "super_archives.thread", + "pk": 4 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list A", + "received_time": "2015-01-28T12:43:00.752Z", + "from_address": 1, + "thread": 1, + "spam": false, + "subject_clean": "Response to Thread 1A", + "message_id": "loreipsum", + "subject": "Response to Thread 1A" + }, + "model": "super_archives.message", + "pk": 3 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list B", + "received_time": "2015-01-28T12:57:22.180Z", + "from_address": 1, + "thread": 3, + "spam": false, + "subject_clean": "Message 1 on Thread 1B", + "message_id": "", + "subject": "Message 1 on Thread 1B" + }, + "model": "super_archives.message", + "pk": 4 +}, +{ + "fields": { + "body": "This is a repply to Thread 1 on list C", + "received_time": "2015-01-28T13:02:12.903Z", + "from_address": 1, + "thread": 4, + "spam": false, + "subject_clean": "Message 1 on Thread 1C", + "message_id": "", + "subject": "Message 1 on Thread 1C" + }, + "model": "super_archives.message", + "pk": 5 +}, +{ + "fields": { + "last_name": "Administrator", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Admin", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "admin@mail.com", + "username": "admin", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 1 +}, +{ + "fields": { + "last_name": "Norris", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Chuck", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "chucknorris@mail.com", + "username": "chucknorris", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 2 +}, + +{ + "fields": { + "last_name": "Norris", + "webpage": "", + "twitter": "", + "is_staff": true, + "user_permissions": [], + "date_joined": "2015-01-28T12:34:58.770Z", + "google_talk": "", + "first_name": "Heisenberg", + "is_superuser": true, + "last_login": "2015-01-28T12:35:39.621Z", + "verification_hash": null, + "role": "", + "email": "heisenberg@mail.com", + "username": "heisenbergnorris", + "bio": "", + "needs_update": true, + "is_active": true, + "facebook": "", + "groups": [], + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", + "institution": "", + "github": "", + "modified": "2015-01-28T12:45:27.375Z" + }, + "model": "accounts.user", + "pk": 3 +}, +{ + "fields": { + "real_name": "Administrator", + "user": 1, + "md5": "edb0e96701c209ab4b50211c856c50c4", + "address": "admin@mail.com" + }, + "model": "super_archives.emailaddress", + "pk": 1 +} +] diff --git a/colab/search/tests.py b/colab/search/tests.py index 55be646..df85e92 100644 --- a/colab/search/tests.py +++ b/colab/search/tests.py @@ -1,4 +1,56 @@ -# uncomment the import if you really use. -# from django.test import TestCase +# -*- coding:utf-8 -*- -# Create your tests here. +from django.test import TestCase, Client +from django.core.management import call_command + + +class SearchViewTest(TestCase): + + fixtures = ['test_data.json'] + + def setUp(self): + call_command('update_index', interactive=False, verbosity=0) + self.client = Client() + + def tearDown(self): + call_command('clear_index', interactive=False,verbosity=0) + + def test_search_thread(self): + request = self.client.get('/search/?q=thread') + thread_list = request.context['page'].object_list + + self.assertEqual(3, len(thread_list)) + + self.assertIn('This is a repply to Thread 1 on list A', + thread_list[0].description) + self.assertIn('This is a repply to Thread 1 on list C', + thread_list[1].description) + self.assertIn('This is a repply to Thread 1 on list B', + thread_list[2].description) + + def test_search_account_by_firstName(self): + request = self.client.get('/search/?q=Chuck') + user_list = request.context['page'].object_list + + self.assertEqual(1, len(user_list)) + + self.assertIn('chucknorris@mail.com', user_list[0].object.email) + self.assertIn('Chuck', user_list[0].object.first_name) + self.assertIn('Norris', user_list[0].object.last_name) + self.assertIn('chucknorris', user_list[0].object.username) + + def test_search_account_by_lastName(self): + request = self.client.get('/search/?q=Norris') + user_list = request.context['page'].object_list + + self.assertEqual(2, len(user_list)) + + self.assertIn('heisenberg@mail.com', user_list[1].object.email) + self.assertIn('Heisenberg', user_list[1].object.first_name) + self.assertIn('Norris', user_list[1].object.last_name) + self.assertIn('heisenbergnorris', user_list[1].object.username) + + self.assertIn('chucknorris@mail.com', user_list[0].object.email) + self.assertIn('Chuck', user_list[0].object.first_name) + self.assertIn('Norris', user_list[0].object.last_name) + self.assertIn('chucknorris', user_list[0].object.username) diff --git a/setup.py b/setup.py index 5b1472d..b0879c2 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ REQUIREMENTS = [ 'python-dateutil==1.5', 'django-cliauth==0.9.1', 'django-mobile==0.3.0', - 'django-haystack==2.1', + 'django-haystack==2.2', 'pysolr==2.1', 'poster==0.8.1', 'etiquetando==0.1', diff --git a/tests/settings.py b/tests/settings.py index 0368e99..e8efd99 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -32,7 +32,8 @@ LOGGING = { import os HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', - 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), + 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', + 'URL': 'http://127.0.0.1:8983/solr' }, } + -- libgit2 0.21.2