def test_add_when_user_already_on_list_raises_user_already_added_error( self, mocker, mock_connection, user_context, mock_detection_list_user_client): def side_effect(url, json): if "add" in url: raise create_mock_error(Py42BadRequestError, mocker, "User already on list") mock_connection.post.side_effect = side_effect client = HighRiskEmployeeService(mock_connection, user_context, mock_detection_list_user_client) with pytest.raises(Py42UserAlreadyAddedError) as err: client.add("user_id") expected = "User with ID user_id is already on the high-risk-employee list." assert str(err.value) == expected
def test_add_posts_expected_data( self, user_context, mock_connection_post_success, mock_detection_list_user_client, ): high_risk_employee_client = HighRiskEmployeeService( mock_connection_post_success, user_context, mock_detection_list_user_client) high_risk_employee_client.add("942897397520289999") posted_data = mock_connection_post_success.post.call_args[1]["json"] assert mock_connection_post_success.post.call_count == 1 assert (mock_connection_post_success.post.call_args[0][0] == "v2/highriskemployee/add") assert (posted_data["tenantId"] == user_context.get_current_tenant_id() and posted_data["userId"] == "942897397520289999")