# Path: tests/support/decorators.py

# 
# Path: tests/support/views.py
# class PaginateViewSet(ArtistViewSet):
#     """Viewset that implements JSON API pagination."""
# 
#     pagination_class = JSONAPILimitOffsetPagination
# 
# class NonJSONPaginateViewSet(ArtistViewSet):
#     """Tests when a viewset is paginated but without a JSONAPI Paginator."""
# 
#     pagination_class = LimitOffsetPagination


import json
from django.urls import reverse
from rest_framework.test import APIRequestFactory
from tests.support.decorators import mark_urls
from tests.support.views import PaginateViewSet, NonJSONPaginateViewSet
    """Pagination works according to spec."""
    list_url = reverse("page-list")
    request = factory.get(list_url, {"offset": 2, "limit": 2})
    view_list = PaginateViewSet.as_view({"get": "list"})

    response = view_list(request)
    response.render()
    assert response["Content-Type"] == "application/vnd.api+json"

    assert json.loads(response.content.decode()) == {
        "meta": {"count": 6},
        "links": {
            "page[next]": f"http://testserver{list_url}?limit=2&offset=4",
            "page[previous]": f"http://testserver{list_url}?limit=2",
        },
        "data": [
            {
                "id": "2",
                "type": "artist",
                "attributes": {"firstName": "Charles", "lastName": "Mingus"},
            },
            {
                "id": "3",
                "type": "artist",
                "attributes": {"firstName": "Bill", "lastName": "Evans"},
            },
        ],
    }



# Path: tests/support/decorators.py

# 
# Path: tests/support/views.py
# class PaginateViewSet(ArtistViewSet):
#     """Viewset that implements JSON API pagination."""
# 
#     pagination_class = JSONAPILimitOffsetPagination
# 
# class NonJSONPaginateViewSet(ArtistViewSet):
#     """Tests when a viewset is paginated but without a JSONAPI Paginator."""
# 
#     pagination_class = LimitOffsetPagination


# Path: tests/test_pagination.py
import json
from django.urls import reverse
from rest_framework.test import APIRequestFactory
from tests.support.decorators import mark_urls
from tests.support.views import PaginateViewSet, NonJSONPaginateViewSet

    """Pagination works according to spec."""
    list_url = reverse("page-list")
    request = factory.get(list_url, {"offset": 2, "limit": 2})
    view_list = PaginateViewSet.as_view({"get": "list"})

    response = view_list(request)
    response.render()
    assert response["Content-Type"] == "application/vnd.api+json"

    assert json.loads(response.content.decode()) == {
        "meta": {"count": 6},
        "links": {
            "page[next]": f"http://testserver{list_url}?limit=2&offset=4",
            "page[previous]": f"http://testserver{list_url}?limit=2",
        },
        "data": [
            {
                "id": "2",
                "type": "artist",
                "attributes": {"firstName": "Charles", "lastName": "Mingus"},
            },
            {
                "id": "3",
                "type": "artist",
                "attributes": {"firstName": "Bill", "lastName": "Evans"},
            },
        ],
    }



@mark_urls