Skip to content

Commit

Permalink
added tests for get unavailability
Browse files Browse the repository at this point in the history
  • Loading branch information
hafizhasyimm committed Mar 15, 2024
1 parent 297bb6d commit ecbe676
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/functional/test_unavailability_get.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ecbe676

Please sign in to comment.