Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions example/tests/test_generic_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from example.tests import TestBase


@override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize')
class GenericViewSet(TestBase):
"""
Test expected responses coming from a Generic ViewSet
Expand Down Expand Up @@ -36,7 +35,8 @@ def test_ember_expected_renderer(self):
"""
url = reverse('user-manual-resource-name', kwargs={'pk': self.miles.pk})

response = self.client.get(url)
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.get(url)
self.assertEqual(200, response.status_code)

expected = {
Expand Down Expand Up @@ -75,14 +75,15 @@ def test_default_validation_exceptions(self):
}
]
}
response = self.client.post('/identities', {
'data': {
'type': 'users',
'attributes': {
'email': 'bar', 'first_name': 'alajflajaljalajlfjafljalj'
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.post('/identities', {
'data': {
'type': 'users',
'attributes': {
'email': 'bar', 'first_name': 'alajflajaljalajlfjafljalj'
}
}
}
})
})

assert expected == response.json()

Expand Down
16 changes: 10 additions & 6 deletions example/tests/test_model_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from example.tests import TestBase


@override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize')
class ModelViewSetTests(TestBase):
"""
Test usage with ModelViewSets, also tests pluralization, camelization,
Expand All @@ -26,7 +25,8 @@ def test_key_in_list_result(self):
"""
Ensure the result has a 'user' key since that is the name of the model
"""
response = self.client.get(self.list_url)
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.get(self.list_url)
self.assertEqual(response.status_code, 200)

user = get_user_model().objects.all()[0]
Expand Down Expand Up @@ -63,7 +63,8 @@ def test_page_two_in_list_result(self):
"""
Ensure that the second page is reachable and is the correct data.
"""
response = self.client.get(self.list_url, {'page[number]': 2})
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.get(self.list_url, {'page[number]': 2})
self.assertEqual(response.status_code, 200)

user = get_user_model().objects.all()[1]
Expand Down Expand Up @@ -102,7 +103,8 @@ def test_page_range_in_list_result(self):
tests pluralization as two objects means it converts ``user`` to
``users``.
"""
response = self.client.get(self.list_url, {'page[size]': 2})
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.get(self.list_url, {'page[size]': 2})
self.assertEqual(response.status_code, 200)

users = get_user_model().objects.all()
Expand Down Expand Up @@ -148,7 +150,8 @@ def test_key_in_detail_result(self):
"""
Ensure the result has a 'user' key.
"""
response = self.client.get(self.detail_url)
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.get(self.detail_url)
self.assertEqual(response.status_code, 200)

expected = {
Expand Down Expand Up @@ -199,7 +202,8 @@ def test_key_in_post(self):
}
}

response = self.client.put(self.detail_url, data=data)
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
response = self.client.put(self.detail_url, data=data)

assert data == response.json()

Expand Down
2 changes: 1 addition & 1 deletion requirements-development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ flake8==3.7.5
flake8-isort==2.6.0
isort==4.3.4
mock==2.0.0
pytest==4.1.1
pytest==4.2.0
pytest-cov==2.6.1
pytest-django==3.4.7
pytest-factoryboy==2.0.2
Expand Down