converted validators and write_only_fields test to pytest style (#4697)

This commit is contained in:
Asif Saifuddin Auvi 2016-11-23 20:05:34 +06:00 committed by Tom Christie
parent 4b59ec27fa
commit 5ec223bca0
2 changed files with 8 additions and 11 deletions

View File

@ -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'})

View File

@ -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'}