Skip to content

Commit

Permalink
Add template deletion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anarute committed Oct 24, 2023
1 parent e3825db commit affd921
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions api/tests/routers/v1/test_timelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,52 @@ def test_cannot_update_other_users_template(client: TestClient, get_regular_user
assert response.status_code == HTTPStatus.FORBIDDEN
res = response.json()
assert res["detail"] == "You are not authorized to create or update templates for this user"


def test_delete_template(client: TestClient, get_regular_user_token_headers: Dict[str, str]) -> None:
# Check existing templates first
response = client.get(
f"{API_BASE_URL}/v1/timelog/templates/", headers=get_regular_user_token_headers, params={"user_id": 1}
)
assert response.status_code == HTTPStatus.OK
templates = response.json()
assert len(templates) == 2

response = client.delete(
f"{API_BASE_URL}/v1/timelog/templates/1",
headers=get_regular_user_token_headers,
params={"user_id": 1},
)
assert response.status_code == HTTPStatus.NO_CONTENT

# There should be only one template now
response = client.get(
f"{API_BASE_URL}/v1/timelog/templates/", headers=get_regular_user_token_headers, params={"user_id": 1}
)
assert response.status_code == HTTPStatus.OK
templates = response.json()
assert len(templates) == 1


def test_cannot_delete_other_users_template(client: TestClient, get_regular_user_token_headers: Dict[str, str]) -> None:
response = client.delete(
f"{API_BASE_URL}/v1/timelog/templates/2",
headers=get_regular_user_token_headers,
params={"user_id": 1},
)
assert response.status_code == HTTPStatus.FORBIDDEN
res = response.json()
assert res["detail"] == "You are not authorized to delete templates for this user"


def test_cannot_delete_other_global_template(
client: TestClient, get_regular_user_token_headers: Dict[str, str]
) -> None:
response = client.delete(
f"{API_BASE_URL}/v1/timelog/templates/3",
headers=get_regular_user_token_headers,
params={"user_id": 1},
)
assert response.status_code == HTTPStatus.FORBIDDEN
res = response.json()
assert res["detail"] == "You are not authorized to delete global templates"

0 comments on commit affd921

Please sign in to comment.