1
- import json
2
-
3
- from example .tests import TestBase
4
-
5
1
from django .contrib .auth import get_user_model
6
2
from django .core .urlresolvers import reverse
7
3
from django .conf import settings
4
+ from django .utils import encoding
5
+
6
+ from example .tests import TestBase
7
+ from example .tests .utils import dump_json , redump_json
8
8
9
9
10
10
class FormatKeysSetTests (TestBase ):
@@ -18,7 +18,8 @@ def setUp(self):
18
18
self .detail_url = reverse ('user-detail' , kwargs = {'pk' : self .miles .pk })
19
19
20
20
# Set the format keys settings.
21
- setattr (settings , 'JSON_API_FORMAT_KEYS' , 'camelization' )
21
+ setattr (settings , 'JSON_API_FORMAT_KEYS' , 'camelize' )
22
+ # CAMELIZE capitalize the type, needs to be checked
22
23
23
24
def tearDown (self ):
24
25
# Remove the format keys settings.
@@ -34,20 +35,33 @@ def test_camelization(self):
34
35
35
36
user = get_user_model ().objects .all ()[0 ]
36
37
expected = {
37
- u'data' : {
38
- u'type' : u'users' ,
39
- u'id' : user .pk ,
40
- u'attributes' : {
41
- u'firstName' : user .first_name ,
42
- u'lastName' : user .last_name ,
43
- u'email' : user .email
44
- },
38
+ 'data' : [
39
+ {
40
+ 'type' : 'Users' ,
41
+ 'id' : encoding .force_text (user .pk ),
42
+ 'attributes' : {
43
+ 'firstName' : user .first_name ,
44
+ 'lastName' : user .last_name ,
45
+ 'email' : user .email
46
+ },
47
+ }
48
+ ],
49
+ 'links' : {
50
+ 'first' : 'http://testserver/identities?page=1' ,
51
+ 'last' : 'http://testserver/identities?page=2' ,
52
+ 'next' : 'http://testserver/identities?page=2' ,
53
+ 'prev' : None
54
+ },
55
+ 'meta' : {
56
+ 'pagination' : {
57
+ 'page' : 1 ,
58
+ 'pages' : 2 ,
59
+ 'count' : 2
60
+ }
45
61
}
46
62
}
47
63
48
- json_content = json . loads (response .content . decode ( 'utf8' ) )
49
- links = json_content . get ( 'links' )
64
+ content_dump = redump_json (response .content )
65
+ expected_dump = dump_json ( expected )
50
66
51
- self .assertEquals (expected .get ('users' ), json_content .get ('users' ))
52
- self .assertEqual (u'http://testserver/identities?page=2' ,
53
- links .get ('next' ))
67
+ assert expected_dump == content_dump
0 commit comments