77from rest_framework .views import APIView
88
99from rest_framework_json_api import utils
10-
1110from example .serializers import (EntrySerializer , BlogSerializer ,
1211 AuthorSerializer , CommentSerializer )
1312from rest_framework_json_api .utils import get_included_serializers
1413
1514pytestmark = pytest .mark .django_db
1615
16+
1717class ResourceView (APIView ):
1818 pass
1919
20+
2021class ResourceSerializer (serializers .ModelSerializer ):
2122 class Meta ():
2223 fields = ('username' ,)
2324 model = get_user_model ()
2425
26+
2527def test_get_resource_name ():
2628 view = ResourceView ()
2729 context = {'view' : view }
@@ -53,6 +55,7 @@ def test_get_resource_name():
5355 view .serializer_class .Meta .resource_name = 'rcustom'
5456 assert 'rcustom' == utils .get_resource_name (context ), 'set on serializer'
5557
58+
5659def test_format_keys ():
5760 underscored = {
5861 'first_name' : 'a' ,
@@ -74,16 +77,19 @@ def test_format_keys():
7477 output = [{'first-name' : 'a' , 'last-name' : 'b' }]
7578 assert utils .format_keys ([underscored ], 'dasherize' ) == output
7679
80+
7781def test_format_value ():
7882 assert utils .format_value ('first_name' , 'camelize' ) == 'firstName'
7983 assert utils .format_value ('first_name' , 'capitalize' ) == 'FirstName'
8084 assert utils .format_value ('first_name' , 'dasherize' ) == 'first-name'
8185 assert utils .format_value ('first-name' , 'underscore' ) == 'first_name'
8286
87+
8388def test_format_relation_name ():
8489 assert utils .format_relation_name ('first_name' , 'capitalize' ) == 'FirstNames'
8590 assert utils .format_relation_name ('first_name' , 'camelize' ) == 'firstNames'
8691
92+
8793def test_build_json_resource_obj ():
8894 resource = {
8995 'pk' : 1 ,
@@ -103,7 +109,7 @@ def test_build_json_resource_obj():
103109 }
104110
105111 assert utils .build_json_resource_obj (
106- serializer .fields , resource , resource_instance , 'user' ) == output
112+ serializer .fields , resource , resource_instance , 'user' ) == output
107113
108114
109115class SerializerWithIncludedSerializers (EntrySerializer ):
@@ -112,7 +118,7 @@ class SerializerWithIncludedSerializers(EntrySerializer):
112118 'authors' : 'example.serializers.AuthorSerializer' ,
113119 'comments' : 'example.serializers.CommentSerializer' ,
114120 'self' : 'self' # this wouldn't make sense in practice (and would be prohibited by
115- # IncludedResourcesValidationMixin) but it's useful for the test
121+ # IncludedResourcesValidationMixin) but it's useful for the test
116122 }
117123
118124
0 commit comments