From 5ec223bca0f2df5be06b583f58012e115d2f52a2 Mon Sep 17 00:00:00 2001 From: Asif Saifuddin Auvi Date: Wed, 23 Nov 2016 20:05:34 +0600 Subject: [PATCH] converted validators and write_only_fields test to pytest style (#4697) --- tests/test_validators.py | 13 +++++-------- tests/test_write_only_fields.py | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/test_validators.py b/tests/test_validators.py index ab2c87c11..37e662b8e 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -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'}) diff --git a/tests/test_write_only_fields.py b/tests/test_write_only_fields.py index 3a289afab..272a05ff3 100644 --- a/tests/test_write_only_fields.py +++ b/tests/test_write_only_fields.py @@ -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'}