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):
|
def test_doesnt_pollute_model(self):
|
||||||
instance = AnotherUniquenessModel.objects.create(code='100')
|
instance = AnotherUniquenessModel.objects.create(code='100')
|
||||||
serializer = AnotherUniquenessSerializer(instance)
|
serializer = AnotherUniquenessSerializer(instance)
|
||||||
self.assertEqual(
|
assert AnotherUniquenessModel._meta.get_field('code').validators == []
|
||||||
AnotherUniquenessModel._meta.get_field('code').validators, [])
|
|
||||||
|
|
||||||
# Accessing data shouldn't effect validators on the model
|
# Accessing data shouldn't effect validators on the model
|
||||||
serializer.data
|
serializer.data
|
||||||
self.assertEqual(
|
assert AnotherUniquenessModel._meta.get_field('code').validators == []
|
||||||
AnotherUniquenessModel._meta.get_field('code').validators, [])
|
|
||||||
|
|
||||||
def test_related_model_is_unique(self):
|
def test_related_model_is_unique(self):
|
||||||
data = {'username': 'Existing', 'email': 'new-email@example.com'}
|
data = {'username': 'Existing', 'email': 'new-email@example.com'}
|
||||||
rs = RelatedModelSerializer(data=data)
|
rs = RelatedModelSerializer(data=data)
|
||||||
self.assertFalse(rs.is_valid())
|
assert not rs.is_valid()
|
||||||
self.assertEqual(rs.errors,
|
assert rs.errors == {'username': ['This field must be unique.']}
|
||||||
{'username': ['This field must be unique.']})
|
|
||||||
data = {'username': 'new-username', 'email': 'new-email@example.com'}
|
data = {'username': 'new-username', 'email': 'new-email@example.com'}
|
||||||
rs = RelatedModelSerializer(data=data)
|
rs = RelatedModelSerializer(data=data)
|
||||||
self.assertTrue(rs.is_valid())
|
assert rs.is_valid()
|
||||||
|
|
||||||
def test_value_error_treated_as_not_unique(self):
|
def test_value_error_treated_as_not_unique(self):
|
||||||
serializer = UniquenessIntegerSerializer(data={'integer': 'abc'})
|
serializer = UniquenessIntegerSerializer(data={'integer': 'abc'})
|
||||||
|
|
|
@ -20,8 +20,8 @@ class WriteOnlyFieldTests(TestCase):
|
||||||
'password': '123'
|
'password': '123'
|
||||||
}
|
}
|
||||||
serializer = self.Serializer(data=data)
|
serializer = self.Serializer(data=data)
|
||||||
self.assertTrue(serializer.is_valid())
|
assert serializer.is_valid()
|
||||||
self.assertEqual(serializer.validated_data, data)
|
assert serializer.validated_data == data
|
||||||
|
|
||||||
def write_only_fields_are_not_present_on_output(self):
|
def write_only_fields_are_not_present_on_output(self):
|
||||||
instance = {
|
instance = {
|
||||||
|
@ -29,4 +29,4 @@ class WriteOnlyFieldTests(TestCase):
|
||||||
'password': '123'
|
'password': '123'
|
||||||
}
|
}
|
||||||
serializer = self.Serializer(instance)
|
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