def test_groups_list(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) create_group({'group_name': 'test', 'description': 'foo'}, sqla_session=session) create_group({'group_name': 'test2', 'description': 'foo2'}, sqla_session=session) url_path = '/api/0.1/groups' headers = {str('x-testscaffold-auth-token'): str(token)} response = full_app.get(url_path, status=200, headers=headers) items = response.json assert len(items) == 2
def test_groups_list(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) create_group( {"group_name": "test", "description": "foo"}, sqla_session=session ) create_group( {"group_name": "test2", "description": "foo2"}, sqla_session=session ) url_path = "/api/0.1/groups" headers = {str("x-testscaffold-auth-token"): str(token)} response = full_app.get(url_path, status=200, headers=headers) items = response.json assert len(items) == 2
def test_user_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {"group_name": "test"}, permissions=["root_administration", "admin_panel"], sqla_session=session, ) user_a = create_user( {"user_name": "aaaa", "email": "foo"}, sqla_session=session ) user_b = create_user( {"user_name": "bbbb", "email": "foo2"}, sqla_session=session ) group.users.append(user_a) group.users.append(user_b) url_path = "/api/0.1/groups/{}/users".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} qs = parse.urlencode({"user_name": user_b.user_name}) assert len(group.users) == 2 full_app.delete("{}?{}".format(url_path, qs), status=200, headers=headers) sqla_session.expire_all() assert group.users[0].id == user_a.id
def test_group_permission_remove_proper(self, full_app, sqla_session): perm_name = 'edit' with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'aaaa'}, sqla_session=session) resource = create_entry({ 'resource_name': 'entry-x', 'note': 'x' }, sqla_session=session) perm_inst = GroupResourcePermission(group_id=group.id, perm_name=perm_name) resource.group_permissions.append(perm_inst) node_id = resource.resource_id qs = parse.urlencode({'group_id': group.id, 'perm_name': perm_name}) url_path = '/api/0.1/resources/{}/group_permissions?{}'.format( node_id, qs) headers = {str('x-testscaffold-auth-token'): str(token)} response = full_app.delete(url_path, status=200, headers=headers) perm_inst = GroupResourcePermissionService.get(group.id, resource_id=node_id, perm_name=perm_name, db_session=sqla_session) assert not isinstance(perm_inst, GroupResourcePermission)
def test_group_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'testX'}, sqla_session=session) url_path = '/api/0.1/groups/{}'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} full_app.delete_json(url_path, status=200, headers=headers)
def test_group_permission_add_proper(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'aaaa'}, sqla_session=session) resource = create_entry({ 'resource_name': 'entry-x', 'note': 'x' }, sqla_session=session) node_id = resource.resource_id url_path = '/api/0.1/resources/{}/group_permissions'.format(node_id) headers = {str('x-testscaffold-auth-token'): str(token)} perm_name = 'edit' perm_dict = {'group_id': group.id, 'perm_name': perm_name} response = full_app.post_json(url_path, perm_dict, status=200, headers=headers) assert response.json['group_id'] == group.id assert response.json['perm_name'] == perm_name assert response.json['resource_id'] == node_id perm_inst = GroupResourcePermissionService.get(group.id, resource_id=node_id, perm_name=perm_name, db_session=sqla_session) assert isinstance(perm_inst, GroupResourcePermission)
def test_group_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({"group_name": "testX"}, sqla_session=session) url_path = "/api/0.1/groups/{}".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} full_app.delete_json(url_path, status=200, headers=headers)
def test_user_delete_not_found(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {'group_name': 'test'}, permissions=['root_administration', 'admin_panel'], sqla_session=session) url_path = '/api/0.1/groups/{}/users'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} full_app.delete(url_path, status=404, headers=headers)
def test_permission_add(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({"group_name": "test"}, sqla_session=session) url_path = "/api/0.1/groups/{}/permissions".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} permission = {"perm_name": "root_administration"} assert not list(group.permissions) full_app.post_json(url_path, permission, status=200, headers=headers) sqla_session.expire_all() assert group.permissions[0].perm_name == "root_administration"
def test_user_delete_not_found(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {"group_name": "test"}, permissions=["root_administration", "admin_panel"], sqla_session=session, ) url_path = "/api/0.1/groups/{}/users".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} full_app.delete(url_path, status=404, headers=headers)
def test_permission_add(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'test'}, sqla_session=session) url_path = '/api/0.1/groups/{}/permissions'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} permission = { 'perm_name': 'root_administration', } assert not list(group.permissions) full_app.post_json(url_path, permission, status=200, headers=headers) sqla_session.expire_all() assert group.permissions[0].perm_name == 'root_administration'
def test_permission_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {"group_name": "test"}, permissions=["root_administration", "admin_panel"], sqla_session=session, ) url_path = "/api/0.1/groups/{}/permissions".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} permission = {"perm_name": "root_administration"} qs = parse.urlencode(permission) full_app.delete("{}?{}".format(url_path, qs), status=200, headers=headers) sqla_session.expire_all() assert group.permissions[0].perm_name == "admin_panel"
def test_group_permission_wrong_resource(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'aaaa'}, sqla_session=session) resource = create_entry({ 'resource_name': 'entry-x', 'note': 'x' }, sqla_session=session) node_id = resource.resource_id url_path = '/api/0.1/resources/{}/group_permissions'.format(-55) headers = {str('x-testscaffold-auth-token'): str(token)} perm_dict = {'group_id': group.id, 'perm_name': 'blabla'} response = full_app.post_json(url_path, perm_dict, status=404, headers=headers)
def test_group_permission_remove_wrong(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'aaaa'}, sqla_session=session) resource = create_entry({ 'resource_name': 'entry-x', 'note': 'x' }, sqla_session=session) node_id = resource.resource_id qs = parse.urlencode({'user_id': -99, 'perm_name': 'BLABLA'}) url_path = '/api/0.1/resources/{}/group_permissions?{}'.format( node_id, qs) headers = {str('x-testscaffold-auth-token'): str(token)} response = full_app.delete(url_path, status=422, headers=headers) assert 'perm_name' in response.json assert 'group_id' in response.json
def test_permission_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {'group_name': 'test'}, permissions=['root_administration', 'admin_panel'], sqla_session=session) url_path = '/api/0.1/groups/{}/permissions'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} permission = { 'perm_name': 'root_administration', } qs = parse.urlencode(permission) full_app.delete('{}?{}'.format(url_path, qs), status=200, headers=headers) sqla_session.expire_all() assert group.permissions[0].perm_name == 'admin_panel'
def test_group_patch(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {'group_name': 'testX', 'description': 'testX'}, sqla_session=session) url_path = '/api/0.1/groups/{}'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} group_dict = { 'id': -9, 'group_name': 'some-new_groupCHANGED', 'description': 'changed' } response = full_app.patch_json(url_path, group_dict, status=200, headers=headers) assert response.json['id'] == group.id assert group_dict['group_name'] == response.json['group_name'] assert group_dict['description'] == response.json['description']
def test_user_add(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({'group_name': 'test'}, sqla_session=session) user_a = create_user({'user_name': 'aaaa', 'email': 'foo'}, sqla_session=session) user_b = create_user({'user_name': 'bbbb', 'email': 'foo2'}, sqla_session=session) url_path = '/api/0.1/groups/{}/users'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} assert not list(group.users) full_app.post_json(url_path, {'user_name': user_a.user_name}, status=200, headers=headers) full_app.post_json(url_path, {'user_name': user_b.user_name}, status=200, headers=headers) sqla_session.expire_all() assert len(group.users) == 2
def test_group_patch(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {"group_name": "testX", "description": "testX"}, sqla_session=session ) url_path = "/api/0.1/groups/{}".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} group_dict = { "id": -9, "group_name": "some-new_groupCHANGED", "description": "changed", } response = full_app.patch_json( url_path, group_dict, status=200, headers=headers ) assert response.json["id"] == group.id assert group_dict["group_name"] == response.json["group_name"] assert group_dict["description"] == response.json["description"]
def test_user_add(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group({"group_name": "test"}, sqla_session=session) user_a = create_user( {"user_name": "aaaa", "email": "foo"}, sqla_session=session ) user_b = create_user( {"user_name": "bbbb", "email": "foo2"}, sqla_session=session ) url_path = "/api/0.1/groups/{}/users".format(group.id) headers = {str("x-testscaffold-auth-token"): str(token)} assert not list(group.users) full_app.post_json( url_path, {"user_name": user_a.user_name}, status=200, headers=headers ) full_app.post_json( url_path, {"user_name": user_b.user_name}, status=200, headers=headers ) sqla_session.expire_all() assert len(group.users) == 2
def test_user_delete(self, full_app, sqla_session): with session_context(sqla_session) as session: admin, token = create_admin(session) group = create_group( {'group_name': 'test'}, permissions=['root_administration', 'admin_panel'], sqla_session=session) user_a = create_user({'user_name': 'aaaa', 'email': 'foo'}, sqla_session=session) user_b = create_user({'user_name': 'bbbb', 'email': 'foo2'}, sqla_session=session) group.users.append(user_a) group.users.append(user_b) url_path = '/api/0.1/groups/{}/users'.format(group.id) headers = {str('x-testscaffold-auth-token'): str(token)} qs = parse.urlencode({'user_name': user_b.user_name}) assert len(group.users) == 2 full_app.delete('{}?{}'.format(url_path, qs), status=200, headers=headers) sqla_session.expire_all() assert group.users[0].id == user_a.id