def test_create_duplicate_role(): """Create a new fake role resource""" insert_role({ "name": "Manager0501201901", "owners": "12345", "administrators": "12345" }) with requests.Session() as session: user_payload = { "name": "Susan Susanson", "username": "******", "password": "******", "email": "*****@*****.**", } user_response = create_test_user(session, user_payload) user_id = user_response.json()["data"]["user"]["id"] role_resource = { "name": "Manager0501201901", "owners": user_id, "administrators": user_id, } insert_role(role_resource) response = session.post("http://rbac-server:8000/api/roles", json=role_resource) assert ( response.json()["message"] == "Error: Could not create this role because the role name already exists." ) assert response.json()["code"] == 400 delete_user_by_username("susan22") delete_role_by_name("Manager0501201901")
def test_proposals(): """Create a new fake role and try to add yourself to role you created""" with requests.Session() as session: user_payload = { "name": "Susan S", "username": "******", "password": "******", "email": "*****@*****.**", } user_response = create_test_user(session, user_payload) user_id = user_response.json()["data"]["user"]["id"] role_resource = { "name": "Office_Assistant", "owners": user_id, "administrators": user_id, } insert_role(role_resource) delete_role_by_name("Office_Assistant") role_response = session.post("http://rbac-server:8000/api/roles", json=role_resource) role_id = role_response.json()["data"]["id"] insert_role(role_resource) res = session.post( "http://rbac-server:8000/api/roles/" + role_id + "/members", json=user_response.json()["data"]["user"], ) assert (res.json()["message"] == "Owner is the requester. Proposal is autoapproved") delete_user_by_username("susans2224") delete_role_by_name("Office_Assistant")