44from flask_restplus ._http import HTTPStatus
55from pytest_mock import MockFixture
66
7- from time_tracker_api .projects . projects_model import PROJECT_TYPE
7+ from time_tracker_api .security import current_user_tenant_id
88
99fake = Faker ()
1010
1111valid_project_data = {
1212 "name" : fake .company (),
1313 "description" : fake .paragraph (),
1414 'customer_id' : fake .uuid4 (),
15- 'tenant_id' : fake .uuid4 (),
1615 'project_type_id' : fake .uuid4 ()
1716}
1817
@@ -30,7 +29,7 @@ def test_create_project_should_succeed_with_valid_request(client: FlaskClient, m
3029 response = client .post ("/projects" , json = valid_project_data , follow_redirects = True )
3130
3231 assert HTTPStatus .CREATED == response .status_code
33- repository_create_mock .assert_called_once_with ( valid_project_data )
32+ repository_create_mock .assert_called_once ( )
3433
3534
3635def test_create_project_should_reject_bad_request (client : FlaskClient , mocker : MockFixture ):
@@ -73,7 +72,8 @@ def test_get_project_should_succeed_with_valid_id(client: FlaskClient, mocker: M
7372
7473 assert HTTPStatus .OK == response .status_code
7574 fake_project == json .loads (response .data )
76- repository_find_mock .assert_called_once_with (str (valid_id ))
75+ repository_find_mock .assert_called_once_with (str (valid_id ),
76+ partition_key_value = current_user_tenant_id ())
7777
7878
7979def test_get_project_should_return_not_found_with_invalid_id (client : FlaskClient , mocker : MockFixture ):
@@ -89,7 +89,8 @@ def test_get_project_should_return_not_found_with_invalid_id(client: FlaskClient
8989 response = client .get ("/projects/%s" % invalid_id , follow_redirects = True )
9090
9191 assert HTTPStatus .NOT_FOUND == response .status_code
92- repository_find_mock .assert_called_once_with (str (invalid_id ))
92+ repository_find_mock .assert_called_once_with (str (invalid_id ),
93+ partition_key_value = current_user_tenant_id ())
9394
9495
9596def test_get_project_should_response_with_unprocessable_entity_for_invalid_id_format (client : FlaskClient ,
@@ -106,22 +107,25 @@ def test_get_project_should_response_with_unprocessable_entity_for_invalid_id_fo
106107 response = client .get ("/projects/%s" % invalid_id , follow_redirects = True )
107108
108109 assert HTTPStatus .UNPROCESSABLE_ENTITY == response .status_code
109- repository_find_mock .assert_called_once_with (str (invalid_id ))
110+ repository_find_mock .assert_called_once_with (str (invalid_id ),
111+ partition_key_value = current_user_tenant_id ())
110112
111113
112114def test_update_project_should_succeed_with_valid_data (client : FlaskClient , mocker : MockFixture ):
113115 from time_tracker_api .projects .projects_namespace import project_dao
114116
115117 repository_update_mock = mocker .patch .object (project_dao .repository ,
116- 'update ' ,
118+ 'partial_update ' ,
117119 return_value = fake_project )
118120
119121 valid_id = fake .random_int (1 , 9999 )
120122 response = client .put ("/projects/%s" % valid_id , json = valid_project_data , follow_redirects = True )
121123
122124 assert HTTPStatus .OK == response .status_code
123125 fake_project == json .loads (response .data )
124- repository_update_mock .assert_called_once_with (str (valid_id ), valid_project_data )
126+ repository_update_mock .assert_called_once_with (str (valid_id ),
127+ changes = valid_project_data ,
128+ partition_key_value = current_user_tenant_id ())
125129
126130
127131def test_update_project_should_reject_bad_request (client : FlaskClient , mocker : MockFixture ):
@@ -148,15 +152,17 @@ def test_update_project_should_return_not_found_with_invalid_id(client: FlaskCli
148152 invalid_id = fake .random_int (1 , 9999 )
149153
150154 repository_update_mock = mocker .patch .object (project_dao .repository ,
151- 'update ' ,
155+ 'partial_update ' ,
152156 side_effect = NotFound )
153157
154158 response = client .put ("/projects/%s" % invalid_id ,
155159 json = valid_project_data ,
156160 follow_redirects = True )
157161
158162 assert HTTPStatus .NOT_FOUND == response .status_code
159- repository_update_mock .assert_called_once_with (str (invalid_id ), valid_project_data )
163+ repository_update_mock .assert_called_once_with (str (invalid_id ),
164+ changes = valid_project_data ,
165+ partition_key_value = current_user_tenant_id ())
160166
161167
162168def test_delete_project_should_succeed_with_valid_id (client : FlaskClient , mocker : MockFixture ):
@@ -165,14 +171,15 @@ def test_delete_project_should_succeed_with_valid_id(client: FlaskClient, mocker
165171 valid_id = fake .random_int (1 , 9999 )
166172
167173 repository_remove_mock = mocker .patch .object (project_dao .repository ,
168- 'remove ' ,
174+ 'delete ' ,
169175 return_value = None )
170176
171177 response = client .delete ("/projects/%s" % valid_id , follow_redirects = True )
172178
173179 assert HTTPStatus .NO_CONTENT == response .status_code
174180 assert b'' == response .data
175- repository_remove_mock .assert_called_once_with (str (valid_id ))
181+ repository_remove_mock .assert_called_once_with (str (valid_id ),
182+ partition_key_value = current_user_tenant_id ())
176183
177184
178185def test_delete_project_should_return_not_found_with_invalid_id (client : FlaskClient , mocker : MockFixture ):
@@ -182,13 +189,14 @@ def test_delete_project_should_return_not_found_with_invalid_id(client: FlaskCli
182189 invalid_id = fake .random_int (1 , 9999 )
183190
184191 repository_remove_mock = mocker .patch .object (project_dao .repository ,
185- 'remove ' ,
192+ 'delete ' ,
186193 side_effect = NotFound )
187194
188195 response = client .delete ("/projects/%s" % invalid_id , follow_redirects = True )
189196
190197 assert HTTPStatus .NOT_FOUND == response .status_code
191- repository_remove_mock .assert_called_once_with (str (invalid_id ))
198+ repository_remove_mock .assert_called_once_with (str (invalid_id ),
199+ partition_key_value = current_user_tenant_id ())
192200
193201
194202def test_delete_project_should_return_unprocessable_entity_for_invalid_id_format (client : FlaskClient ,
@@ -199,10 +207,11 @@ def test_delete_project_should_return_unprocessable_entity_for_invalid_id_format
199207 invalid_id = fake .company ()
200208
201209 repository_remove_mock = mocker .patch .object (project_dao .repository ,
202- 'remove ' ,
210+ 'delete ' ,
203211 side_effect = UnprocessableEntity )
204212
205213 response = client .delete ("/projects/%s" % invalid_id , follow_redirects = True )
206214
207215 assert HTTPStatus .UNPROCESSABLE_ENTITY == response .status_code
208- repository_remove_mock .assert_called_once_with (str (invalid_id ))
216+ repository_remove_mock .assert_called_once_with (str (invalid_id ),
217+ partition_key_value = current_user_tenant_id ())
0 commit comments