import pytest import requests import json OK = 200 CREATED = 201 NOT_FOUND = 404 NOT_ACCEPTABLE = 406 CONFLICT = 409 from constants import WEBSITE_PREFIX def test_group_apis(): from user_test import register_user, get_user, delete_user resp = register_user('pytest-group-user', 'password') assert(resp.status_code == CREATED) resp = get_user('pytest-group-user') user = json.loads(resp.text) assert(user['userName'] == 'pytest-group-user') resp = create_group({ 'name': 'Pytest-Group', }) assert(resp.status_code == OK) create_group({ 'name': 'Child-Group' }) assert(resp.status_code == OK) root_group = json.loads(get_group_by_name('Pytest-Group').text) child_group = json.loads(get_group_by_name('Child-Group').text) resp = edit_group(child_group['id'], { 'parentGroupId' : root_group['id'] }) assert(resp.status_code == OK) resp = add_user_to_group(child_group['id'], user) assert(resp.status_code == OK) resp = remove_user_from_group(child_group['id'], user) assert(resp.status_code == OK) resp = remove_user_from_group(child_group['id'], user) assert(resp.status_code == NOT_ACCEPTABLE) delete_user(user['userName']) delete_group(child_group['id']) delete_group(root_group['id']) def get_group(gid): url = WEBSITE_PREFIX + '/groups/' + gid return requests.get(url) def get_group_by_name(group_name): url = WEBSITE_PREFIX + '/groups' + '?group=' + group_name return requests.get(url) def get_all_groups_by_user(user_name): url = WEBSITE_PREFIX + '/groups' + '?user=' + user_name return requests.get(url) def create_group(group): url = WEBSITE_PREFIX + '/groups' return requests.post(url, json=group) def edit_group(gid, updatedGroup): url = WEBSITE_PREFIX + '/groups/' + gid return requests.put(url, json=updatedGroup) def delete_group(gid): url = WEBSITE_PREFIX + '/admin/groups/' + gid return requests.delete(url) def add_user_to_group(gid, user): url = WEBSITE_PREFIX + '/admin/groups/' + gid + '/users' return requests.post(url, json=user) def remove_user_from_group(gid, user): url = WEBSITE_PREFIX + '/admin/groups/' + gid + '/users' return requests.delete(url, json=user)