|
6 | 6 | add_departing_employee, |
7 | 7 | remove_departing_employee, |
8 | 8 | ) |
| 9 | + |
9 | 10 | from .conftest import TEST_ID |
10 | 11 |
|
| 12 | +from py42.exceptions import Py42BadRequestError |
| 13 | + |
11 | 14 |
|
12 | 15 | _EMPLOYEE = "departing employee" |
13 | 16 |
|
@@ -46,6 +49,27 @@ def test_add_departing_employee_when_user_does_not_exist_prints_error( |
46 | 49 | assert str(UserDoesNotExistError(_EMPLOYEE)) in caplog.text |
47 | 50 |
|
48 | 51 |
|
| 52 | +def test_add_departing_employee_when_user_already_added_prints_error( |
| 53 | + sdk_with_user, profile, bad_request_for_user_already_added, caplog |
| 54 | +): |
| 55 | + sdk_with_user.detectionlists.departing_employee.add.side_effect = ( |
| 56 | + bad_request_for_user_already_added |
| 57 | + ) |
| 58 | + add_departing_employee(sdk_with_user, profile, _EMPLOYEE) |
| 59 | + with caplog.at_level(logging.ERROR): |
| 60 | + assert _EMPLOYEE in caplog.text |
| 61 | + assert "already on the" in caplog.text |
| 62 | + assert "departing-employee" in caplog.text |
| 63 | + |
| 64 | + |
| 65 | +def test_add_departing_employee_when_bad_request_but_not_user_already_added_raises_Py42BadRequestError( |
| 66 | + sdk_with_user, profile, bad_request_for_other_reasons, caplog |
| 67 | +): |
| 68 | + sdk_with_user.detectionlists.departing_employee.add.side_effect = bad_request_for_other_reasons |
| 69 | + with pytest.raises(Py42BadRequestError): |
| 70 | + add_departing_employee(sdk_with_user, profile, _EMPLOYEE) |
| 71 | + |
| 72 | + |
49 | 73 | def test_remove_departing_employee_calls_remove(sdk_with_user, profile): |
50 | 74 | remove_departing_employee(sdk_with_user, profile, _EMPLOYEE) |
51 | 75 | sdk_with_user.detectionlists.departing_employee.remove.assert_called_once_with(TEST_ID) |
|
0 commit comments