-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af25485
commit 87bf1f7
Showing
2 changed files
with
99 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from django.core.management import call_command | ||
from django.test import Client | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
import haystack | ||
|
||
|
||
# Need to use a clean index for our tests | ||
TEST_INDEX = { | ||
'default': { | ||
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', | ||
'URL': 'http://127.0.0.1:9200/', | ||
'INDEX_NAME': 'haystack', | ||
'INCLUDE_SPELLING': True, | ||
'EXCLUDED_INDEXES': [ | ||
'public_interface.search_indexes.AdvancedSearchIndex', | ||
'public_interface.search_indexes.VouchersIndex', | ||
], | ||
}, | ||
'vouchers': { | ||
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', | ||
'URL': 'http://127.0.0.1:9200/', | ||
'INDEX_NAME': 'vouchers', | ||
'INCLUDE_SPELLING': False, | ||
'EXCLUDED_INDEXES': [ | ||
'public_interface.search_indexes.SimpleSearchIndex', | ||
'public_interface.search_indexes.AdvancedSearchIndex', | ||
], | ||
}, | ||
'advanced_search': { | ||
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', | ||
'URL': 'http://127.0.0.1:9200/', | ||
'INDEX_NAME': 'advanced_search', | ||
'INCLUDE_SPELLING': False, | ||
'EXCLUDED_INDEXES': [ | ||
'public_interface.search_indexes.SimpleSearchIndex', | ||
], | ||
}, | ||
} | ||
|
||
|
||
@override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX) | ||
class TestViews(TestCase): | ||
def setUp(self): | ||
args = [] | ||
opts = {'dumpfile': 'test_db_dump.xml', 'verbosity': 0} | ||
cmd = 'migrate_db' | ||
call_command(cmd, *args, **opts) | ||
|
||
# build index with our test data | ||
haystack.connections.reload('default') | ||
call_command('rebuild_index', interactive=False, verbosity=0) | ||
super(TestViews, self).setUp() | ||
|
||
self.client = Client() | ||
|
||
def test_advanced_search_gui_form(self): | ||
response = self.client.get('/search/advanced/') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('Search by querying a single field for any combination of fields' in content) | ||
|
||
def test_advanced_search_voucher_objs(self): | ||
response = self.client.get('/search/advanced/?orden=Hymenoptera') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('Melitaea' in content) | ||
|
||
def test_advanced_search_sequence_objs(self): | ||
response = self.client.get('/search/advanced/?labPerson=Niklas') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('Melitaea' in content) | ||
|
||
def test_advanced_search_dont_show_duplicate_records(self): | ||
"""Since we are looking into the Sequences tables, we might get | ||
several sequences belonging to the same voucher. Need to get only | ||
one. | ||
""" | ||
response = self.client.get('/search/advanced/?labPerson=Niklas+Wahlberg') | ||
content = response.content.decode('utf-8') | ||
self.assertEqual(1, content.count('/CP100-10')) | ||
|
||
def test_advanced_search_sequence_table_only(self): | ||
response = self.client.get('/search/advanced/?labPerson=Niklas+Wahlberg') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('CP100-10' in content) | ||
self.assertTrue('CP100-11' in content) | ||
|
||
def test_advanced_search_voucher_table_only(self): | ||
response = self.client.get('/search/advanced/?orden=Lepidoptera') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('CP100-11' in content) | ||
self.assertTrue('CP100-13' in content) | ||
self.assertFalse('CP100-10' in content) | ||
|
||
def test_advanced_search_combined(self): | ||
response = self.client.get('/search/advanced/?orden=Lepidoptera&labPerson=Niklas+Wahlberg') | ||
content = response.content.decode('utf-8') | ||
self.assertTrue('CP100-11' in content) | ||
self.assertFalse('CP100-10' in content) | ||
self.assertFalse('CP100-13' in content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters