Skip to content

Commit 8a3c845

Browse files
committed
fix: TT-261 handle response Not found and added unit testing of methond add_complementary_info
1 parent 9f0f50d commit 8a3c845

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
from utils.extend_model import (
2+
add_project_info_to_time_entries,
3+
add_activity_name_to_time_entries,
4+
)
5+
from time_tracker_api.time_entries.time_entries_repository import (
6+
TimeEntryCosmosDBModel,
7+
)
8+
from time_tracker_api.time_entries.time_entries_dao import (
9+
TimeEntriesCosmosDBDao,
10+
)
11+
from time_tracker_api.projects.projects_model import (
12+
ProjectCosmosDBDao,
13+
ProjectCosmosDBModel,
14+
)
15+
from time_tracker_api.activities.activities_model import (
16+
ActivityCosmosDBDao,
17+
ActivityCosmosDBModel,
18+
)
19+
20+
21+
def test_add_complementary_info(
22+
mocker,
23+
):
24+
time_entry_data = {
25+
'id': 'id',
26+
'start_date': '2021-03-22T10:00:00.000Z',
27+
'end_date': "2021-03-22T11:00:00.000Z",
28+
'description': 'do some testing',
29+
'tenant_id': 'tenant_id',
30+
'project_id': 'project_id1',
31+
'activity_id': 'activity_id1',
32+
'technologies': ['python', 'pytest'],
33+
}
34+
project_data = {
35+
'customer_id': 'dsakldh12ASD',
36+
'id': 'project_id1',
37+
'name': 'project_name',
38+
'description': 'do some testing',
39+
'project_type_id': "id2",
40+
'tenant_id': 'tenantid1',
41+
}
42+
activity_data = {
43+
'id': 'activity_id1',
44+
'name': 'activity',
45+
'description': 'testing',
46+
"tenant_id": 'nomatter',
47+
}
48+
projects_db_get_all_mock = mocker.patch.object(
49+
ProjectCosmosDBDao, 'get_all'
50+
)
51+
activities_db_get_all_mock = mocker.patch.object(
52+
ActivityCosmosDBDao, 'get_all'
53+
)
54+
time_entry_db_get_all_mock = mocker.patch.object(
55+
TimeEntriesCosmosDBDao, 'get_all'
56+
)
57+
58+
expected_projects = ProjectCosmosDBModel(project_data)
59+
expected_activities = ActivityCosmosDBModel(activity_data)
60+
expected_time_entry = TimeEntryCosmosDBModel(time_entry_data)
61+
setattr(expected_projects, 'customer_name', 'customer_name')
62+
63+
projects_db_get_all_mock.return_value = expected_projects
64+
activities_db_get_all_mock.return_value = expected_activities
65+
time_entry_db_get_all_mock.return_value = expected_time_entry
66+
67+
add_project_info_to_time_entries(
68+
[expected_time_entry], [expected_projects]
69+
)
70+
add_activity_name_to_time_entries(
71+
[expected_time_entry], [expected_activities]
72+
)
73+
74+
assert (
75+
expected_time_entry.__dict__['project_name']
76+
== expected_projects.__dict__['name']
77+
)
78+
assert (
79+
expected_time_entry.__dict__['customer_id']
80+
== expected_projects.__dict__['customer_id']
81+
)
82+
assert (
83+
expected_time_entry.__dict__['customer_name']
84+
== expected_projects.__dict__['customer_name']
85+
)
86+
assert (
87+
expected_time_entry.__dict__['activity_name']
88+
== expected_activities.__dict__['name']
89+
)

time_tracker_api/time_entries/time_entries_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def add_complementary_info(
119119

120120
users = AzureConnection().users()
121121
add_user_email_to_time_entries(time_entries, users)
122-
elif not time_entries and exist_conditions:
122+
elif not time_entries and not exist_conditions:
123123
abort(HTTPStatus.NOT_FOUND, "Time entry not found")
124124
return time_entries
125125

0 commit comments

Comments
 (0)