diff --git a/src/mock_vws/_services_validators/exceptions.py b/src/mock_vws/_services_validators/exceptions.py index c978ad25d..6a582a9fc 100644 --- a/src/mock_vws/_services_validators/exceptions.py +++ b/src/mock_vws/_services_validators/exceptions.py @@ -7,7 +7,6 @@ import uuid from collections.abc import Mapping from http import HTTPStatus -from pathlib import Path from beartype import beartype @@ -265,48 +264,6 @@ def __init__(self) -> None: } -@beartype -class OopsErrorOccurredResponseError(ValidatorError): - """Exception raised when VWS returns an HTML page which says "Oops, an - error occurred". - - This has been seen to happen when the given name includes a bad - character. - """ - - def __init__(self) -> None: - """ - Attributes: - status_code: The status code to use in a response if this is - raised. - response_text: The response text to use in a response if this is - raised. - """ - super().__init__() - self.status_code = HTTPStatus.INTERNAL_SERVER_ERROR - resources_dir = Path(__file__).parent.parent / "resources" - filename = "oops_error_occurred_response.html" - oops_resp_file = resources_dir / filename - text = str(object=oops_resp_file.read_text()) - self.response_text = text - date = email.utils.formatdate( - timeval=None, - localtime=False, - usegmt=True, - ) - self.headers = { - "Connection": "keep-alive", - "Content-Type": "text/html; charset=UTF-8", - "server": "envoy", - "Date": date, - "x-envoy-upstream-service-time": "5", - "Content-Length": str(object=len(self.response_text)), - "strict-transport-security": "max-age=31536000", - "x-aws-region": "us-east-2, us-west-2", - "x-content-type-options": "nosniff", - } - - @beartype class BadImageError(ValidatorError): """ diff --git a/src/mock_vws/_services_validators/name_validators.py b/src/mock_vws/_services_validators/name_validators.py index 2b1c93eb9..604c8a1a0 100644 --- a/src/mock_vws/_services_validators/name_validators.py +++ b/src/mock_vws/_services_validators/name_validators.py @@ -12,7 +12,6 @@ from mock_vws._database_matchers import get_database_matching_server_keys from mock_vws._services_validators.exceptions import ( FailError, - OopsErrorOccurredResponseError, TargetNameExistError, ) from mock_vws.database import VuforiaDatabase @@ -35,8 +34,8 @@ def validate_name_characters_in_range( request_path: The path to the endpoint. Raises: - OopsErrorOccurredResponseError: Characters are out of range and the - request is trying to make a new target. + FailError: Characters are out of range and the request is trying to + make a new target. TargetNameExistError: Characters are out of range and the request is for another endpoint. """ @@ -55,7 +54,7 @@ def validate_name_characters_in_range( if (request_method, request_path) == (HTTPMethod.POST, "/targets"): _LOGGER.warning(msg="Characters are out of range.") - raise OopsErrorOccurredResponseError + raise FailError(status_code=HTTPStatus.INTERNAL_SERVER_ERROR) _LOGGER.warning(msg="Characters are out of range.") raise TargetNameExistError diff --git a/src/mock_vws/resources/oops_error_occurred_response.html b/src/mock_vws/resources/oops_error_occurred_response.html deleted file mode 100644 index d844502ae..000000000 --- a/src/mock_vws/resources/oops_error_occurred_response.html +++ /dev/null @@ -1,42 +0,0 @@ - - -
-- This exception has been logged with id 7mdbgjp16. -
- - - diff --git a/tests/mock_vws/test_add_target.py b/tests/mock_vws/test_add_target.py index 778392a08..cd3ce28d8 100644 --- a/tests/mock_vws/test_add_target.py +++ b/tests/mock_vws/test_add_target.py @@ -11,10 +11,9 @@ import pytest from beartype import beartype -from dirty_equals import IsInstance from vws import VWS from vws.exceptions.custom_exceptions import ( - OopsAnErrorOccurredPossiblyBadNameError, + ServerError, ) from vws.exceptions.vws_exceptions import ( AuthenticationFailureError, @@ -30,7 +29,6 @@ from mock_vws._constants import ResultCodes from tests.mock_vws.utils import make_image_file from tests.mock_vws.utils.assertions import ( - assert_valid_date_header, assert_vws_failure, assert_vws_response, ) @@ -65,32 +63,6 @@ def _add_target_to_vws( ) -@beartype -def _assert_oops_response(response: Response) -> None: - """Assert that the response is in the format of Vuforia's "Oops, an error - occurred" HTML response. - - Raises: - AssertionError: The given response is not expected format. - """ - assert_valid_date_header(response=response) - assert "Oops, an error occurred" in response.text - assert "This exception has been logged with id" in response.text - - expected_headers = { - "Connection": "keep-alive", - "Content-Type": "text/html; charset=UTF-8", - "Date": response.headers["Date"], - "server": "envoy", - "Content-Length": "1190", - "x-envoy-upstream-service-time": IsInstance(expected_type=str), - "strict-transport-security": "max-age=31536000", - "x-aws-region": IsInstance(expected_type=str), - "x-content-type-options": "nosniff", - } - assert response.headers == expected_headers - - def assert_success(response: Response) -> None: """Assert that the given response is a success response for adding a target. @@ -378,17 +350,14 @@ def test_name_invalid( "active_flag": True, } + exc: pytest.ExceptionInfo[FailError | ServerError] + if status_code == HTTPStatus.INTERNAL_SERVER_ERROR: - with pytest.raises( - expected_exception=OopsAnErrorOccurredPossiblyBadNameError, - ) as oops_exc: + with pytest.raises(expected_exception=ServerError) as exc: + _add_target_to_vws(vws_client=vws_client, data=data) + else: + with pytest.raises(expected_exception=FailError) as exc: _add_target_to_vws(vws_client=vws_client, data=data) - assert oops_exc.value.response.status_code == status_code - _assert_oops_response(response=oops_exc.value.response) - return - - with pytest.raises(expected_exception=FailError) as exc: - _add_target_to_vws(vws_client=vws_client, data=data) assert_vws_failure( response=exc.value.response,