Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#354 Default ordering of results is not correct #225

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scoap3/articles/api/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django_elasticsearch_dsl_drf.constants import LOOKUP_FILTER_RANGE, LOOKUP_QUERY_IN
from django_elasticsearch_dsl_drf.filter_backends import (
DefaultOrderingFilterBackend,
FacetedSearchFilterBackend,
FilteringFilterBackend,
OrderingFilterBackend,
Expand Down Expand Up @@ -104,6 +105,7 @@ def __init__(self, *args, **kwargs):
FacetedSearchFilterBackend,
FilteringFilterBackend,
OrderingFilterBackend,
DefaultOrderingFilterBackend,
]
renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES + [ArticleCSVRenderer]

Expand Down
40 changes: 40 additions & 0 deletions scoap3/articles/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,43 @@ def test_article_search(user, client):
client.force_login(user)
response = client.get(reverse("search:article-list"))
assert response.status_code == status.HTTP_200_OK


def test_article_search_ordering_default(user, client, license):
client.force_login(user)

articles = [
{
"title": "Article 1",
"related_licenses": [license.id],
"publication_date": "2014-01-01",
},
{
"title": "Article 2",
"related_licenses": [license.id],
"publication_date": "2014-01-02",
},
{
"title": "Article 3",
"related_licenses": [license.id],
"publication_date": "2014-01-03",
},
]

for article in articles:
response = client.post(
reverse("api:article-list"),
data=article,
)
assert response.status_code == 201

response = client.get(reverse("search:article-list"))
data = response.json()

publication_dates = []
for result in data["results"]:
publication_dates.append(result["publication_date"])

assert publication_dates == sorted(
publication_dates, reverse=True
), "Articles are not ordered by publication date in descending order"
Loading