def test_global_permission_manager(self):
        from serious_django_permissions.models import GlobalPermission
        create_permissions.Command().handle()
        query = GlobalPermission.objects.get_queryset()

        for item in query:
            self.assertTrue(isinstance(item, GlobalPermission))
    def test_create_global_permission(self):
        perm = Permission.objects.filter(codename=GlobalPermission.codename)
        self.assertFalse(perm,
                         'The permission should not exist yet, but it does.')

        create_permissions.Command().handle()

        perm = Permission.objects.filter(codename=GlobalPermission.codename)
        self.assertTrue(perm, 'The permission should exist, but it doesnt.')
    def test_create_explicit_referencing_permissions(self):
        perm = Permission.objects.filter(
            codename=ExplicitReferenceToRestrictedModelPermission.codename)
        self.assertFalse(perm,
                         'The permission should not exist yet, but it does.')

        create_permissions.Command().handle()

        perm = Permission.objects.filter(
            codename=ExplicitReferenceToRestrictedModelPermission.codename)
        self.assertTrue(perm, 'The permission should exist, but it doesnt.')
    def setUp(self):
        self.authorized_user = get_user_model().objects.create(
            username='******')
        self.unauthorized_user = get_user_model().objects.create(
            username='******')
        create_permissions.Command().handle()
        create_groups.Command().handle()

        self.authorized_user.groups.add(AuthorizedGroup)

        self.factory = RequestFactory()
    def setUpTestData(cls):
        create_permissions.Command().handle()

        cls.authorized_user = get_user_model().objects.create(
            username='******')
        perm = GlobalPermission.get()
        cls.authorized_user.user_permissions.add(perm)

        cls.unauthorized_user = get_user_model().objects.create(
            username='******')

        cls.factory = RequestFactory()
    def setUpTestData(cls):
        create_permissions.Command().handle()

        cls.authorized_user = get_user_model().objects.create(
            username='******')
        cls.authorized_user_explicit = get_user_model().objects.create(
            username='******')
        perm = RestrictedModelPermission.get()
        cls.authorized_user.user_permissions.add(perm)
        explicit_perm = ExplicitReferenceToRestrictedModelPermission.get()
        cls.authorized_user_explicit.user_permissions.add(explicit_perm)

        cls.unauthorized_user = get_user_model().objects.create(
            username='******')

        cls.factory = RequestFactory()
    def setUp(self):
        create_permissions.Command().handle()

        self.authorized_user = get_user_model().objects.create(
            username='******')
        RestrictedModelPermission.get()  # create the permission in the DB
 def setUp(self):
     create_permissions.Command().handle()
     create_groups.Command().handle()
     self.test_user = get_user_model().objects.create_user(
         username="******", password="******"
     )