Skip to content

Commit

Permalink
Add minimal test for project allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
anarute committed Jan 10, 2024
1 parent 26718fb commit c90f551
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
88 changes: 88 additions & 0 deletions api/tests/routers/v1/test_projects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from decouple import config
from http import HTTPStatus
from fastapi.testclient import TestClient
from typing import Dict

API_BASE_URL = config("API_BASE_URL")


def test_create_project_allocation(client: TestClient, get_regular_user_token_headers: Dict[str, str]) -> None:
response = client.get(
f"{API_BASE_URL}/v1/projects/1/allocations?start=2024-01-01",
headers=get_regular_user_token_headers,
params={"user_id": 1},
)
assert response.status_code == HTTPStatus.OK
allocations = response.json()

allocation_payload = {
"userId": 1,
"projectId": 1,
"startDate": "2024-01-08",
"endDate": "2024-01-10",
"hoursPerDay": 8.0,
"fte": 1,
"isTentative": False,
"isBillable": True,
"notes": "test",
}
response = client.post(
f"{API_BASE_URL}/v1/projects/1/allocations",
headers=get_regular_user_token_headers,
params={"user_id": 1},
json=allocation_payload,
)
assert response.status_code == HTTPStatus.CREATED
expected_new_allocation = {
"id": 2,
"userId": 1,
"projectId": 1,
"username": "user",
"startDate": "2024-01-08",
"endDate": "2024-01-10",
"hoursPerDay": 8.0,
"totalHours": 24.0,
"fte": 1.0,
"isTentative": False,
"isBillable": True,
"notes": "test",
}
assert response.json() == expected_new_allocation

response = client.get(
f"{API_BASE_URL}/v1/projects/1/allocations?start=2024-01-01&end=2024-12-01",
headers=get_regular_user_token_headers,
params={"user_id": 1},
)
assert response.status_code == HTTPStatus.OK
allocations = response.json()
expected_response = [
{
"username": "user",
"hours": {
"2024-1": {
"days": [
"2024-01-01",
"2024-01-02",
"2024-01-03",
"2024-01-04",
"2024-01-05",
],
"ISOWeek": 1,
"month": "Jan",
"totalHours": 40.0,
"project": 1,
"isLeave": False,
},
"2024-2": {
"days": ["2024-01-08", "2024-01-09", "2024-01-10"],
"ISOWeek": 2,
"month": "Jan",
"totalHours": 24.0,
"project": 1,
"isLeave": False,
},
},
}
]
assert allocations == expected_response
18 changes: 17 additions & 1 deletion api/tests/utils/mock_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from models.area import Area
from models.customer import Customer
from models.project import Project
from models.project import Project, ProjectAllocation
from models.timelog import Task, TaskType, Template
from models.user import User, UserGroup, UserRoles
from models.sector import Sector
Expand Down Expand Up @@ -111,6 +111,22 @@
},
],
),
(
ProjectAllocation,
[
{
"user_id": 1,
"project_id": 1,
"start_date": "2024-01-01",
"end_date": "2024-01-05",
"hours_per_day": 8.0,
"fte": 1.0,
"is_tentative": False,
"is_billable": True,
"notes": "test",
}
],
),
(
TaskType,
[
Expand Down

0 comments on commit c90f551

Please sign in to comment.