Commit a5fb3168bdb312736140690a1bad99707ff77212
Exists in
master
and in
39 other branches
Merge branch 'haystack_tests' into 'master'
Haystack tests Added tests for haystack using Solr.
Showing
5 changed files
with
267 additions
and
6 deletions
Show diff stats
| @@ -0,0 +1,208 @@ | @@ -0,0 +1,208 @@ | ||
| 1 | +[ | ||
| 2 | +{ | ||
| 3 | + "fields": { | ||
| 4 | + "logo": "", | ||
| 5 | + "description": "", | ||
| 6 | + "last_imported_index": 0, | ||
| 7 | + "name": "ListA", | ||
| 8 | + "email": "listA@example.com" | ||
| 9 | + }, | ||
| 10 | + "model": "super_archives.mailinglist", | ||
| 11 | + "pk": 1 | ||
| 12 | +}, | ||
| 13 | +{ | ||
| 14 | + "fields": { | ||
| 15 | + "logo": "", | ||
| 16 | + "description": "", | ||
| 17 | + "last_imported_index": 0, | ||
| 18 | + "name": "ListB", | ||
| 19 | + "email": "listB@example.com" | ||
| 20 | + }, | ||
| 21 | + "model": "super_archives.mailinglist", | ||
| 22 | + "pk": 2 | ||
| 23 | +}, | ||
| 24 | +{ | ||
| 25 | + "fields": { | ||
| 26 | + "logo": "", | ||
| 27 | + "description": "", | ||
| 28 | + "last_imported_index": 0, | ||
| 29 | + "name": "ListC", | ||
| 30 | + "email": "listC@example.com" | ||
| 31 | + }, | ||
| 32 | + "model": "super_archives.mailinglist", | ||
| 33 | + "pk": 3 | ||
| 34 | +}, | ||
| 35 | +{ | ||
| 36 | + "fields": { | ||
| 37 | + "spam": false, | ||
| 38 | + "subject_token": "Thread_1_on_List_A", | ||
| 39 | + "mailinglist": 1, | ||
| 40 | + "score": 31, | ||
| 41 | + "latest_message": 3 | ||
| 42 | + }, | ||
| 43 | + "model": "super_archives.thread", | ||
| 44 | + "pk": 1 | ||
| 45 | +}, | ||
| 46 | +{ | ||
| 47 | + "fields": { | ||
| 48 | + "spam": false, | ||
| 49 | + "subject_token": "Thread_1_on_List_B", | ||
| 50 | + "mailinglist": 2, | ||
| 51 | + "score": 0, | ||
| 52 | + "latest_message": 4 | ||
| 53 | + }, | ||
| 54 | + "model": "super_archives.thread", | ||
| 55 | + "pk": 3 | ||
| 56 | +}, | ||
| 57 | +{ | ||
| 58 | + "fields": { | ||
| 59 | + "spam": false, | ||
| 60 | + "subject_token": "Thread_1_on_List_C", | ||
| 61 | + "mailinglist": 3, | ||
| 62 | + "score": 0, | ||
| 63 | + "latest_message": 5 | ||
| 64 | + }, | ||
| 65 | + "model": "super_archives.thread", | ||
| 66 | + "pk": 4 | ||
| 67 | +}, | ||
| 68 | +{ | ||
| 69 | + "fields": { | ||
| 70 | + "body": "This is a repply to Thread 1 on list A", | ||
| 71 | + "received_time": "2015-01-28T12:43:00.752Z", | ||
| 72 | + "from_address": 1, | ||
| 73 | + "thread": 1, | ||
| 74 | + "spam": false, | ||
| 75 | + "subject_clean": "Response to Thread 1A", | ||
| 76 | + "message_id": "loreipsum", | ||
| 77 | + "subject": "Response to Thread 1A" | ||
| 78 | + }, | ||
| 79 | + "model": "super_archives.message", | ||
| 80 | + "pk": 3 | ||
| 81 | +}, | ||
| 82 | +{ | ||
| 83 | + "fields": { | ||
| 84 | + "body": "This is a repply to Thread 1 on list B", | ||
| 85 | + "received_time": "2015-01-28T12:57:22.180Z", | ||
| 86 | + "from_address": 1, | ||
| 87 | + "thread": 3, | ||
| 88 | + "spam": false, | ||
| 89 | + "subject_clean": "Message 1 on Thread 1B", | ||
| 90 | + "message_id": "", | ||
| 91 | + "subject": "Message 1 on Thread 1B" | ||
| 92 | + }, | ||
| 93 | + "model": "super_archives.message", | ||
| 94 | + "pk": 4 | ||
| 95 | +}, | ||
| 96 | +{ | ||
| 97 | + "fields": { | ||
| 98 | + "body": "This is a repply to Thread 1 on list C", | ||
| 99 | + "received_time": "2015-01-28T13:02:12.903Z", | ||
| 100 | + "from_address": 1, | ||
| 101 | + "thread": 4, | ||
| 102 | + "spam": false, | ||
| 103 | + "subject_clean": "Message 1 on Thread 1C", | ||
| 104 | + "message_id": "", | ||
| 105 | + "subject": "Message 1 on Thread 1C" | ||
| 106 | + }, | ||
| 107 | + "model": "super_archives.message", | ||
| 108 | + "pk": 5 | ||
| 109 | +}, | ||
| 110 | +{ | ||
| 111 | + "fields": { | ||
| 112 | + "last_name": "Administrator", | ||
| 113 | + "webpage": "", | ||
| 114 | + "twitter": "", | ||
| 115 | + "is_staff": true, | ||
| 116 | + "user_permissions": [], | ||
| 117 | + "date_joined": "2015-01-28T12:34:58.770Z", | ||
| 118 | + "google_talk": "", | ||
| 119 | + "first_name": "Admin", | ||
| 120 | + "is_superuser": true, | ||
| 121 | + "last_login": "2015-01-28T12:35:39.621Z", | ||
| 122 | + "verification_hash": null, | ||
| 123 | + "role": "", | ||
| 124 | + "email": "admin@mail.com", | ||
| 125 | + "username": "admin", | ||
| 126 | + "bio": "", | ||
| 127 | + "needs_update": true, | ||
| 128 | + "is_active": true, | ||
| 129 | + "facebook": "", | ||
| 130 | + "groups": [], | ||
| 131 | + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", | ||
| 132 | + "institution": "", | ||
| 133 | + "github": "", | ||
| 134 | + "modified": "2015-01-28T12:45:27.375Z" | ||
| 135 | + }, | ||
| 136 | + "model": "accounts.user", | ||
| 137 | + "pk": 1 | ||
| 138 | +}, | ||
| 139 | +{ | ||
| 140 | + "fields": { | ||
| 141 | + "last_name": "Norris", | ||
| 142 | + "webpage": "", | ||
| 143 | + "twitter": "", | ||
| 144 | + "is_staff": true, | ||
| 145 | + "user_permissions": [], | ||
| 146 | + "date_joined": "2015-01-28T12:34:58.770Z", | ||
| 147 | + "google_talk": "", | ||
| 148 | + "first_name": "Chuck", | ||
| 149 | + "is_superuser": true, | ||
| 150 | + "last_login": "2015-01-28T12:35:39.621Z", | ||
| 151 | + "verification_hash": null, | ||
| 152 | + "role": "", | ||
| 153 | + "email": "chucknorris@mail.com", | ||
| 154 | + "username": "chucknorris", | ||
| 155 | + "bio": "", | ||
| 156 | + "needs_update": true, | ||
| 157 | + "is_active": true, | ||
| 158 | + "facebook": "", | ||
| 159 | + "groups": [], | ||
| 160 | + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", | ||
| 161 | + "institution": "", | ||
| 162 | + "github": "", | ||
| 163 | + "modified": "2015-01-28T12:45:27.375Z" | ||
| 164 | + }, | ||
| 165 | + "model": "accounts.user", | ||
| 166 | + "pk": 2 | ||
| 167 | +}, | ||
| 168 | + | ||
| 169 | +{ | ||
| 170 | + "fields": { | ||
| 171 | + "last_name": "Norris", | ||
| 172 | + "webpage": "", | ||
| 173 | + "twitter": "", | ||
| 174 | + "is_staff": true, | ||
| 175 | + "user_permissions": [], | ||
| 176 | + "date_joined": "2015-01-28T12:34:58.770Z", | ||
| 177 | + "google_talk": "", | ||
| 178 | + "first_name": "Heisenberg", | ||
| 179 | + "is_superuser": true, | ||
| 180 | + "last_login": "2015-01-28T12:35:39.621Z", | ||
| 181 | + "verification_hash": null, | ||
| 182 | + "role": "", | ||
| 183 | + "email": "heisenberg@mail.com", | ||
| 184 | + "username": "heisenbergnorris", | ||
| 185 | + "bio": "", | ||
| 186 | + "needs_update": true, | ||
| 187 | + "is_active": true, | ||
| 188 | + "facebook": "", | ||
| 189 | + "groups": [], | ||
| 190 | + "password": "pbkdf2_sha256$12000$iiKCMnLZnFJw$UTx89LB8oYTiw9UqkcglzFLmIaZtbr+ZzF1cG3vfcyo=", | ||
| 191 | + "institution": "", | ||
| 192 | + "github": "", | ||
| 193 | + "modified": "2015-01-28T12:45:27.375Z" | ||
| 194 | + }, | ||
| 195 | + "model": "accounts.user", | ||
| 196 | + "pk": 3 | ||
| 197 | +}, | ||
| 198 | +{ | ||
| 199 | + "fields": { | ||
| 200 | + "real_name": "Administrator", | ||
| 201 | + "user": 1, | ||
| 202 | + "md5": "edb0e96701c209ab4b50211c856c50c4", | ||
| 203 | + "address": "admin@mail.com" | ||
| 204 | + }, | ||
| 205 | + "model": "super_archives.emailaddress", | ||
| 206 | + "pk": 1 | ||
| 207 | +} | ||
| 208 | +] |
colab/search/tests.py
| 1 | -# uncomment the import if you really use. | ||
| 2 | -# from django.test import TestCase | 1 | +# -*- coding:utf-8 -*- |
| 3 | 2 | ||
| 4 | -# Create your tests here. | 3 | +from django.test import TestCase, Client |
| 4 | +from django.core.management import call_command | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +class SearchViewTest(TestCase): | ||
| 8 | + | ||
| 9 | + fixtures = ['test_data.json'] | ||
| 10 | + | ||
| 11 | + def setUp(self): | ||
| 12 | + call_command('update_index', interactive=False, verbosity=0) | ||
| 13 | + self.client = Client() | ||
| 14 | + | ||
| 15 | + def tearDown(self): | ||
| 16 | + call_command('clear_index', interactive=False,verbosity=0) | ||
| 17 | + | ||
| 18 | + def test_search_thread(self): | ||
| 19 | + request = self.client.get('/search/?q=thread') | ||
| 20 | + thread_list = request.context['page'].object_list | ||
| 21 | + | ||
| 22 | + self.assertEqual(3, len(thread_list)) | ||
| 23 | + | ||
| 24 | + self.assertIn('This is a repply to Thread 1 on list A', | ||
| 25 | + thread_list[0].description) | ||
| 26 | + self.assertIn('This is a repply to Thread 1 on list C', | ||
| 27 | + thread_list[1].description) | ||
| 28 | + self.assertIn('This is a repply to Thread 1 on list B', | ||
| 29 | + thread_list[2].description) | ||
| 30 | + | ||
| 31 | + def test_search_account_by_firstName(self): | ||
| 32 | + request = self.client.get('/search/?q=Chuck') | ||
| 33 | + user_list = request.context['page'].object_list | ||
| 34 | + | ||
| 35 | + self.assertEqual(1, len(user_list)) | ||
| 36 | + | ||
| 37 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
| 38 | + self.assertIn('Chuck', user_list[0].object.first_name) | ||
| 39 | + self.assertIn('Norris', user_list[0].object.last_name) | ||
| 40 | + self.assertIn('chucknorris', user_list[0].object.username) | ||
| 41 | + | ||
| 42 | + def test_search_account_by_lastName(self): | ||
| 43 | + request = self.client.get('/search/?q=Norris') | ||
| 44 | + user_list = request.context['page'].object_list | ||
| 45 | + | ||
| 46 | + self.assertEqual(2, len(user_list)) | ||
| 47 | + | ||
| 48 | + self.assertIn('heisenberg@mail.com', user_list[1].object.email) | ||
| 49 | + self.assertIn('Heisenberg', user_list[1].object.first_name) | ||
| 50 | + self.assertIn('Norris', user_list[1].object.last_name) | ||
| 51 | + self.assertIn('heisenbergnorris', user_list[1].object.username) | ||
| 52 | + | ||
| 53 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
| 54 | + self.assertIn('Chuck', user_list[0].object.first_name) | ||
| 55 | + self.assertIn('Norris', user_list[0].object.last_name) | ||
| 56 | + self.assertIn('chucknorris', user_list[0].object.username) |
setup.py
| @@ -12,7 +12,7 @@ REQUIREMENTS = [ | @@ -12,7 +12,7 @@ REQUIREMENTS = [ | ||
| 12 | 'python-dateutil==1.5', | 12 | 'python-dateutil==1.5', |
| 13 | 'django-cliauth==0.9.1', | 13 | 'django-cliauth==0.9.1', |
| 14 | 'django-mobile==0.3.0', | 14 | 'django-mobile==0.3.0', |
| 15 | - 'django-haystack==2.1', | 15 | + 'django-haystack==2.2', |
| 16 | 'pysolr==2.1', | 16 | 'pysolr==2.1', |
| 17 | 'poster==0.8.1', | 17 | 'poster==0.8.1', |
| 18 | 'etiquetando==0.1', | 18 | 'etiquetando==0.1', |
tests/settings.py
| @@ -32,7 +32,8 @@ LOGGING = { | @@ -32,7 +32,8 @@ LOGGING = { | ||
| 32 | import os | 32 | import os |
| 33 | HAYSTACK_CONNECTIONS = { | 33 | HAYSTACK_CONNECTIONS = { |
| 34 | 'default': { | 34 | 'default': { |
| 35 | - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', | ||
| 36 | - 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'), | 35 | + 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', |
| 36 | + 'URL': 'http://127.0.0.1:8983/solr' | ||
| 37 | }, | 37 | }, |
| 38 | } | 38 | } |
| 39 | + |