# Path: rest_framework_json_schema/negotiation.py
# class JSONAPIContentNegotiation(DefaultContentNegotiation):
#     """
#     Implement the following two MUSTs in the JSON API.
# 
#     Servers MUST respond with a 415 Unsupported Media Type status code if a
#     request specifies the header Content-Type: application/vnd.api+json
#     with any media type parameters.
# 
#     Servers MUST respond with a 406 Not Acceptable status code if a request's
#     Accept header contains the JSON API media type and all instances of that
#     media type are modified with media type parameters.
# 
#     https://jsonapi.org/format/#content-negotiation
#     """
# 
#     def get_accept_list(self, request: Request) -> List[str]:
#         """Filter any JSON API specification that includes media parameters."""
#         accept_list = super().get_accept_list(request)
# 
#         def jsonapi_params(media_type_str: str) -> bool:
#             media_type = _MediaType(media_type_str)
#             # We don't use _MediaType.match() because we want an *exact* match, without matching */*
#             return (
#                 media_type.full_type == "application/vnd.api+json" and media_type.params
#             )
# 
#         return [accept for accept in accept_list if not jsonapi_params(accept)]
# 
# Path: tests/support/decorators.py

# 
# 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()


from django.urls import reverse
from rest_framework.test import APIRequestFactory
from rest_framework_json_schema.negotiation import JSONAPIContentNegotiation
from tests.support.decorators import mark_urls
from tests.support.views import ArtistViewSet



@mark_urls
def test_accept_list(factory: APIRequestFactory) -> None:
    """The negotiator filters application/vnd.api+json with params, but not any non-vnd.api+json"""
    negotiator = JSONAPIContentNegotiation()

    request = factory.get(
        reverse("artist-list"), HTTP_ACCEPT="application/vnd.api+json"
    )
    accept_list = negotiator.get_accept_list(request)
    assert accept_list == ["application/vnd.api+json"]

    accept = (
        "text/html,application/vnd.api+json;indent=4,application/xml;q=0.9,*/*;q=0.8"
    )
    request = factory.get(reverse("artist-list"), HTTP_ACCEPT=accept)
    accept_list = negotiator.get_accept_list(request)
    assert accept_list == ["text/html", "application/xml;q=0.9", "*/*;q=0.8"]



# Path: rest_framework_json_schema/negotiation.py
# class JSONAPIContentNegotiation(DefaultContentNegotiation):
#     """
#     Implement the following two MUSTs in the JSON API.
# 
#     Servers MUST respond with a 415 Unsupported Media Type status code if a
#     request specifies the header Content-Type: application/vnd.api+json
#     with any media type parameters.
# 
#     Servers MUST respond with a 406 Not Acceptable status code if a request's
#     Accept header contains the JSON API media type and all instances of that
#     media type are modified with media type parameters.
# 
#     https://jsonapi.org/format/#content-negotiation
#     """
# 
#     def get_accept_list(self, request: Request) -> List[str]:
#         """Filter any JSON API specification that includes media parameters."""
#         accept_list = super().get_accept_list(request)
# 
#         def jsonapi_params(media_type_str: str) -> bool:
#             media_type = _MediaType(media_type_str)
#             # We don't use _MediaType.match() because we want an *exact* match, without matching */*
#             return (
#                 media_type.full_type == "application/vnd.api+json" and media_type.params
#             )
# 
#         return [accept for accept in accept_list if not jsonapi_params(accept)]
# 
# Path: tests/support/decorators.py

# 
# 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()


# Path: tests/test_negotiation.py
from django.urls import reverse
from rest_framework.test import APIRequestFactory
from rest_framework_json_schema.negotiation import JSONAPIContentNegotiation
from tests.support.decorators import mark_urls
from tests.support.views import ArtistViewSet




@mark_urls
def test_accept_list(factory: APIRequestFactory) -> None:
    """The negotiator filters application/vnd.api+json with params, but not any non-vnd.api+json"""
    negotiator = JSONAPIContentNegotiation()

    request = factory.get(
        reverse("artist-list"), HTTP_ACCEPT="application/vnd.api+json"
    )
    accept_list = negotiator.get_accept_list(request)
    assert accept_list == ["application/vnd.api+json"]

    accept = (
        "text/html,application/vnd.api+json;indent=4,application/xml;q=0.9,*/*;q=0.8"
    )
    request = factory.get(reverse("artist-list"), HTTP_ACCEPT=accept)
    accept_list = negotiator.get_accept_list(request)
    assert accept_list == ["text/html", "application/xml;q=0.9", "*/*;q=0.8"]



@mark_urls