Skip to content
Snippets Groups Projects
Verified Commit 995be494 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

See #432: fixed an ordering issue on tag length

parent e3f6baec
No related branches found
No related tags found
No related merge requests found
from django.db.models import functions
from rest_framework import viewsets
import django_filters.rest_framework
from funkwhale_api.users.oauth import permissions as oauth_permissions
from . import filters
......@@ -20,3 +22,4 @@ class TagViewSet(viewsets.ReadOnlyModelViewSet):
required_scope = "libraries"
anonymous_policy = "setting"
filterset_class = filters.TagFilter
filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
......@@ -23,18 +23,21 @@ def test_tags_list_ordering_length(factories, logged_in_api_client):
url = reverse("api:v1:tags-list")
tags = [
factories["tags.Tag"](name="iamareallylongtag"),
factories["tags.Tag"](name="reallylongtag"),
factories["tags.Tag"](name="short"),
factories["tags.Tag"](name="reallylongtag"),
factories["tags.Tag"](name="bar"),
]
expected = {
"count": 4,
"next": None,
"previous": None,
"results": [serializers.TagSerializer(tag).data for tag in tags],
"results": [
serializers.TagSerializer(tag).data
for tag in [tags[3], tags[1], tags[2], tags[0]]
],
}
response = logged_in_api_client.get(url, {"ordering": "-length"})
response = logged_in_api_client.get(url, {"ordering": "length"})
assert response.data == expected
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment