Skip to content

Commit 68f4961

Browse files
magallegos1996Angeluz-07
authored andcommitted
feat: add new fixture user_id testing update user role is being called with expected arguments #229
1 parent bcd2564 commit 68f4961

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def owner_id() -> str:
140140
return fake.uuid4()
141141

142142

143+
@pytest.fixture(scope="session")
144+
def user_id() -> str:
145+
return fake.uuid4()
146+
147+
143148
@pytest.fixture(scope="function")
144149
def sample_item(
145150
cosmos_db_repository: CosmosDBRepository,

tests/time_tracker_api/users/users_namespace_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
fake = Faker()
99

10-
valid_user_role_data = {'role': 'admin'}
11-
user_id = fake.random_int(1, 9999)
12-
1310

1411
def test_users_response_contains_expected_props(
1512
client: FlaskClient,
@@ -34,32 +31,38 @@ def test_users_response_contains_expected_props(
3431
def test_update_user_role_response_contains_expected_props(
3532
client: FlaskClient,
3633
valid_header: dict,
34+
user_id: dict,
3735
):
36+
valid_user_role_data = {'role': 'admin'}
3837
AzureConnection.update_user_role = Mock(
39-
return_value=[{'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}]
38+
return_value={'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}
4039
)
4140

4241
response = client.put(
4342
f'/users/{user_id}', headers=valid_header, json=valid_user_role_data
4443
)
4544

4645
assert HTTPStatus.OK == response.status_code
47-
assert 'name' in json.loads(response.data)[0]
48-
assert 'email' in json.loads(response.data)[0]
49-
assert 'role' in json.loads(response.data)[0]
46+
assert 'name' in json.loads(response.data)
47+
assert 'email' in json.loads(response.data)
48+
assert 'role' in json.loads(response.data)
5049

5150

52-
@patch('utils.azure_users.AzureConnection', new_callable=Mock)
51+
@patch('utils.azure_users.AzureConnection.update_user_role', new_callable=Mock)
5352
def test_update_user_role_is_being_called_with_valid_arguments(
5453
update_user_role_mock,
5554
client: FlaskClient,
5655
valid_header: dict,
56+
user_id: dict,
5757
):
5858

59+
valid_user_role_data = {'role': 'admin'}
5960
response = client.put(
6061
f'/users/{user_id}', headers=valid_header, json=valid_user_role_data
6162
)
6263

6364
assert HTTPStatus.OK == response.status_code
6465
assert valid_user_role_data['role'] == 'admin'
65-
update_user_role_mock.assert_called_once()
66+
update_user_role_mock.assert_called_once_with(
67+
user_id, valid_user_role_data['role']
68+
)

0 commit comments

Comments
 (0)