def test_get_resource_name_from_model_serializer_class(settings, format_type, pluralize_type, output): settings.JSON_API_FORMAT_TYPES = format_type settings.JSON_API_PLURALIZE_TYPES = pluralize_type view = GenericAPIView() view.serializer_class = BasicModelSerializer context = {"view": view} assert output == get_resource_name(context)
def test_get_resource_name_from_model_serializer_class_custom_resource_name( settings, format_type, pluralize_type): settings.JSON_API_FORMAT_TYPES = format_type settings.JSON_API_PLURALIZE_TYPES = pluralize_type view = GenericAPIView() view.serializer_class = BasicModelSerializer view.serializer_class.Meta.resource_name = "custom" context = {"view": view} assert "custom" == get_resource_name(context)
def get_list_view_data(self, view: GenericAPIView, limit: int = None): view = view(request=self.request) queryset = view.get_queryset() if limit: queryset = queryset[:limit] serializer = view.serializer_class(queryset, many=True, context={'request': self.request}) return serializer.data
def test_get_resource_name_from_plain_serializer_class(settings, format_type, pluralize_type): class PlainSerializer(serializers.Serializer): class Meta: resource_name = "custom" settings.JSON_API_FORMAT_TYPES = format_type settings.JSON_API_PLURALIZE_TYPES = pluralize_type view = GenericAPIView() view.serializer_class = PlainSerializer context = {"view": view} assert "custom" == get_resource_name(context)