# Path: tests/support/decorators.py

# 
# Path: tests/support/serializers.py
# def get_artists() -> QuerySet:
#     """Get all artists."""
#     return QuerySet(ARTISTS)
# 
# def get_albums() -> QuerySet:
#     """Get all albums."""
#     return QuerySet(ALBUMS)
# 
# def get_tracks() -> QuerySet:
#     """Get all tracks."""
#     return QuerySet(TRACKS)
# 
# def get_non_default_ids() -> QuerySet:
#     """Get all tracks."""
#     return QuerySet(NON_DEFAULT_IDS)
# 
# Path: tests/support/views.py
# class ArtistViewSet(BaseViewSet):
#     """A simple ViewSet for listing or retrieving artists."""
# 
#     serializer_class = ArtistSerializer
#     # This is not testing pagination
#     pagination_class: Optional[Type[BasePagination]] = None
# 
#     def get_queryset(self) -> QuerySet[Artist]:
#         """Return the list of artists."""
#         return get_artists()
# 
# class AlbumViewSet(BaseViewSet):
#     """A simple ViewSet for listing or retrieving albums."""
# 
#     pagination_class = None
# 
#     def get_queryset(self) -> QuerySet[Album]:
#         """Return the list of albums."""
#         return get_albums()
# 
#     def get_serializer(self, *args: Any, **kwargs: Any) -> BaseSerializer:
#         """Test the use of dynamic serializers with the parser."""
#         return AlbumSerializer(*args, **kwargs)
# 
#     @action_route
#     def relationship_artist(self) -> Response:
#         """Do nothing."""
#         # Not currently called, just reversed.
#         return Response()
# 
#     @action_route
#     def related_artist(self) -> Response:
#         """Do nothing."""
#         # Not currently called, just reversed.
#         return Response()
# 
# class NonDefaultIdViewSet(BaseViewSet):
#     """A ViewSet to test non-default IDs."""
# 
#     serializer_class = NonDefaultIdSerializer
#     pagination_class = None
# 
#     def get_queryset(self) -> QuerySet[NonDefaultId]:
#         """Return the list of non default ID objects."""
#         return get_non_default_ids()


import json
from django.urls import reverse
from rest_framework.test import APIRequestFactory
from tests.support.decorators import mark_urls
from tests.support.serializers import (
    get_artists,
    get_albums,
    get_tracks,
    get_non_default_ids,
)
from tests.support.views import ArtistViewSet, AlbumViewSet, NonDefaultIdViewSet

@mark_urls
def test_list_attributes(factory: APIRequestFactory) -> None:
    """You can create using primary data attributes."""
    request = factory.post(
        reverse("artist-list"),
        {
            "data": {
                "type": "artist",
                "attributes": {"firstName": "Thelonious", "lastName": "Monk"},
            }
        },
    )
    view_list = ArtistViewSet.as_view({"post": "create"})
    response = view_list(request)
    response.render()
    assert response["Content-Type"] == "application/vnd.api+json"
    assert json.loads(response.content) == {
        "data": {
            "id": "6",
            "type": "artist",
            "attributes": {"firstName": "Thelonious", "lastName": "Monk"},
        }
    }
    artist = get_artists().get(6)
    assert artist.id == 6
    assert artist.first_name == "Thelonious"
    assert artist.last_name == "Monk"



# Path: tests/support/decorators.py

# 
# Path: tests/support/serializers.py
# def get_artists() -> QuerySet:
#     """Get all artists."""
#     return QuerySet(ARTISTS)
# 
# def get_albums() -> QuerySet:
#     """Get all albums."""
#     return QuerySet(ALBUMS)
# 
# def get_tracks() -> QuerySet:
#     """Get all tracks."""
#     return QuerySet(TRACKS)
# 
# def get_non_default_ids() -> QuerySet:
#     """Get all tracks."""
#     return QuerySet(NON_DEFAULT_IDS)
# 
# Path: tests/support/views.py
# class ArtistViewSet(BaseViewSet):
#     """A simple ViewSet for listing or retrieving artists."""
# 
#     serializer_class = ArtistSerializer
#     # This is not testing pagination
#     pagination_class: Optional[Type[BasePagination]] = None
# 
#     def get_queryset(self) -> QuerySet[Artist]:
#         """Return the list of artists."""
#         return get_artists()
# 
# class AlbumViewSet(BaseViewSet):
#     """A simple ViewSet for listing or retrieving albums."""
# 
#     pagination_class = None
# 
#     def get_queryset(self) -> QuerySet[Album]:
#         """Return the list of albums."""
#         return get_albums()
# 
#     def get_serializer(self, *args: Any, **kwargs: Any) -> BaseSerializer:
#         """Test the use of dynamic serializers with the parser."""
#         return AlbumSerializer(*args, **kwargs)
# 
#     @action_route
#     def relationship_artist(self) -> Response:
#         """Do nothing."""
#         # Not currently called, just reversed.
#         return Response()
# 
#     @action_route
#     def related_artist(self) -> Response:
#         """Do nothing."""
#         # Not currently called, just reversed.
#         return Response()
# 
# class NonDefaultIdViewSet(BaseViewSet):
#     """A ViewSet to test non-default IDs."""
# 
#     serializer_class = NonDefaultIdSerializer
#     pagination_class = None
# 
#     def get_queryset(self) -> QuerySet[NonDefaultId]:
#         """Return the list of non default ID objects."""
#         return get_non_default_ids()


# Path: tests/test_parsers.py
import json
from django.urls import reverse
from rest_framework.test import APIRequestFactory
from tests.support.decorators import mark_urls
from tests.support.serializers import (
    get_artists,
    get_albums,
    get_tracks,
    get_non_default_ids,
)
from tests.support.views import ArtistViewSet, AlbumViewSet, NonDefaultIdViewSet


@mark_urls
def test_list_attributes(factory: APIRequestFactory) -> None:
    """You can create using primary data attributes."""
    request = factory.post(
        reverse("artist-list"),
        {
            "data": {
                "type": "artist",
                "attributes": {"firstName": "Thelonious", "lastName": "Monk"},
            }
        },
    )
    view_list = ArtistViewSet.as_view({"post": "create"})
    response = view_list(request)
    response.render()
    assert response["Content-Type"] == "application/vnd.api+json"
    assert json.loads(response.content) == {
        "data": {
            "id": "6",
            "type": "artist",
            "attributes": {"firstName": "Thelonious", "lastName": "Monk"},
        }
    }
    artist = get_artists().get(6)
    assert artist.id == 6
    assert artist.first_name == "Thelonious"
    assert artist.last_name == "Monk"



@mark_urls