Skip to content

Commit 8c89c81

Browse files
committed
fix: TT-261 refactor code based on PR reviews
1 parent 8a3c845 commit 8c89c81

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed
Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
from utils.extend_model import (
2-
add_project_info_to_time_entries,
3-
add_activity_name_to_time_entries,
4-
)
1+
from utils.azure_users import AzureConnection, AzureUser
52
from time_tracker_api.time_entries.time_entries_repository import (
63
TimeEntryCosmosDBModel,
4+
TimeEntryCosmosDBRepository,
75
)
8-
from time_tracker_api.time_entries.time_entries_dao import (
9-
TimeEntriesCosmosDBDao,
10-
)
6+
117
from time_tracker_api.projects.projects_model import (
128
ProjectCosmosDBDao,
139
ProjectCosmosDBModel,
@@ -18,9 +14,7 @@
1814
)
1915

2016

21-
def test_add_complementary_info(
22-
mocker,
23-
):
17+
def create_time_entry_data():
2418
time_entry_data = {
2519
'id': 'id',
2620
'start_date': '2021-03-22T10:00:00.000Z',
@@ -30,7 +24,12 @@ def test_add_complementary_info(
3024
'project_id': 'project_id1',
3125
'activity_id': 'activity_id1',
3226
'technologies': ['python', 'pytest'],
27+
'owner_id': 'id',
3328
}
29+
return time_entry_data
30+
31+
32+
def create_project_data():
3433
project_data = {
3534
'customer_id': 'dsakldh12ASD',
3635
'id': 'project_id1',
@@ -39,51 +38,59 @@ def test_add_complementary_info(
3938
'project_type_id': "id2",
4039
'tenant_id': 'tenantid1',
4140
}
41+
return project_data
42+
43+
44+
def create_activity_data():
4245
activity_data = {
4346
'id': 'activity_id1',
4447
'name': 'activity',
4548
'description': 'testing',
4649
"tenant_id": 'nomatter',
4750
}
51+
return activity_data
52+
53+
54+
def test_add_complementary_info(
55+
mocker,
56+
time_entry_repository: TimeEntryCosmosDBRepository,
57+
):
4858
projects_db_get_all_mock = mocker.patch.object(
4959
ProjectCosmosDBDao, 'get_all'
5060
)
5161
activities_db_get_all_mock = mocker.patch.object(
5262
ActivityCosmosDBDao, 'get_all'
5363
)
54-
time_entry_db_get_all_mock = mocker.patch.object(
55-
TimeEntriesCosmosDBDao, 'get_all'
56-
)
64+
users_mock = mocker.patch.object(AzureConnection, 'users')
5765

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')
66+
expected_project = ProjectCosmosDBModel(create_project_data())
67+
expected_activity = ActivityCosmosDBModel(create_activity_data())
68+
expected_time_entry_in = TimeEntryCosmosDBModel(create_time_entry_data())
69+
expected_users = AzureUser('email1', [], 'id', 'name', ['admin'])
70+
setattr(expected_project, 'customer_name', 'customer_name')
6271

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
72+
projects_db_get_all_mock.return_value = [expected_project]
73+
activities_db_get_all_mock.return_value = [expected_activity]
74+
users_mock.return_value = [expected_users]
6675

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]
76+
expected_time_entry_out = time_entry_repository.add_complementary_info(
77+
[expected_time_entry_in], max_count=None, exist_conditions=True
7278
)
7379

80+
assert isinstance(expected_time_entry_out[0], TimeEntryCosmosDBModel)
7481
assert (
75-
expected_time_entry.__dict__['project_name']
76-
== expected_projects.__dict__['name']
82+
expected_time_entry_out[0].__dict__['project_name']
83+
== expected_project.__dict__['name']
7784
)
7885
assert (
79-
expected_time_entry.__dict__['customer_id']
80-
== expected_projects.__dict__['customer_id']
86+
expected_time_entry_out[0].__dict__['customer_id']
87+
== expected_project.__dict__['customer_id']
8188
)
8289
assert (
83-
expected_time_entry.__dict__['customer_name']
84-
== expected_projects.__dict__['customer_name']
90+
expected_time_entry_out[0].__dict__['customer_name']
91+
== expected_project.__dict__['customer_name']
8592
)
8693
assert (
87-
expected_time_entry.__dict__['activity_name']
88-
== expected_activities.__dict__['name']
94+
expected_time_entry_out[0].__dict__['activity_name']
95+
== expected_activity.__dict__['name']
8996
)

0 commit comments

Comments
 (0)