diff options
| author | 2019-12-19 13:52:19 -0800 | |
|---|---|---|
| committer | 2019-12-19 13:52:19 -0800 | |
| commit | 7c991b292b81f8381b1b71eaa6374c23dc8d3521 (patch) | |
| tree | 127293993f27bf73831498b505e5169680a5dd7b | |
| parent | Remove default value from the active field of infractions (diff) | |
Add tests for missing active field of infractions
| -rw-r--r-- | pydis_site/apps/api/tests/test_infractions.py | 28 | 
1 files changed, 28 insertions, 0 deletions
| diff --git a/pydis_site/apps/api/tests/test_infractions.py b/pydis_site/apps/api/tests/test_infractions.py index c59ddaed..63d1b144 100644 --- a/pydis_site/apps/api/tests/test_infractions.py +++ b/pydis_site/apps/api/tests/test_infractions.py @@ -504,6 +504,16 @@ class CreationTests(APISubdomainTestCase):              reason="An active ban for the second user"          ) +    def test_integrity_error_if_missing_active_field(self): +        pattern = 'null value in column "active" violates not-null constraint' +        with self.assertRaisesRegex(IntegrityError, pattern): +            Infraction.objects.create( +                user=self.user, +                actor=self.user, +                type='ban', +                reason='A reason.', +            ) +  class ExpandedTests(APISubdomainTestCase):      @classmethod @@ -640,3 +650,21 @@ class SerializerTests(APISubdomainTestCase):          serializer = InfractionSerializer(data=data)          self.assertTrue(serializer.is_valid(), msg=serializer.errors) + +    def test_validation_error_if_missing_active_field(self): +        data = { +            'user': self.user.id, +            'actor': self.user.id, +            'type': 'ban', +            'reason': 'A reason.', +        } +        serializer = InfractionSerializer(data=data) + +        if not serializer.is_valid(): +            self.assertIn('active', serializer.errors) + +            code = serializer.errors['active'][0].code +            msg = f'Expected failure on required active field but got {serializer.errors}' +            self.assertEqual(code, 'required', msg=msg) +        else: +            self.fail('Validation unexpectedly succeeded.') | 
