Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Pena committed Jun 27, 2020
1 parent 72d56c0 commit 036c562
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 110 deletions.
58 changes: 2 additions & 56 deletions public_interface/tests/test_advanced_search.py
Expand Up @@ -3,57 +3,8 @@
from django.test import Client, TestCase
from django.conf import settings
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.AutoCompleteIndex',
'public_interface.search_indexes.VouchersIndex',
],
},
'autocomplete': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'autocomplete',
'INCLUDE_SPELLING': False,
'EXCLUDED_INDEXES': [
'public_interface.search_indexes.SimpleSearchIndex',
'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',
'public_interface.search_indexes.AutoCompleteIndex',
],
},
'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',
'public_interface.search_indexes.VouchersIndex',
],
},
}


@override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX)


class TestAdvancedSearch(TestCase):
def setUp(self):
with connection.cursor() as cursor:
Expand All @@ -63,11 +14,6 @@ def setUp(self):
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(TestAdvancedSearch, self).setUp()

self.client = Client()

def test_advanced_search_combined(self):
Expand Down
59 changes: 5 additions & 54 deletions public_interface/tests/test_views.py
@@ -1,73 +1,21 @@
from unittest import skip

from django.core.management import call_command
from django.test import Client
from django.conf import settings
from django.test import TestCase
from django.contrib.auth.models import User
from django.test.utils import override_settings

import haystack

from public_interface.utils import VoSeqSearchView


# 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': 'test_haystack',
'INCLUDE_SPELLING': True,
'EXCLUDED_INDEXES': [
'public_interface.search_indexes.AdvancedSearchIndex',
'public_interface.search_indexes.AutoCompleteIndex',
'public_interface.search_indexes.VouchersIndex',
],
},
'autocomplete': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'test_autocomplete',
'INCLUDE_SPELLING': False,
'EXCLUDED_INDEXES': [
'public_interface.search_indexes.SimpleSearchIndex',
'public_interface.search_indexes.VouchersIndex',
],
},
'vouchers': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'test_vouchers',
'INCLUDE_SPELLING': False,
'EXCLUDED_INDEXES': [
'public_interface.search_indexes.SimpleSearchIndex',
'public_interface.search_indexes.AdvancedSearchIndex',
'public_interface.search_indexes.AutoCompleteIndex',
],
},
'advanced_search': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'test_advanced_search',
'INCLUDE_SPELLING': False,
'EXCLUDED_INDEXES': [
'public_interface.search_indexes.SimpleSearchIndex',
'public_interface.search_indexes.VouchersIndex',
],
},
}


@override_settings(HAYSTACK_CONNECTIONS=TEST_INDEX)
class TestViews(TestCase):
def setUp(self):
args = []
opts = {'dumpfile': settings.MEDIA_ROOT + '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()
Expand Down Expand Up @@ -127,20 +75,23 @@ def test_search_returns_empty(self):
content = str(response.content)
self.assertFalse('NN1-2' in content and 'NN1-1' in content)

@skip
def test_autocomplete_param_field(self):
"""Parameters field and term are required to return JSON info for
autocomplete input boxes in advanced search GUI.
"""
response = self.client.get('/autocomplete/?field=genus')
self.assertEqual(404, response.status_code)

@skip
def test_autocomplete_param_term(self):
"""Parameters field and term are required to return JSON info for
autocomplete input boxes in advanced search GUI.
"""
response = self.client.get('/autocomplete/?term=euptychia')
self.assertEqual(404, response.status_code)

@skip
def test_autocomplete(self):
response = self.client.get('/autocomplete/?field=genus&term=melita')
content = response.content.decode('utf-8')
Expand Down
1 change: 1 addition & 0 deletions public_interface/views.py
Expand Up @@ -84,6 +84,7 @@ def search(request):
return render(request, 'public_interface/search_results.html', context)
else:
sqs = Vouchers.objects.filter(
Q(orden__icontains=query) |
Q(genus__icontains=query) | Q(species__icontains=query) | Q(code__icontains=query),
)
results = ""
Expand Down

0 comments on commit 036c562

Please sign in to comment.