Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add new fixture user_id testing update user role is being calle…
…d with expected arguments #229
  • Loading branch information
magallegos1996 authored and Angeluz-07 committed Nov 19, 2020
commit 68f4961333786769377bc7716a2ee54da89e1e85
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def owner_id() -> str:
return fake.uuid4()


@pytest.fixture(scope="session")
def user_id() -> str:
return fake.uuid4()


@pytest.fixture(scope="function")
def sample_item(
cosmos_db_repository: CosmosDBRepository,
Expand Down
21 changes: 12 additions & 9 deletions tests/time_tracker_api/users/users_namespace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

fake = Faker()

valid_user_role_data = {'role': 'admin'}
user_id = fake.random_int(1, 9999)


def test_users_response_contains_expected_props(
client: FlaskClient,
Expand All @@ -34,32 +31,38 @@ def test_users_response_contains_expected_props(
def test_update_user_role_response_contains_expected_props(
client: FlaskClient,
valid_header: dict,
user_id: dict,
):
valid_user_role_data = {'role': 'admin'}
AzureConnection.update_user_role = Mock(
return_value=[{'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}]
return_value={'name': 'dummy', 'email': 'dummy', 'role': 'dummy'}
)

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

assert HTTPStatus.OK == response.status_code
assert 'name' in json.loads(response.data)[0]
assert 'email' in json.loads(response.data)[0]
assert 'role' in json.loads(response.data)[0]
assert 'name' in json.loads(response.data)
assert 'email' in json.loads(response.data)
assert 'role' in json.loads(response.data)


@patch('utils.azure_users.AzureConnection', new_callable=Mock)
@patch('utils.azure_users.AzureConnection.update_user_role', new_callable=Mock)
def test_update_user_role_is_being_called_with_valid_arguments(
update_user_role_mock,
client: FlaskClient,
valid_header: dict,
user_id: dict,
):

valid_user_role_data = {'role': 'admin'}
response = client.put(
f'/users/{user_id}', headers=valid_header, json=valid_user_role_data
)

assert HTTPStatus.OK == response.status_code
assert valid_user_role_data['role'] == 'admin'
update_user_role_mock.assert_called_once()
update_user_role_mock.assert_called_once_with(
user_id, valid_user_role_data['role']
)