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
5
2
from time_tracker_api .time_entries .time_entries_repository import (
6
3
TimeEntryCosmosDBModel ,
4
+ TimeEntryCosmosDBRepository ,
7
5
)
8
- from time_tracker_api .time_entries .time_entries_dao import (
9
- TimeEntriesCosmosDBDao ,
10
- )
6
+
11
7
from time_tracker_api .projects .projects_model import (
12
8
ProjectCosmosDBDao ,
13
9
ProjectCosmosDBModel ,
18
14
)
19
15
20
16
21
- def test_add_complementary_info (
22
- mocker ,
23
- ):
17
+ def create_time_entry_data ():
24
18
time_entry_data = {
25
19
'id' : 'id' ,
26
20
'start_date' : '2021-03-22T10:00:00.000Z' ,
@@ -30,7 +24,12 @@ def test_add_complementary_info(
30
24
'project_id' : 'project_id1' ,
31
25
'activity_id' : 'activity_id1' ,
32
26
'technologies' : ['python' , 'pytest' ],
27
+ 'owner_id' : 'id' ,
33
28
}
29
+ return time_entry_data
30
+
31
+
32
+ def create_project_data ():
34
33
project_data = {
35
34
'customer_id' : 'dsakldh12ASD' ,
36
35
'id' : 'project_id1' ,
@@ -39,51 +38,59 @@ def test_add_complementary_info(
39
38
'project_type_id' : "id2" ,
40
39
'tenant_id' : 'tenantid1' ,
41
40
}
41
+ return project_data
42
+
43
+
44
+ def create_activity_data ():
42
45
activity_data = {
43
46
'id' : 'activity_id1' ,
44
47
'name' : 'activity' ,
45
48
'description' : 'testing' ,
46
49
"tenant_id" : 'nomatter' ,
47
50
}
51
+ return activity_data
52
+
53
+
54
+ def test_add_complementary_info (
55
+ mocker ,
56
+ time_entry_repository : TimeEntryCosmosDBRepository ,
57
+ ):
48
58
projects_db_get_all_mock = mocker .patch .object (
49
59
ProjectCosmosDBDao , 'get_all'
50
60
)
51
61
activities_db_get_all_mock = mocker .patch .object (
52
62
ActivityCosmosDBDao , 'get_all'
53
63
)
54
- time_entry_db_get_all_mock = mocker .patch .object (
55
- TimeEntriesCosmosDBDao , 'get_all'
56
- )
64
+ users_mock = mocker .patch .object (AzureConnection , 'users' )
57
65
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' )
62
71
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 ]
66
75
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
72
78
)
73
79
80
+ assert isinstance (expected_time_entry_out [0 ], TimeEntryCosmosDBModel )
74
81
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' ]
77
84
)
78
85
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' ]
81
88
)
82
89
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' ]
85
92
)
86
93
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' ]
89
96
)
0 commit comments