|
| 1 | +from py42.exceptions import Py42NotFoundError |
| 2 | +from requests import HTTPError |
| 3 | +from requests import Request |
| 4 | +from requests import Response |
1 | 5 | from tests.cmds.conftest import TEST_EMPLOYEE |
2 | 6 | from tests.cmds.conftest import thread_safe_side_effect |
3 | 7 | from tests.conftest import TEST_ID |
|
7 | 11 | _NAMESPACE = "code42cli.cmds.high_risk_employee" |
8 | 12 |
|
9 | 13 |
|
| 14 | +def get_user_not_on_high_risk_employee_list_side_effect(mocker): |
| 15 | + def side_effect(*args, **kwargs): |
| 16 | + err = mocker.MagicMock(spec=HTTPError) |
| 17 | + resp = mocker.MagicMock(spec=Response) |
| 18 | + resp.text = "TEST_ERR" |
| 19 | + err.response = resp |
| 20 | + err.response.request = mocker.MagicMock(spec=Request) |
| 21 | + raise Py42NotFoundError(err) |
| 22 | + |
| 23 | + return side_effect |
| 24 | + |
| 25 | + |
10 | 26 | def test_add_high_risk_employee_adds(runner, cli_state_with_user): |
11 | 27 | runner.invoke( |
12 | 28 | cli, ["high-risk-employee", "add", TEST_EMPLOYEE], obj=cli_state_with_user |
@@ -219,3 +235,21 @@ def test_bulk_remove_risk_tags_uses_expected_arguments(runner, cli_state, mocker |
219 | 235 | {"username": "test@example.com", "tag": "tag1"}, |
220 | 236 | {"username": "test2@example.com", "tag": "tag2"}, |
221 | 237 | ] |
| 238 | + |
| 239 | + |
| 240 | +def test_remove_high_risk_employee_when_user_not_on_list_prints_expected_error( |
| 241 | + mocker, runner, cli_state |
| 242 | +): |
| 243 | + cli_state.sdk.detectionlists.high_risk_employee.remove.side_effect = get_user_not_on_high_risk_employee_list_side_effect( |
| 244 | + mocker |
| 245 | + ) |
| 246 | + test_username = "test@example.com" |
| 247 | + result = runner.invoke( |
| 248 | + cli, ["high-risk-employee", "remove", test_username], obj=cli_state |
| 249 | + ) |
| 250 | + assert ( |
| 251 | + "User {} is not currently on the high-risk-employee detection list.".format( |
| 252 | + test_username |
| 253 | + ) |
| 254 | + in result.output |
| 255 | + ) |
0 commit comments