1- from unittest .mock import Mock , patch
2-
1+ import copy
2+ from unittest .mock import Mock , patch , ANY
3+ from faker import Faker
34from commons .data_access_layer .database import EventContext
45from time_tracker_api .activities .activities_model import (
56 ActivityCosmosDBRepository ,
67 ActivityCosmosDBModel ,
8+ create_dao ,
79)
810
11+ faker = Faker ()
12+
913
1014@patch (
1115 'time_tracker_api.activities.activities_model.ActivityCosmosDBRepository.find_partition_key_value'
@@ -16,10 +20,10 @@ def test_find_all_with_id_in_list(
1620 activity_repository : ActivityCosmosDBRepository ,
1721):
1822 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 () ,
2327 }
2428
2529 query_items_mock = Mock (return_value = [expected_item ])
@@ -37,3 +41,25 @@ def test_find_all_with_id_in_list(
3741 activity = result [0 ]
3842 assert isinstance (activity , ActivityCosmosDBModel )
3943 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