def test_permission_group_form_updates_members(regular_user): with replace_modules([ARestrictedTestModule]): modules = [m for m in get_modules()] test_module = modules[0] module_permissions = test_module.get_required_permissions() assert module_permissions group = get_default_permission_group() form = PermissionGroupForm(instance=group, prefix=None) assert not group.permissions.all() assert not group.user_set.all() data = { "name": "New Name", "modules": [force_text(test_module.name)], "members": [force_text(regular_user.pk)], } form = PermissionGroupForm(instance=group, prefix=None, data=data) form.save() module_permissions = [get_permission_object_from_string(m) for m in module_permissions] assert group.name == "New Name" assert set(module_permissions) == set(group.permissions.all()) assert regular_user in group.user_set.all() form = PermissionGroupForm(instance=group, prefix=None, data={"name": "Name"}) form.save() assert not group.permissions.all() assert not group.user_set.all()
def test_permission_group_form_updates_members(): with replace_modules([ARestrictedTestModule]): modules = [m for m in get_modules()] test_module = modules[0] module_permissions = test_module.get_required_permissions() assert module_permissions group = get_default_permission_group() PermissionGroupForm(instance=group, prefix=None) assert not group.permissions.all() assert not group.user_set.all() data = { "name": "New Name", } for permission in ARestrictedTestModule().get_required_permissions(): data["perm:%s" % permission] = permission form = PermissionGroupForm(instance=group, prefix=None, data=data) form.save() assert group.name == "New Name" assert set(module_permissions) == get_permissions_from_group(group) form = PermissionGroupForm(instance=group, prefix=None, data={"name": "Name"}) form.save() assert not group.permissions.all() assert not group.user_set.all()
def test_only_show_modules_with_defined_names(): """ Make sure that only modules with defined names are show as choices in admin. """ form = PermissionGroupForm(prefix=None) assert AdminModule.name not in form.admin_modules
def test_only_show_modules_with_defined_names(): """ Make sure that only modules with defined names are show as choices in admin. """ form = PermissionGroupForm(prefix=None) choices = [name for (name, value) in form.fields["modules"].choices] assert AdminModule.name not in choices