aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
authorGravatar D0rs4n <[email protected]>2021-08-31 19:21:36 +0200
committerGravatar D0rs4n <[email protected]>2021-11-26 21:14:16 +0100
commitf34a52016bd5a7d50c1146d6fbd213ce889f58c7 (patch)
tree358f03d4735a91391272070c9eb27c60318be70c /pydis_site
parentPatch roles test to use fresh instance from the DB (diff)
Patch signals to use post_delete, instead of pre_delete
From now on the signal will only get executed after the Role has been deleted The commit also introduces minor changes in the tests of roles
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/apps/api/signals.py4
-rw-r--r--pydis_site/apps/api/tests/test_roles.py5
2 files changed, 4 insertions, 5 deletions
diff --git a/pydis_site/apps/api/signals.py b/pydis_site/apps/api/signals.py
index c69704b1..5c26bfb6 100644
--- a/pydis_site/apps/api/signals.py
+++ b/pydis_site/apps/api/signals.py
@@ -1,10 +1,10 @@
-from django.db.models.signals import pre_delete
+from django.db.models.signals import post_delete
from django.dispatch import receiver
from pydis_site.apps.api.models.bot import Role, User
-@receiver(signal=pre_delete, sender=Role)
+@receiver(signal=post_delete, sender=Role)
def delete_role_from_user(sender: Role, instance: Role, **kwargs) -> None:
"""Unassigns the Role (instance) that is being deleted from every user that has it."""
for user in User.objects.filter(roles__contains=[instance.id]):
diff --git a/pydis_site/apps/api/tests/test_roles.py b/pydis_site/apps/api/tests/test_roles.py
index 88c0256b..73c80c77 100644
--- a/pydis_site/apps/api/tests/test_roles.py
+++ b/pydis_site/apps/api/tests/test_roles.py
@@ -4,7 +4,6 @@ from .base import AuthenticatedAPITestCase
from ..models import Role, User
-
class CreationTests(AuthenticatedAPITestCase):
@classmethod
def setUpTestData(cls):
@@ -96,11 +95,11 @@ class CreationTests(AuthenticatedAPITestCase):
url = reverse('api:bot:role-list')
response = self.client.get(url)
- self.assertContains(response, text="id", count=4, status_code=200)
+ self.assertContains(response, text="id", count=5, status_code=200)
roles = response.json()
self.assertIsInstance(roles, list)
- self.assertEqual(len(roles), 4)
+ self.assertEqual(len(roles), 5)
for role in roles:
self._validate_roledict(role)