-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathtest_format_keys.py
69 lines (59 loc) · 1.99 KB
/
test_format_keys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils import encoding
from rest_framework import status
from example.tests import TestBase
class FormatKeysSetTests(TestBase):
"""
Test that camelization and underscoring of key names works if they are activated.
"""
list_url = reverse("user-list")
def setUp(self):
super().setUp()
self.detail_url = reverse("user-detail", kwargs={"pk": self.miles.pk})
def test_camelization(self):
"""
Test that camelization works.
"""
response = self.client.get(self.list_url)
self.assertEqual(response.status_code, 200)
user = get_user_model().objects.all()[0]
expected = {
"data": [
{
"type": "users",
"id": encoding.force_str(user.pk),
"attributes": {
"firstName": user.first_name,
"lastName": user.last_name,
"email": user.email,
},
}
],
"links": {
"first": "http://testserver/identities?page%5Bnumber%5D=1",
"last": "http://testserver/identities?page%5Bnumber%5D=2",
"next": "http://testserver/identities?page%5Bnumber%5D=2",
"prev": None,
},
"meta": {"pagination": {"page": 1, "pages": 2, "count": 2}},
}
assert expected == response.json()
def test_options_format_field_names(db, client):
response = client.options(reverse("author-list"))
assert response.status_code == status.HTTP_200_OK
data = response.json()["data"]
expected_keys = {
"name",
"fullName",
"email",
"bio",
"entries",
"firstEntry",
"authorType",
"comments",
"secrets",
"defaults",
"initials",
}
assert expected_keys == data["actions"]["POST"].keys()