1
- from unittest .mock import Mock , patch
2
-
1
+ import copy
2
+ from unittest .mock import Mock , patch , ANY
3
+ from faker import Faker
3
4
from commons .data_access_layer .database import EventContext
4
5
from time_tracker_api .activities .activities_model import (
5
6
ActivityCosmosDBRepository ,
6
7
ActivityCosmosDBModel ,
8
+ create_dao ,
7
9
)
8
10
11
+ faker = Faker ()
12
+
9
13
10
14
@patch (
11
15
'time_tracker_api.activities.activities_model.ActivityCosmosDBRepository.find_partition_key_value'
@@ -16,10 +20,10 @@ def test_find_all_with_id_in_list(
16
20
activity_repository : ActivityCosmosDBRepository ,
17
21
):
18
22
expected_item = {
19
- 'id' : 'id1' ,
20
- 'name' : 'testing' ,
21
- 'description' : 'do some testing' ,
22
- 'tenant_id' : 'tenantid1' ,
23
+ 'id' : faker . uuid4 () ,
24
+ 'name' : faker . name () ,
25
+ 'description' : faker . sentence ( nb_words = 4 ) ,
26
+ 'tenant_id' : faker . uuid4 () ,
23
27
}
24
28
25
29
query_items_mock = Mock (return_value = [expected_item ])
@@ -37,3 +41,25 @@ def test_find_all_with_id_in_list(
37
41
activity = result [0 ]
38
42
assert isinstance (activity , ActivityCosmosDBModel )
39
43
assert activity .__dict__ == expected_item
44
+
45
+
46
+ def test_create_activity_should_add_active_status (
47
+ mocker ,
48
+ ):
49
+ activity_payload = {
50
+ 'name' : faker .name (),
51
+ 'description' : faker .sentence (nb_words = 5 ),
52
+ 'tenant_id' : faker .uuid4 (),
53
+ }
54
+ activity_repository_create_mock = mocker .patch .object (
55
+ ActivityCosmosDBRepository , 'create'
56
+ )
57
+
58
+ activity_dao = create_dao ()
59
+ activity_dao .create (activity_payload )
60
+
61
+ expect_argument = copy .copy (activity_payload )
62
+ expect_argument ['status' ] = 'active'
63
+ activity_repository_create_mock .assert_called_with (
64
+ data = expect_argument , event_context = ANY
65
+ )
0 commit comments