mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
converted validators and write_only_fields test to pytest style (#4697)
This commit is contained in:
parent
4b59ec27fa
commit
5ec223bca0
|
@ -94,23 +94,20 @@ class TestUniquenessValidation(TestCase):
|
|||
def test_doesnt_pollute_model(self):
|
||||
instance = AnotherUniquenessModel.objects.create(code='100')
|
||||
serializer = AnotherUniquenessSerializer(instance)
|
||||
self.assertEqual(
|
||||
AnotherUniquenessModel._meta.get_field('code').validators, [])
|
||||
assert AnotherUniquenessModel._meta.get_field('code').validators == []
|
||||
|
||||
# Accessing data shouldn't effect validators on the model
|
||||
serializer.data
|
||||
self.assertEqual(
|
||||
AnotherUniquenessModel._meta.get_field('code').validators, [])
|
||||
assert AnotherUniquenessModel._meta.get_field('code').validators == []
|
||||
|
||||
def test_related_model_is_unique(self):
|
||||
data = {'username': 'Existing', 'email': 'new-email@example.com'}
|
||||
rs = RelatedModelSerializer(data=data)
|
||||
self.assertFalse(rs.is_valid())
|
||||
self.assertEqual(rs.errors,
|
||||
{'username': ['This field must be unique.']})
|
||||
assert not rs.is_valid()
|
||||
assert rs.errors == {'username': ['This field must be unique.']}
|
||||
data = {'username': 'new-username', 'email': 'new-email@example.com'}
|
||||
rs = RelatedModelSerializer(data=data)
|
||||
self.assertTrue(rs.is_valid())
|
||||
assert rs.is_valid()
|
||||
|
||||
def test_value_error_treated_as_not_unique(self):
|
||||
serializer = UniquenessIntegerSerializer(data={'integer': 'abc'})
|
||||
|
|
|
@ -20,8 +20,8 @@ class WriteOnlyFieldTests(TestCase):
|
|||
'password': '123'
|
||||
}
|
||||
serializer = self.Serializer(data=data)
|
||||
self.assertTrue(serializer.is_valid())
|
||||
self.assertEqual(serializer.validated_data, data)
|
||||
assert serializer.is_valid()
|
||||
assert serializer.validated_data == data
|
||||
|
||||
def write_only_fields_are_not_present_on_output(self):
|
||||
instance = {
|
||||
|
@ -29,4 +29,4 @@ class WriteOnlyFieldTests(TestCase):
|
|||
'password': '123'
|
||||
}
|
||||
serializer = self.Serializer(instance)
|
||||
self.assertEqual(serializer.data, {'email': 'foo@example.com'})
|
||||
assert serializer.data == {'email': 'foo@example.com'}
|
||||
|
|
Loading…
Reference in New Issue
Block a user