diff --git a/openlobby/core/api/schema.py b/openlobby/core/api/schema.py index eb66ac698677a86c2ada91d2acb9115190004f03..d191bc5d1514a8432b6fa4a482db2159135b9d67 100644 --- a/openlobby/core/api/schema.py +++ b/openlobby/core/api/schema.py @@ -70,8 +70,6 @@ class Query: query = kwargs.get('query', '') query = extract_text(query) params = { - 'es': info.context['es'], - 'index': info.context['index'], 'highlight': kwargs.get('highlight'), } response = search.query_reports(query, paginator, **params) diff --git a/tests/dummy.py b/tests/dummy.py new file mode 100644 index 0000000000000000000000000000000000000000..dd168559ac0a74eedfc0c1f6b3828c14bf83c066 --- /dev/null +++ b/tests/dummy.py @@ -0,0 +1,47 @@ +import arrow + +from openlobby.core.models import Report, User + + +reports = [ + { + 'id': 1, + 'date': arrow.get(2018, 1, 1).datetime, + 'published': arrow.get(2018, 1, 2).datetime, + 'title': 'The Fellowship of the Ring', + 'body': 'Long story short: we got the Ring!', + 'received_benefit': 'The Ring', + 'provided_benefit': '', + 'our_participants': 'Frodo, Gandalf', + 'other_participants': 'Saruman', + }, + { + 'id': 2, + 'date': arrow.get(2018, 1, 5).datetime, + 'published': arrow.get(2018, 1, 10).datetime, + 'title': 'The Two Towers', + 'body': 'Another long story.', + 'received_benefit': 'Mithrill Jacket', + 'provided_benefit': '', + 'our_participants': 'Frodo, Gimli, Legolas', + 'other_participants': 'Saruman, Sauron', + }, + { + 'id': 3, + 'date': arrow.get(2018, 1, 7).datetime, + 'published': arrow.get(2018, 1, 8).datetime, + 'title': 'The Return of the King', + 'body': 'Aragorn is the King. And we have lost the Ring.', + 'received_benefit': '', + 'provided_benefit': 'The Ring', + 'our_participants': 'Aragorn', + 'other_participants': 'Sauron', + }, +] + + +def prepare_reports(): + author = User.objects.create(id=1, username='Wolf', openid_uid='Wolf', + first_name='Winston', last_name='Wolfe') + for report in reports: + Report.objects.create(author=author, **report) diff --git a/tests/test_search.py b/tests/test_search.py index d604b0e82a25a10198a343a0c284f1178e5d4f92..32743f0a8cd30ac0e562c659f52bb476d0734e59 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,56 +1,12 @@ import pytest -import arrow from openlobby.core.api.paginator import Paginator, encode_cursor -from openlobby.core.models import Report, User from openlobby.core.search import query_reports +from .dummy import prepare_reports -pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')] - - -reports = [ - { - 'id': 1, - 'date': arrow.get(2018, 1, 1).datetime, - 'published': arrow.get(2018, 1, 2).datetime, - 'title': 'The Fellowship of the Ring', - 'body': 'Long story short: we got the Ring!', - 'received_benefit': 'The Ring', - 'provided_benefit': '', - 'our_participants': 'Frodo, Gandalf', - 'other_participants': 'Saruman', - }, - { - 'id': 2, - 'date': arrow.get(2018, 1, 5).datetime, - 'published': arrow.get(2018, 1, 10).datetime, - 'title': 'The Two Towers', - 'body': 'Another long story.', - 'received_benefit': 'Mithrill Jacket', - 'provided_benefit': '', - 'our_participants': 'Frodo, Gimli, Legolas', - 'other_participants': 'Saruman, Sauron', - }, - { - 'id': 3, - 'date': arrow.get(2018, 1, 7).datetime, - 'published': arrow.get(2018, 1, 8).datetime, - 'title': 'The Return of the King', - 'body': 'Aragorn is the King. And we have lost the Ring.', - 'received_benefit': '', - 'provided_benefit': 'The Ring', - 'our_participants': 'Aragorn', - 'other_participants': 'Sauron', - }, -] - -def prepare_data(): - author = User.objects.create(id=1, username='Wolf', openid_uid='Wolf', - first_name='Winston', last_name='Wolfe') - for report in reports: - Report.objects.create(author=author, **report) +pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')] @pytest.mark.parametrize('query, expected_ids', [ @@ -60,14 +16,14 @@ def prepare_data(): ('Aragorn Gandalf', [3, 1]), ]) def test_query_reports(query, expected_ids): - prepare_data() + prepare_reports() paginator = Paginator() response = query_reports(query, paginator) assert expected_ids == [int(r.meta.id) for r in response] def test_query_reports__highlight(): - prepare_data() + prepare_reports() paginator = Paginator() query = 'King' response = query_reports(query, paginator, highlight=True) @@ -81,7 +37,7 @@ def test_query_reports__highlight(): (2, encode_cursor(1), [3, 1]), ]) def test_query_reports__pagination(first, after, expected_ids): - prepare_data() + prepare_reports() query = '' paginator = Paginator(first=first, after=after) response = query_reports(query, paginator)