mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Added unit-test that checks OPTIONS response for dynamic serializers
This commit is contained in:
parent
1f72fd42bc
commit
63a6d6b778
|
@ -43,7 +43,7 @@ def main():
|
|||
test_module_name = 'rest_framework.tests'
|
||||
if django.VERSION[0] == 1 and django.VERSION[1] < 6:
|
||||
test_module_name = 'tests'
|
||||
|
||||
print test_module_name + test_case
|
||||
failures = test_runner.run_tests([test_module_name + test_case])
|
||||
|
||||
sys.exit(failures)
|
||||
|
|
|
@ -607,3 +607,31 @@ class TestFilterBackendAppliedToViews(TestCase):
|
|||
response = view(request).render()
|
||||
self.assertContains(response, 'field_b')
|
||||
self.assertNotContains(response, 'field_a')
|
||||
|
||||
def test_options_with_dynamic_serializer(self):
|
||||
"""
|
||||
Ensure that OPTIONS returns correct POST json schema: DynamicSerializer with single field 'field_b'
|
||||
"""
|
||||
request = factory.options('/')
|
||||
view = DynamicSerializerView.as_view()
|
||||
with self.assertNumQueries(0):
|
||||
response = view(request).render()
|
||||
expected = {
|
||||
u'name': u'Dynamic Serializer',
|
||||
u'description': u'',
|
||||
u'renders': [u'text/html', u'application/json'],
|
||||
u'parses': [u'application/json', u'application/x-www-form-urlencoded', u'multipart/form-data'],
|
||||
u'actions': {
|
||||
u'POST': {
|
||||
u'field_b': {
|
||||
u'type': u'string',
|
||||
u'required': True,
|
||||
u'read_only': False,
|
||||
u'label': u'field b',
|
||||
u'max_length': 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data, expected)
|
Loading…
Reference in New Issue
Block a user