From be6d35b831b828d26745d27bd17d7437bed970c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Thu, 1 Mar 2018 19:02:34 +0100 Subject: [PATCH] Order search of Reports by newest date. --- openlobby/core/search.py | 4 +- tests/dummy.py | 16 ++--- tests/schema/snapshots/snap_test_authors.py | 8 +-- .../snapshots/snap_test_report_drafts.py | 4 +- .../snapshots/snap_test_search_reports.py | 72 +++++++++---------- tests/test_search.py | 8 +-- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/openlobby/core/search.py b/openlobby/core/search.py index 77371bc..a87e167 100644 --- a/openlobby/core/search.py +++ b/openlobby/core/search.py @@ -17,7 +17,7 @@ def query_reports(query, paginator, *, highlight=False): s = s.query('multi_match', query=query, fields=fields) if highlight: s = s.highlight(*fields, **HIGHLIGHT_PARAMS) - s = s.sort('-published') + s = s.sort('-date') s = s[paginator.slice_from:paginator.slice_to] return s.execute() @@ -26,6 +26,6 @@ def reports_by_author(author_id, paginator): s = ReportDoc.search() s = s.exclude('term', is_draft=True) s = s.filter('term', author_id=author_id) - s = s.sort('-published') + s = s.sort('-date') s = s[paginator.slice_from:paginator.slice_to] return s.execute() diff --git a/tests/dummy.py b/tests/dummy.py index 9e8a1be..5e99de3 100644 --- a/tests/dummy.py +++ b/tests/dummy.py @@ -42,8 +42,8 @@ reports = [ }, { 'id': 2, - 'date': arrow.get(2018, 1, 5).datetime, - 'published': arrow.get(2018, 1, 10).datetime, + 'date': arrow.get(2018, 1, 3).datetime, + 'published': arrow.get(2018, 1, 4).datetime, 'title': 'The Two Towers', 'body': 'Another long story.', 'received_benefit': 'Mithrill Jacket', @@ -54,8 +54,8 @@ reports = [ }, { 'id': 3, - 'date': arrow.get(2018, 1, 7).datetime, - 'published': arrow.get(2018, 1, 8).datetime, + 'date': arrow.get(2018, 1, 5).datetime, + 'published': arrow.get(2018, 1, 6).datetime, 'title': 'The Return of the King', 'body': 'Aragorn is the King. And we have lost the Ring.', 'received_benefit': '', @@ -65,8 +65,8 @@ reports = [ }, { 'id': 4, - 'date': arrow.get(2018, 1, 9).datetime, - 'published': arrow.get(2018, 1, 11).datetime, + 'date': arrow.get(2018, 1, 7).datetime, + 'published': arrow.get(2018, 1, 8).datetime, 'title': 'The Silmarillion', 'body': 'Not finished yet.', 'received_benefit': '', @@ -77,8 +77,8 @@ reports = [ }, { 'id': 5, - 'date': arrow.get(2018, 1, 12).datetime, - 'published': arrow.get(2018, 1, 13).datetime, + 'date': arrow.get(2018, 1, 9).datetime, + 'published': arrow.get(2018, 1, 10).datetime, 'title': 'The Hobbit', 'body': 'Work in progress...', 'received_benefit': '', diff --git a/tests/schema/snapshots/snap_test_authors.py b/tests/schema/snapshots/snap_test_authors.py index e29162b..af19833 100644 --- a/tests/schema/snapshots/snap_test_authors.py +++ b/tests/schema/snapshots/snap_test_authors.py @@ -197,14 +197,14 @@ snapshots['test_with_reports 1'] = { 'cursor': 'MQ==', 'node': { 'body': 'Another long story.', - 'date': '2018-01-05 00:00:00+00:00', + 'date': '2018-01-03 00:00:00+00:00', 'extra': '{"rings": 1}', 'id': 'UmVwb3J0OjI=', 'isDraft': False, 'otherParticipants': 'Saruman, Sauron', 'ourParticipants': 'Frodo, Gimli, Legolas', 'providedBenefit': '', - 'published': '2018-01-10 00:00:00+00:00', + 'published': '2018-01-04 00:00:00+00:00', 'receivedBenefit': 'Mithrill Jacket', 'title': 'The Two Towers' } @@ -228,14 +228,14 @@ snapshots['test_with_reports 1'] = { 'cursor': 'MQ==', 'node': { 'body': 'Aragorn is the King. And we have lost the Ring.', - 'date': '2018-01-07 00:00:00+00:00', + 'date': '2018-01-05 00:00:00+00:00', 'extra': None, 'id': 'UmVwb3J0OjM=', 'isDraft': False, 'otherParticipants': 'Sauron', 'ourParticipants': 'Aragorn', 'providedBenefit': 'The Ring', - 'published': '2018-01-08 00:00:00+00:00', + 'published': '2018-01-06 00:00:00+00:00', 'receivedBenefit': '', 'title': 'The Return of the King' } diff --git a/tests/schema/snapshots/snap_test_report_drafts.py b/tests/schema/snapshots/snap_test_report_drafts.py index b514fd2..a589b1b 100644 --- a/tests/schema/snapshots/snap_test_report_drafts.py +++ b/tests/schema/snapshots/snap_test_report_drafts.py @@ -19,13 +19,13 @@ snapshots['test_authenticated 1'] = { 'reportDrafts': [ { 'body': 'Not finished yet.', - 'date': '2018-01-09 00:00:00+00:00', + 'date': '2018-01-07 00:00:00+00:00', 'id': 'UmVwb3J0OjQ=', 'isDraft': True, 'otherParticipants': '', 'ourParticipants': '', 'providedBenefit': '', - 'published': '2018-01-11 00:00:00+00:00', + 'published': '2018-01-08 00:00:00+00:00', 'receivedBenefit': '', 'title': 'The Silmarillion' } diff --git a/tests/schema/snapshots/snap_test_search_reports.py b/tests/schema/snapshots/snap_test_search_reports.py index a35f915..ef7aaa9 100644 --- a/tests/schema/snapshots/snap_test_search_reports.py +++ b/tests/schema/snapshots/snap_test_search_reports.py @@ -13,30 +13,6 @@ snapshots['test_all 1'] = { 'edges': [ { 'cursor': 'MQ==', - 'node': { - 'author': { - 'extra': None, - 'firstName': 'Spongebob', - 'hasCollidingName': False, - 'id': 'QXV0aG9yOjI=', - 'lastName': 'Squarepants', - 'totalReports': 1 - }, - 'body': 'Another long story.', - 'date': '2018-01-05 00:00:00+00:00', - 'extra': '{"rings": 1}', - 'id': 'UmVwb3J0OjI=', - 'isDraft': False, - 'otherParticipants': 'Saruman, Sauron', - 'ourParticipants': 'Frodo, Gimli, Legolas', - 'providedBenefit': '', - 'published': '2018-01-10 00:00:00+00:00', - 'receivedBenefit': 'Mithrill Jacket', - 'title': 'The Two Towers' - } - }, - { - 'cursor': 'Mg==', 'node': { 'author': { 'extra': '{"movies": 1}', @@ -47,18 +23,42 @@ snapshots['test_all 1'] = { 'totalReports': 2 }, 'body': 'Aragorn is the King. And we have lost the Ring.', - 'date': '2018-01-07 00:00:00+00:00', + 'date': '2018-01-05 00:00:00+00:00', 'extra': None, 'id': 'UmVwb3J0OjM=', 'isDraft': False, 'otherParticipants': 'Sauron', 'ourParticipants': 'Aragorn', 'providedBenefit': 'The Ring', - 'published': '2018-01-08 00:00:00+00:00', + 'published': '2018-01-06 00:00:00+00:00', 'receivedBenefit': '', 'title': 'The Return of the King' } }, + { + 'cursor': 'Mg==', + 'node': { + 'author': { + 'extra': None, + 'firstName': 'Spongebob', + 'hasCollidingName': False, + 'id': 'QXV0aG9yOjI=', + 'lastName': 'Squarepants', + 'totalReports': 1 + }, + 'body': 'Another long story.', + 'date': '2018-01-03 00:00:00+00:00', + 'extra': '{"rings": 1}', + 'id': 'UmVwb3J0OjI=', + 'isDraft': False, + 'otherParticipants': 'Saruman, Sauron', + 'ourParticipants': 'Frodo, Gimli, Legolas', + 'providedBenefit': '', + 'published': '2018-01-04 00:00:00+00:00', + 'receivedBenefit': 'Mithrill Jacket', + 'title': 'The Two Towers' + } + }, { 'cursor': 'Mw==', 'node': { @@ -111,14 +111,14 @@ snapshots['test_query 1'] = { 'totalReports': 1 }, 'body': 'Another long story.', - 'date': '2018-01-05 00:00:00+00:00', + 'date': '2018-01-03 00:00:00+00:00', 'extra': '{"rings": 1}', 'id': 'UmVwb3J0OjI=', 'isDraft': False, 'otherParticipants': 'Saruman, Sauron', 'ourParticipants': 'Frodo, Gimli, Legolas', 'providedBenefit': '', - 'published': '2018-01-10 00:00:00+00:00', + 'published': '2018-01-04 00:00:00+00:00', 'receivedBenefit': 'Mithrill Jacket', 'title': 'The Two Towers' } @@ -145,14 +145,14 @@ snapshots['test_highlight 1'] = { 'totalReports': 2 }, 'body': 'Aragorn is the King. And we have lost the <mark>Ring</mark>.', - 'date': '2018-01-07 00:00:00+00:00', + 'date': '2018-01-05 00:00:00+00:00', 'extra': None, 'id': 'UmVwb3J0OjM=', 'isDraft': False, 'otherParticipants': 'Sauron', 'ourParticipants': 'Aragorn', 'providedBenefit': 'The <mark>Ring</mark>', - 'published': '2018-01-08 00:00:00+00:00', + 'published': '2018-01-06 00:00:00+00:00', 'receivedBenefit': '', 'title': 'The Return of the King' } @@ -194,8 +194,8 @@ snapshots['test_first 1'] = { { 'cursor': 'MQ==', 'node': { - 'id': 'UmVwb3J0OjI=', - 'title': 'The Two Towers' + 'id': 'UmVwb3J0OjM=', + 'title': 'The Return of the King' } } ], @@ -217,8 +217,8 @@ snapshots['test_first_after 1'] = { { 'cursor': 'Mg==', 'node': { - 'id': 'UmVwb3J0OjM=', - 'title': 'The Return of the King' + 'id': 'UmVwb3J0OjI=', + 'title': 'The Two Towers' } } ], @@ -257,8 +257,8 @@ snapshots['test_last_before 1'] = { { 'cursor': 'Mg==', 'node': { - 'id': 'UmVwb3J0OjM=', - 'title': 'The Return of the King' + 'id': 'UmVwb3J0OjI=', + 'title': 'The Two Towers' } } ], diff --git a/tests/test_search.py b/tests/test_search.py index a77314f..5e8d6d0 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -10,8 +10,8 @@ pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')] @pytest.mark.parametrize('query, expected_ids', [ - ('', [2, 3, 1]), - ('sauron', [2, 3]), + ('', [3, 2, 1]), + ('sauron', [3, 2]), ('towers', [2]), ('Aragorn Gandalf', [3, 1]), ]) @@ -33,8 +33,8 @@ def test_query_reports__highlight(): @pytest.mark.parametrize('first, after, expected_ids', [ - (2, None, [2, 3]), - (2, encode_cursor(1), [3, 1]), + (2, None, [3, 2]), + (2, encode_cursor(1), [2, 1]), ]) def test_query_reports__pagination(first, after, expected_ids): prepare_reports() -- GitLab