|
3 | 3 | from flask.testing import FlaskClient
|
4 | 4 | from flask_restplus._http import HTTPStatus
|
5 | 5 | from utils.azure_users import AzureConnection
|
| 6 | +from pytest import mark |
6 | 7 |
|
7 | 8 |
|
8 | 9 | def test_users_response_contains_expected_props(
|
@@ -76,3 +77,32 @@ def test_on_delete_update_user_role_is_being_called_with_valid_arguments(
|
76 | 77 |
|
77 | 78 | assert HTTPStatus.OK == response.status_code
|
78 | 79 | update_user_role_mock.assert_called_once_with(user_id, role=None)
|
| 80 | + |
| 81 | + |
| 82 | +@patch('utils.azure_users.AzureConnection.update_role', new_callable=Mock) |
| 83 | +@mark.parametrize( |
| 84 | + 'role_id,action,is_grant', |
| 85 | + [ |
| 86 | + ('admin', 'grant', True), |
| 87 | + ('admin', 'revoke', False), |
| 88 | + ('test', 'grant', True), |
| 89 | + ('test', 'revoke', False), |
| 90 | + ], |
| 91 | +) |
| 92 | +def test_update_role_is_called_properly_on_each_action( |
| 93 | + update_role_mock, |
| 94 | + client: FlaskClient, |
| 95 | + valid_header: dict, |
| 96 | + user_id: str, |
| 97 | + role_id, |
| 98 | + action, |
| 99 | + is_grant, |
| 100 | +): |
| 101 | + response = client.post( |
| 102 | + f'/users/{user_id}/roles/{role_id}/{action}', headers=valid_header, |
| 103 | + ) |
| 104 | + |
| 105 | + assert HTTPStatus.OK == response.status_code |
| 106 | + update_role_mock.assert_called_once_with( |
| 107 | + user_id, role_id, is_grant=is_grant |
| 108 | + ) |
0 commit comments