diff options
| author | 2021-08-31 17:54:39 +0200 | |
|---|---|---|
| committer | 2021-11-26 21:14:16 +0100 | |
| commit | 0f24bdcd0ba261da045ac73e8567239eb63c6fc6 (patch) | |
| tree | 0371b5357f8102006d57ddd6434ecd1ba7a9adef /pydis_site/apps/api | |
| parent | Create a signal to unassign roles from user when deleted (diff) | |
Add test to check role unassignment
Create a test that checks if a role gets deleted it will also get unassigned from the user
Diffstat (limited to 'pydis_site/apps/api')
| -rw-r--r-- | pydis_site/apps/api/tests/test_roles.py | 22 | 
1 files changed, 21 insertions, 1 deletions
| diff --git a/pydis_site/apps/api/tests/test_roles.py b/pydis_site/apps/api/tests/test_roles.py index d39cea4d..7c968852 100644 --- a/pydis_site/apps/api/tests/test_roles.py +++ b/pydis_site/apps/api/tests/test_roles.py @@ -1,7 +1,8 @@  from django.urls import reverse  from .base import AuthenticatedAPITestCase -from ..models import Role +from ..models import Role, User +  class CreationTests(AuthenticatedAPITestCase): @@ -35,6 +36,20 @@ class CreationTests(AuthenticatedAPITestCase):              permissions=6,              position=0,          ) +        cls.role_to_delete = Role.objects.create( +            id=7, +            name="role to delete", +            colour=7, +            permissions=7, +            position=0, +        ) +        cls.role_unassigned_test_user = User.objects.create( +            id=8, +            name="role_unassigned_test_user", +            discriminator="0000", +            roles=[cls.role_to_delete.id], +            in_guild=True +        )      def _validate_roledict(self, role_dict: dict) -> None:          """Helper method to validate a dict representing a role.""" @@ -181,6 +196,11 @@ class CreationTests(AuthenticatedAPITestCase):          response = self.client.delete(url)          self.assertEqual(response.status_code, 204) +    def test_role_delete_unassigned(self): +        """Tests if the deleted Role gets unassigned from the user.""" +        self.role_to_delete.delete() +        self.assertEqual(self.role_unassigned_test_user.roles, []) +      def test_role_detail_404_all_methods(self):          """Tests detail view with non-existing ID."""          url = reverse('api:bot:role-detail', args=(20190815,)) | 
