Skip to content

Commit

Permalink
reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed May 8, 2015
1 parent af25485 commit 87bf1f7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 32 deletions.
99 changes: 99 additions & 0 deletions voseq/public_interface/tests/test_advanced_search.py
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)
32 changes: 0 additions & 32 deletions voseq/public_interface/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,3 @@ def test_autocomplete(self):
response = self.client.get('/autocomplete/?field=genus&term=melita')
content = response.content.decode('utf-8')
self.assertTrue('Melitaea' in content)

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_combined(self):
response = self.client.get('/search/advanced/?orden=Lepidoptera&labPerson=Niklas+Wahlberg')
content = response.content.decode('utf-8')
self.assertEqual(1, content.count('/CP100-10'))

def tearDown(self):
call_command('clear_index', interactive=False, verbosity=0)

0 comments on commit 87bf1f7

Please sign in to comment.