def test_error_on_group_member_id_or_email_not_set(test_client, api_headers_bearer, insert_tokens): password = "******" user = User(first_name="Max", last_name="Muster", email="*****@*****.**", password=password) user = insert_user(user) tokens = insert_tokens(user.email) group_data = { "name": "Muster", "members": [ { "id": user.id, }, { } ] } response = test_client.post("/groups", headers=api_headers_bearer( tokens["access_token"]["token"]), data=json.dumps(group_data)) json_response = json.loads(response.get_data(as_text=True)) assert response.status_code == 400 assert json_response["message"] == "Attribute id or email needs to be set" assert len(get_all_groups()) == 0
def test_error_on_user_not_in_group(test_client, api_headers_bearer, insert_tokens): password = "******" user1 = User(first_name="Max", last_name="Muster", email="*****@*****.**", password=password) insert_user(user1) tokens = insert_tokens(user1.email) user2 = User(first_name="Max", last_name="Muster", email="*****@*****.**", password=password) insert_user(user2) group_data = { "name": "Muster", "members": [ { "id": user2.id, } ] } response = test_client.post("/groups", headers=api_headers_bearer( tokens["access_token"]["token"]), data=json.dumps(group_data)) json_response = json.loads(response.get_data(as_text=True)) assert response.status_code == 400 assert json_response["message"] == "User who created group must be group member" assert len(get_all_groups()) == 0
def test_get_all_groups(app): g1 = Group(name="G1") g2 = Group(name="G2") insert_group(g1) insert_group(g2) groups = get_all_groups() assert len(groups) == 2 assert groups[0].name == g1.name assert groups[1].name == g2.name
def test_error_on_members_missing(test_client, api_headers_bearer, insert_tokens): password = "******" user = User(first_name="Max", last_name="Muster", email="*****@*****.**", password=password) user = insert_user(user) tokens = insert_tokens(user.email) group_data = { "name": "Group" } response = test_client.post("/groups", headers=api_headers_bearer( tokens["access_token"]["token"]), data=json.dumps(group_data)) json_response = json.loads(response.get_data(as_text=True)) assert response.status_code == 400 assert json_response["message"] == "Missing attribute members" assert len(get_all_groups()) == 0
def test_dont_add_user_if_group_not_exist(test_client, api_headers_bearer, insert_tokens): password = "******" user = User(first_name="Max", last_name="Muster", email="*****@*****.**", password=password) user = insert_user(user) tokens = insert_tokens(user.email) group_add_user_data = { "user_id": user.id, } response = test_client.post("/groups/1/members", headers=api_headers_bearer( tokens["access_token"]["token"]), data=json.dumps(group_add_user_data)) json_response = json.loads(response.get_data(as_text=True)) assert response.status_code == 401 assert json_response["message"] == "Group does not exist" assert len(get_all_groups()) == 0