Ejemplo n.º 1
0
def _assign_perms(user, profile):
    for perm, name in ASSIGNED_PERMISSIONS.get('profile', ()):
        assign_perm(perm, user, profile)

    # Give permissions to view and change itself
    for perm, name in ASSIGNED_PERMISSIONS.get('user', ()):
        assign_perm(perm, user, user)
Ejemplo n.º 2
0
    def test_incomplete_permissions(self):
        # Delete the neccesary permissions
        content_type_user = ContentType.objects.get_for_model(User)
        for model, perms in ASSIGNED_PERMISSIONS.items():
            content_type = content_type_user
            for perm in perms:
                Permission.objects.get(name=perm[1],
                                       content_type=content_type).delete()

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            content_type = content_type_user
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1],
                                                  content_type=content_type)
                except Permission.DoesNotExist: pass
                else: self.fail("Found %s: " % perm)

        # Repair them
        call_command('check_permissions', test=True)

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            content_type = content_type_user
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1],
                                                  content_type=content_type)
                except Permission.DoesNotExist:
                    self.fail()
Ejemplo n.º 3
0
    def test_incomplete_permissions(self):
        # Delete the neccesary permissions
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                Permission.objects.get(name=perm[1]).delete()

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1])
                except Permission.DoesNotExist:
                    pass
                else:
                    self.fail()

        # Repair them
        call_command('check_permissions')

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1])
                except Permission.DoesNotExist:
                    self.fail()
Ejemplo n.º 4
0
    def setUp(self):
        # Add the models to the db.

        # Call the original method that does the fixtures etc.
        super(UserenaSignupModelTests, self).setUp()

        call_command('syncdb', interactive=False, verbosity=0)

        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                if model == 'profile':
                    model_obj = get_profile_model()
                else:
                    model_obj = get_user_model()

                model_content_type = ContentType.objects.get_for_model(
                    model_obj)

                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)
    def test_incomplete_permissions(self):  # noqa:C901
        # Delete the neccesary permissions
        profile_model_obj = get_profile_model()
        content_type_profile = ContentType.objects.get_for_model(
            profile_model_obj)
        content_type_user = ContentType.objects.get_for_model(User)
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == "profile":
                content_type = content_type_profile
            else:
                content_type = content_type_user
            for perm in perms:
                Permission.objects.get(name=perm[1],
                                       content_type=content_type).delete()

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == "profile":
                content_type = content_type_profile
            else:
                content_type = content_type_user
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1],
                                                  content_type=content_type)
                except Permission.DoesNotExist:
                    pass
                else:
                    self.fail("Found %s: " % perm)

        # Repair them
        call_command("check_permissions", test=True)

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == "profile":
                content_type = content_type_profile
            else:
                content_type = content_type_user
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1],
                                                  content_type=content_type)
                except Permission.DoesNotExist:
                    self.fail()
Ejemplo n.º 6
0
    def test_incomplete_permissions(self):
        # Delete the neccesary permissions
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                Permission.objects.get(name=perm[1]).delete()

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1])
                except Permission.DoesNotExist: pass
                else: self.fail()

        # Repair them
        call_command('check_permissions')

        # Check if they are they are back
        for model, perms in ASSIGNED_PERMISSIONS.items():
            for perm in perms:
                try:
                    perm = Permission.objects.get(name=perm[1])
                except Permission.DoesNotExist:
                    self.fail()