forked from django-json-api/django-rest-framework-json-api
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generic_validation.py
39 lines (30 loc) · 1.01 KB
/
test_generic_validation.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
importjson
fromdjango.core.urlresolversimportreverse
fromdjango.confimportsettings
fromrest_framework.serializersimportValidationError
fromexample.testsimportTestBase
fromexample.tests.utilsimportload_json
classGenericValidationTest(TestBase):
"""
Test that a non serializer specific validation can be thrown and formatted
"""
defsetUp(self):
super(GenericValidationTest, self).setUp()
self.url=reverse('user-validation', kwargs={'pk': self.miles.pk})
deftest_generic_validation_error(self):
"""
Check error formatting
"""
response=self.client.get(self.url)
self.assertEqual(response.status_code, 400)
expected= {
'errors': [{
'status': '400',
'source': {
'pointer': '/data'
},
'detail': 'Oh nohs!'
}]
}
parsed_content=load_json(response.content)
assertexpected==parsed_content