def test_set_resources_to_role_with_existing_resources_no_overlap(self): resources = [{ 'name': 'resource1', 'permissions': ['create'] }, { 'name': 'resource2', 'permissions': ['create'] }, { 'name': 'resource3', 'permissions': ['create'] }] role = Role(name='test', resources=resources) new_resources = [{ 'name': 'resource4', 'permissions': ['create'] }, { 'name': 'resource5', 'permissions': ['create'] }, { 'name': 'resource6', 'permissions': ['create'] }] role.set_resources(new_resources) db.session.add(role) self.assertRoleConstructionIsCorrect(role, 'test', resources=new_resources)
def test_set_resources_update_permissions(self): resources = [{ 'name': 'resource1', 'permissions': ['create'] }, { 'name': 'resource2', 'permissions': ['create'] }, { 'name': 'resource3', 'permissions': ['create'] }] role = Role(name='test', resources=resources) db.session.add(role) db.session.commit() new_resources = [{ 'name': 'resource1', 'permissions': ['read'] }, { 'name': 'resource2', 'permissions': ['update'] }, { 'name': 'resource3', 'permissions': ['delete'] }] role.set_resources(new_resources) db.session.commit() self.assertRoleConstructionIsCorrect(role, 'test', resources=new_resources)
def test_set_resources_to_role_with_no_resources_and_no_resources_in_db(self): role = Role(name='test') resources = [{'name': 'resource1', 'permissions': ['create']}, {'name': 'resource2', 'permissions': ['create']}] role.set_resources(resources) db.session.add(role) self.assertRoleConstructionIsCorrect(role, 'test', resources=resources)
def test_set_resources_to_role_with_existing_resources_with_overlap(self): resources = [{'name': 'resource1', 'permissions': ['create']}, {'name': 'resource2', 'permissions': ['create']}, {'name': 'resource3', 'permissions': ['create']}] role = Role(name='test', resources=resources) new_resources = [{'name': 'resource3', 'permissions': ['create']}, {'name': 'resource4', 'permissions': ['create']}, {'name': 'resource5', 'permissions': ['create']}] role.set_resources(new_resources) db.session.add(role) self.assertRoleConstructionIsCorrect(role, 'test', resources=new_resources)
def test_set_resources_update_permissions(self): resources = [{'name': 'resource1', 'permissions': ['create']}, {'name': 'resource2', 'permissions': ['create']}, {'name': 'resource3', 'permissions': ['create']}] role = Role(name='test', resources=resources) db.session.add(role) db.session.commit() new_resources = [{'name': 'resource1', 'permissions': ['read']}, {'name': 'resource2', 'permissions': ['update']}, {'name': 'resource3', 'permissions': ['delete']}] role.set_resources(new_resources) db.session.commit() self.assertRoleConstructionIsCorrect(role, 'test', resources=new_resources)
def test_set_resources_to_role_no_resources_to_add(self): role = Role(name='test') role.set_resources({}) self.assertListEqual(role.resources, [])