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