def test_monkey_patch(self, mocked_get_user_model):
        class CustomUserTestClass(AbstractUser):
            pass

        mocked_get_user_model.return_value = CustomUserTestClass

        self.assertFalse(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertFalse(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertFalse(getattr(CustomUserTestClass, 'del_obj_perm', False))

        # Monkey Patch
        guardian.monkey_patch_user()

        self.assertTrue(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertTrue(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertTrue(getattr(CustomUserTestClass, 'del_obj_perm', False))
    def test_monkey_patch(self, mocked_get_user_model):

        class CustomUserTestClass(AbstractUser):
            pass

        mocked_get_user_model.return_value = CustomUserTestClass

        self.assertFalse(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertFalse(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertFalse(getattr(CustomUserTestClass, 'del_obj_perm', False))

        # Monkey Patch
        guardian.monkey_patch_user()

        self.assertTrue(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertTrue(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertTrue(getattr(CustomUserTestClass, 'del_obj_perm', False))
Exemple #3
0
    def test_monkey_patch(self, mocked_get_user_model):
        # Import AbstractUser here as it is only available since Django 1.5
        from django.contrib.auth.models import AbstractUser

        class CustomUserTestClass(AbstractUser):
            pass

        mocked_get_user_model.return_value = CustomUserTestClass

        self.assertFalse(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertFalse(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertFalse(getattr(CustomUserTestClass, 'del_obj_perm', False))

        # Monkey Patch
        guardian.monkey_patch_user()

        self.assertTrue(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertTrue(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertTrue(getattr(CustomUserTestClass, 'del_obj_perm', False))
Exemple #4
0
    def test_monkey_patch(self, mocked_get_user_model):
        # Import AbstractUser here as it is only available since Django 1.5
        from django.contrib.auth.models import AbstractUser

        class CustomUserTestClass(AbstractUser):
            pass

        mocked_get_user_model.return_value = CustomUserTestClass

        self.assertFalse(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertFalse(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertFalse(getattr(CustomUserTestClass, 'del_obj_perm', False))

        # Monkey Patch
        guardian.monkey_patch_user()

        self.assertTrue(getattr(CustomUserTestClass, 'get_anonymous', False))
        self.assertTrue(getattr(CustomUserTestClass, 'add_obj_perm', False))
        self.assertTrue(getattr(CustomUserTestClass, 'del_obj_perm', False))