mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
Write test for failing URL param format kwarg
This commit is contained in:
parent
5b388e8f83
commit
8f138afd9f
|
@ -136,3 +136,31 @@ class TestCustomSettings(TestCase):
|
|||
response = self.view(request)
|
||||
assert response.status_code == 400
|
||||
assert response.data == {'error': 'SyntaxError'}
|
||||
|
||||
|
||||
class FormatView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return Response({'format': self.format_kwarg})
|
||||
|
||||
|
||||
class TestAPIViewFormat(TestCase):
|
||||
def setUp(self):
|
||||
self.view = FormatView.as_view()
|
||||
|
||||
def test_uses_kwargs_format(self):
|
||||
request = factory.get('/')
|
||||
response = self.view(request, format='json')
|
||||
|
||||
assert response.data == {'format': 'json'}
|
||||
|
||||
def test_uses_url_format(self):
|
||||
request = factory.get('/test?format=json')
|
||||
response = self.view(request)
|
||||
|
||||
assert response.data == {'format': 'json'}
|
||||
|
||||
def test_prefers_kwarg_over_url_format(self):
|
||||
request = factory.get('/test?format=json')
|
||||
response = self.view(request, format='api')
|
||||
|
||||
assert response.data == {'format': 'api'}
|
||||
|
|
Loading…
Reference in New Issue
Block a user