4
4
from flask_restplus ._http import HTTPStatus
5
5
from pytest_mock import MockFixture
6
6
7
- from time_tracker_api .projects . projects_model import PROJECT_TYPE
7
+ from time_tracker_api .security import current_user_tenant_id
8
8
9
9
fake = Faker ()
10
10
11
11
valid_project_data = {
12
12
"name" : fake .company (),
13
13
"description" : fake .paragraph (),
14
14
'customer_id' : fake .uuid4 (),
15
- 'tenant_id' : fake .uuid4 (),
16
15
'project_type_id' : fake .uuid4 ()
17
16
}
18
17
@@ -30,7 +29,7 @@ def test_create_project_should_succeed_with_valid_request(client: FlaskClient, m
30
29
response = client .post ("/projects" , json = valid_project_data , follow_redirects = True )
31
30
32
31
assert HTTPStatus .CREATED == response .status_code
33
- repository_create_mock .assert_called_once_with ( valid_project_data )
32
+ repository_create_mock .assert_called_once ( )
34
33
35
34
36
35
def 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
73
72
74
73
assert HTTPStatus .OK == response .status_code
75
74
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 ())
77
77
78
78
79
79
def 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
89
89
response = client .get ("/projects/%s" % invalid_id , follow_redirects = True )
90
90
91
91
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 ())
93
94
94
95
95
96
def 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
106
107
response = client .get ("/projects/%s" % invalid_id , follow_redirects = True )
107
108
108
109
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 ())
110
112
111
113
112
114
def test_update_project_should_succeed_with_valid_data (client : FlaskClient , mocker : MockFixture ):
113
115
from time_tracker_api .projects .projects_namespace import project_dao
114
116
115
117
repository_update_mock = mocker .patch .object (project_dao .repository ,
116
- 'update ' ,
118
+ 'partial_update ' ,
117
119
return_value = fake_project )
118
120
119
121
valid_id = fake .random_int (1 , 9999 )
120
122
response = client .put ("/projects/%s" % valid_id , json = valid_project_data , follow_redirects = True )
121
123
122
124
assert HTTPStatus .OK == response .status_code
123
125
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 ())
125
129
126
130
127
131
def 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
148
152
invalid_id = fake .random_int (1 , 9999 )
149
153
150
154
repository_update_mock = mocker .patch .object (project_dao .repository ,
151
- 'update ' ,
155
+ 'partial_update ' ,
152
156
side_effect = NotFound )
153
157
154
158
response = client .put ("/projects/%s" % invalid_id ,
155
159
json = valid_project_data ,
156
160
follow_redirects = True )
157
161
158
162
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 ())
160
166
161
167
162
168
def 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
165
171
valid_id = fake .random_int (1 , 9999 )
166
172
167
173
repository_remove_mock = mocker .patch .object (project_dao .repository ,
168
- 'remove ' ,
174
+ 'delete ' ,
169
175
return_value = None )
170
176
171
177
response = client .delete ("/projects/%s" % valid_id , follow_redirects = True )
172
178
173
179
assert HTTPStatus .NO_CONTENT == response .status_code
174
180
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 ())
176
183
177
184
178
185
def 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
182
189
invalid_id = fake .random_int (1 , 9999 )
183
190
184
191
repository_remove_mock = mocker .patch .object (project_dao .repository ,
185
- 'remove ' ,
192
+ 'delete ' ,
186
193
side_effect = NotFound )
187
194
188
195
response = client .delete ("/projects/%s" % invalid_id , follow_redirects = True )
189
196
190
197
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 ())
192
200
193
201
194
202
def 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
199
207
invalid_id = fake .company ()
200
208
201
209
repository_remove_mock = mocker .patch .object (project_dao .repository ,
202
- 'remove ' ,
210
+ 'delete ' ,
203
211
side_effect = UnprocessableEntity )
204
212
205
213
response = client .delete ("/projects/%s" % invalid_id , follow_redirects = True )
206
214
207
215
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