def test_update_invalid_duplicate_name(self): role1 = ckanext_factories.Role() role2 = ckanext_factories.Role() input_dict = { 'id': role1['id'], 'name': role2['name'], } result, obj = self.test_action('role_update', should_error=True, **input_dict) assert_error(result, 'name', 'Duplicate name')
def test_user_role_unassign_invalid_not_assigned(self): role = ckanext_factories.Role() org = ckan_factories.Organization() result, _ = self.test_action('user_role_unassign', should_error=True, user_id=self.normal_user['id'], role_id=role['id'], organization_id=org['id']) assert_error(result, 'message', 'The user does not have the specified role')
def test_permission_revoke_invalid_not_granted(self): role = ckanext_factories.Role() permission = ckanext_factories.Permission() result, _ = self.test_action('role_permission_revoke', should_error=True, role_id=role['name'], content_type=permission['content_type'], operation=permission['operation']) assert_error(result, 'message', 'The role does not have the specified permission')
def test_permission_grant_valid(self): role = ckanext_factories.Role() permission = ckanext_factories.Permission() self.test_action('role_permission_grant', role_id=role['name'], content_type=permission['content_type'], operation=permission['operation']) role_permission = extmodel.RolePermission.lookup(role['id'], permission['content_type'], permission['operation']) assert role_permission and role_permission.state == 'active'
def test_user_role_assign_invalid_deleted_role(self): role = ckanext_factories.Role() org = ckan_factories.Organization() call_action('role_delete', id=role['id']) result, _ = self.test_action('user_role_assign', should_error=True, exception_class=tk.ObjectNotFound, user_id=self.normal_user['name'], role_id=role['name'], organization_id=org['name']) assert_error(result, '', 'Not found: Role')
def test_user_role_assign_valid(self): role = ckanext_factories.Role() org = ckan_factories.Organization() self.test_action('user_role_assign', user_id=self.normal_user['name'], role_id=role['name'], organization_id=org['name']) user_role = extmodel.UserRole.lookup(self.normal_user['id'], role['id'], org['id']) assert user_role and user_role.state == 'active'
def test_update_valid_partial(self): role = ckanext_factories.Role() input_dict = { 'id': role['id'], 'title': 'Updated Test Role', } result, obj = self.test_action('role_update', **input_dict) assert obj.title == input_dict['title'] assert obj.name == role['name'] assert obj.description == role['description']
def test_update_valid(self): role = ckanext_factories.Role() input_dict = { 'id': role['id'], 'name': 'updated-test-role', 'title': 'Updated Test Role', 'description': 'Updated test role', } result, obj = self.test_action('role_update', **input_dict) assert_object_matches_dict(obj, input_dict)
def _prepare_user_privilege(self): self.user = ckan_factories.User() self.org = ckan_factories.Organization() self.role = ckanext_factories.Role() self.user_role = ckanext_factories.UserRole( role_id=self.role['id'], user_id=self.user['id'], organization_id=self.org['id']) self.permission = ckanext_factories.Permission() self.role_permission = ckanext_factories.RolePermission( role_id=self.role['id'], content_type=self.permission['content_type'], operation=self.permission['operation'])
def test_delete_valid(self): role = ckanext_factories.Role() self.test_action('role_delete', id=role['id'])
def test_create_invalid_duplicate_name(self): role = ckanext_factories.Role() result, obj = self.test_action('role_create', should_error=True, name=role['name']) assert_error(result, 'name', 'Duplicate name')