From ecbe676d009809e42eec18fe78b434cf6f7fbcb4 Mon Sep 17 00:00:00 2001 From: Muhammad Hafizh Hasyim Date: Fri, 15 Mar 2024 17:03:25 +1100 Subject: [PATCH] added tests for get unavailability --- tests/functional/test_unavailability_get.py | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/functional/test_unavailability_get.py diff --git a/tests/functional/test_unavailability_get.py b/tests/functional/test_unavailability_get.py new file mode 100644 index 00000000..d552a40c --- /dev/null +++ b/tests/functional/test_unavailability_get.py @@ -0,0 +1,40 @@ +def test_get_volunteer_unavailability_success(test_client): + user_id = 6 # Assuming this user has at least one unavailability record + response = test_client.get(f"/v2/volunteers/{user_id}/unavailability") + assert response.status_code == 200 + assert "unavailability" in response.json # Assuming the response includes an 'unavailability' key + assert isinstance(response.json["unavailability"], list) # Assuming the unavailability records are returned as a + # list + + +def test_get_volunteer_unavailability_no_records(test_client): + user_id = 50 # Assuming this user has no unavailability records + response = test_client.get(f"/v2/volunteers/{user_id}/unavailability") + assert response.status_code == 400 # Assuming the endpoint returns a 400 status for no records found + assert response.json == {'userID': user_id, 'success': False} # Expected response body for no records + + +def test_get_volunteer_unavailability_invalid_user(test_client): + user_id = -1 # Non-existent user ID + response = test_client.get(f"/v2/volunteers/{user_id}/unavailability") + # Assuming the system treats requests for non-existent users as bad requests or not found + assert response.status_code == 404 + assert response.json == {"message": "User not found"} # Assuming this is the response for an invalid user ID + + +# This is not yet implemented in the get method +def test_get_volunteer_unavailability_unauthorized(test_client): + user_id = 30 + # This test assumes that the endpoint requires authentication and that the test client is not authenticated + response = test_client.get(f"/v2/volunteers/{user_id}/unavailability") + assert response.status_code == 401 # Unauthorized access + assert "error" in response.json # Checking for an error message in the response + + +# This is not yet implemented in the get method +def test_get_volunteer_unavailability_forbidden(test_client): + user_id = 31 + # Assuming the test client is authenticated as a different user without permissions to access this user's data + response = test_client.get(f"/v2/volunteers/{user_id}/unavailability") + assert response.status_code == 403 # Forbidden access + assert "error" in response.json # Checking for an error message indicating lack of permissions