diff options
author | 2019-12-19 13:36:08 -0800 | |
---|---|---|
committer | 2019-12-19 13:36:08 -0800 | |
commit | 438e947d7edaf1f9dfa10bea0a2adf20e0ebbc9f (patch) | |
tree | 5a5e5cfb38044ea8e2716dd654bad38af2415419 | |
parent | Output errors more clearly for infraction serializer test failures (diff) |
Remove default value from the active field of infractions
Due to the active field being specified in the UniqueTogetherValidator,
the field is implicitly required. Typically default values are excluded
from this restriction but in this case some infraction types must always
be False.
It's easier and makes more sense to require the active field explicitly
rather than to write logic in the serializer which is conditional on the
type of infractions.
3 files changed, 37 insertions, 10 deletions
diff --git a/pydis_site/apps/api/migrations/0050_remove_infractions_active_default_value.py b/pydis_site/apps/api/migrations/0050_remove_infractions_active_default_value.py new file mode 100644 index 00000000..a0f03ad4 --- /dev/null +++ b/pydis_site/apps/api/migrations/0050_remove_infractions_active_default_value.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.6 on 2019-12-19 21:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0049_offensivemessage'), + ] + + operations = [ + migrations.AlterField( + model_name='infraction', + name='active', + field=models.BooleanField(help_text='Whether the infraction is still active.'), + ), + ] diff --git a/pydis_site/apps/api/models/bot/infraction.py b/pydis_site/apps/api/models/bot/infraction.py index 108fd3a2..f58e89a3 100644 --- a/pydis_site/apps/api/models/bot/infraction.py +++ b/pydis_site/apps/api/models/bot/infraction.py @@ -29,7 +29,6 @@ class Infraction(ModelReprMixin, models.Model): ) ) active = models.BooleanField( - default=True, help_text="Whether the infraction is still active." ) user = models.ForeignKey( diff --git a/pydis_site/apps/api/tests/test_infractions.py b/pydis_site/apps/api/tests/test_infractions.py index 4ed5ac25..c59ddaed 100644 --- a/pydis_site/apps/api/tests/test_infractions.py +++ b/pydis_site/apps/api/tests/test_infractions.py @@ -55,7 +55,8 @@ class InfractionTests(APISubdomainTestCase): type='ban', reason='He terk my jerb!', hidden=True, - expires_at=dt(5018, 11, 20, 15, 52, tzinfo=timezone.utc) + expires_at=dt(5018, 11, 20, 15, 52, tzinfo=timezone.utc), + active=True ) cls.ban_inactive = Infraction.objects.create( user_id=cls.user.id, @@ -185,7 +186,8 @@ class CreationTests(APISubdomainTestCase): 'type': 'ban', 'reason': 'He terk my jerb!', 'hidden': True, - 'expires_at': '5018-11-20T15:52:00+00:00' + 'expires_at': '5018-11-20T15:52:00+00:00', + 'active': True, } response = self.client.post(url, data=data) @@ -209,7 +211,8 @@ class CreationTests(APISubdomainTestCase): url = reverse('bot:infraction-list', host='api') data = { 'actor': self.user.id, - 'type': 'kick' + 'type': 'kick', + 'active': False, } response = self.client.post(url, data=data) @@ -223,7 +226,8 @@ class CreationTests(APISubdomainTestCase): data = { 'user': 1337, 'actor': self.user.id, - 'type': 'kick' + 'type': 'kick', + 'active': True, } response = self.client.post(url, data=data) @@ -237,7 +241,8 @@ class CreationTests(APISubdomainTestCase): data = { 'user': self.user.id, 'actor': self.user.id, - 'type': 'hug' + 'type': 'hug', + 'active': True, } response = self.client.post(url, data=data) @@ -252,7 +257,8 @@ class CreationTests(APISubdomainTestCase): 'user': self.user.id, 'actor': self.user.id, 'type': 'ban', - 'expires_at': '20/11/5018 15:52:00' + 'expires_at': '20/11/5018 15:52:00', + 'active': True, } response = self.client.post(url, data=data) @@ -272,7 +278,8 @@ class CreationTests(APISubdomainTestCase): 'user': self.user.id, 'actor': self.user.id, 'type': infraction_type, - 'expires_at': '5018-11-20T15:52:00+00:00' + 'expires_at': '5018-11-20T15:52:00+00:00', + 'active': False, } response = self.client.post(url, data=data) @@ -289,7 +296,8 @@ class CreationTests(APISubdomainTestCase): 'user': self.user.id, 'actor': self.user.id, 'type': infraction_type, - 'hidden': True + 'hidden': True, + 'active': False, } response = self.client.post(url, data=data) @@ -306,6 +314,7 @@ class CreationTests(APISubdomainTestCase): 'actor': self.user.id, 'type': 'note', 'hidden': False, + 'active': False, } response = self.client.post(url, data=data) @@ -541,7 +550,8 @@ class ExpandedTests(APISubdomainTestCase): data = { 'user': self.user.id, 'actor': self.user.id, - 'type': 'warning' + 'type': 'warning', + 'active': False } response = self.client.post(url, data=data) |