def mock_get_by_id_fails(self, mocker, mock_connection): response = mocker.MagicMock(spec=Response) response.status_code = 400 exception = mocker.MagicMock(spec=HTTPError) exception.response = response mock_connection.post.side_effect = Py42BadRequestError(exception) return mock_connection
def side_effect(*args, **kwargs): err = mocker.MagicMock(spec=HTTPError) resp = mocker.MagicMock(spec=Response) resp.text = "CREATE_FAILED" err.response = resp py42_error = Py42BadRequestError(err) raise py42_error
def side_effect(*args, **kwargs): base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = ( '[{"name":"SYSTEM","description":"Organization was not found"}]' ) raise Py42BadRequestError(base_err)
def test_add_when_unknown_error_raises_error(self, mock_connection, mock_unknown_error): case_file_event_service = CasesFileEventsService(mock_connection) mock_connection.post.side_effect = Py42BadRequestError( mock_unknown_error) with pytest.raises(Py42BadRequestError) as e: case_file_event_service.add(_TEST_CASE_NUMBER, event_id=u"x") assert e.value.response.status_code == 400
def test_create_when_fails_with_unknown_error_raises_custom_exception( self, mock_connection, mock_unknown_error): cases_service = CasesService(mock_connection) mock_connection.post.side_effect = Py42BadRequestError( mock_unknown_error) with pytest.raises(Py42BadRequestError) as e: cases_service.create("Case") assert e.value.response.status_code == 400
def test_delete_on_a_closed_case_raises_error(self, mock_connection, mock_update_failed_response): case_file_event_service = CasesFileEventsService(mock_connection) mock_connection.delete.side_effect = Py42BadRequestError( mock_update_failed_response) with pytest.raises(Py42UpdateClosedCaseError) as e: case_file_event_service.delete(_TEST_CASE_NUMBER, event_id=u"x") assert e.value.args[0] == u"Cannot update a closed case."
def test_add_when_same_event_is_added_multiple_times_raises_error( self, mock_connection, mock_add_same_event_multiple_times): case_file_event_service = CasesFileEventsService(mock_connection) mock_connection.post.side_effect = Py42BadRequestError( mock_add_same_event_multiple_times) with pytest.raises(Py42CaseAlreadyHasEventError) as e: case_file_event_service.add(_TEST_CASE_NUMBER, event_id=u"x") assert e.value.args[0] == u"Event is already associated to the case."
def mock_user_client_raises_exception(self, mocker, mock_session, user_context, py42_response): user_client = UserClient(mock_session) response = mocker.MagicMock(spec=Response) response.status_code = 400 exception = mocker.MagicMock(spec=HTTPError) exception.response = response mock_session.post.side_effect = Py42BadRequestError(exception) return user_client
def test_create_when_fails_with_description_too_long_error_raises_custom_exception( self, mock_connection, mock_description_too_long_response): cases_service = CasesService(mock_connection) mock_connection.post.side_effect = Py42BadRequestError( mock_description_too_long_response) with pytest.raises(Py42DescriptionLimitExceededError) as e: cases_service.create("test", description=u"supposedly too long") assert (e.value.args[0] == u"Description limit exceeded, max 250 characters allowed.")
def test_file_events_add_when_py42_raises_exception_returns_error_message( runner, cli_state, error): cli_state.sdk.cases.file_events.add.side_effect = Py42BadRequestError( error) result = runner.invoke( cli, ["cases", "file-events", "add", "1", "--event-id", "1"], obj=cli_state, ) cli_state.sdk.cases.file_events.add.assert_called_once_with(1, "1") assert "Invalid case-number or event-id." in result.output
def test_update_failure_raised_appropriate_custom_exception( self, mock_connection, mock_get_response, mock_update_failed_response): cases_service = CasesService(mock_connection) mock_connection.get.return_value = mock_get_response mock_connection.put.side_effect = Py42BadRequestError( mock_update_failed_response) with pytest.raises(Py42UpdateClosedCaseError) as e: cases_service.update(_TEST_CASE_NUMBER, findings=u"x") assert e.value.args[0] == u"Cannot update a closed case."
def test_create_when_fails_with_name_exists_error_raises_custom_exception( self, mock_connection, mock_name_exists_response): cases_service = CasesService(mock_connection) mock_connection.post.side_effect = Py42BadRequestError( mock_name_exists_response) with pytest.raises(Py42CaseNameExistsError) as e: cases_service.create("Duplicate") assert ( e.value.args[0] == u"Case name 'Duplicate' already exists, please set another name")
def mock_user_client_error_on_adding_cloud_aliases( self, mocker, mock_connection, user_context, py42_response ): user_client = UserService(mock_connection) response = mocker.MagicMock(spec=Response) response.status_code = 400 response.text = CLOUD_ALIAS_LIMIT_EXCEEDED_ERROR_MESSAGE exception = mocker.MagicMock(spec=HTTPError) exception.response = response mock_connection.post.side_effect = Py42BadRequestError(exception) return user_client
def mock_detection_list_get_by_id_failure_when_invalid_id( mocker, mock_connection, py42_response): response = mocker.MagicMock(spec=Response) response.status_code = 400 exception = mocker.MagicMock(spec=Py42BadRequestError) exception.response = response detection_list_user_service = mocker.MagicMock( spec=DetectionListUserService) detection_list_user_service.create_if_not_exists.return_value = False detection_list_user_service.get_by_id.side_effect = Py42BadRequestError( exception, "") return detection_list_user_service
def side_effect(*args, **kwargs): base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = "USER_ALREADY_IN_HOLD" raise Py42BadRequestError(base_err)
def side_effect(*args, **kwargs): err = create_mock_http_error(mocker, data="TEST_ERR", status=400) raise Py42BadRequestError(err)
def side_effect(*args, **kwargs): base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = "At least one criteria must be specified; holdMembershipUid, holdUid, userUid, or userSearch" raise Py42BadRequestError(base_err)
def side_effect(*args, **kwargs): err = mocker.MagicMock(spec=HTTPError) resp = mocker.MagicMock(spec=Response) resp.text = "TEST_ERR" err.response = resp raise Py42BadRequestError(err)
def side_effect(url, json): if "add" in url: base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = "User already on list" raise Py42BadRequestError(base_err)
def deactivate_device_in_legal_hold_failure(cli_state, custom_error): cli_state.sdk.devices.deactivate.side_effect = Py42BadRequestError( custom_error)
def user_already_added_response(mocker): mock_response = mocker.MagicMock(spec=Response) mock_response.text = "USER_ALREADY_IN_HOLD" http_error = HTTPError() http_error.response = mock_response return Py42BadRequestError(http_error)
def check_matter_accessible_failure(cli_state, custom_error): cli_state.sdk.legalhold.get_matter_by_uid.side_effect = Py42BadRequestError( custom_error )
def side_effect(url, json): if "UserDeactivation" in url: base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = "ACTIVE_LEGAL_HOLD" raise Py42BadRequestError(base_err)
def mock_get_by_id_fails(self, mocker, mock_session): response = mocker.MagicMock(spec=Response) response.status_code = 400 mock_session.post.side_effect = Py42BadRequestError(response) return mock_session
def side_effect(*args, **kwargs): http_error = mocker.MagicMock(spec=HTTPError) response = mocker.MagicMock(spec=Response) response.text = "DIFFERENT_ERROR" http_error.response = response raise Py42BadRequestError(http_error)
def side_effect(*args, **kwargs): http_error = mocker.MagicMock(spec=HTTPError) response = mocker.MagicMock(spec=Response) response.text = "INVALID_PAGE_TOKEN" http_error.response = response raise Py42BadRequestError(http_error)
def deactivate_device_in_legal_hold_failure(cli_state): cli_state.sdk.devices.deactivate.side_effect = Py42BadRequestError( HTTPError())
def side_effect(*args, **kwargs): base_err = mocker.MagicMock(spec=HTTPError) base_err.response = mocker.MagicMock(spec=Response) base_err.response.text = "BAD REQUEST" raise Py42BadRequestError(base_err)