Skip to content

Remove Oops error which no longer occurs #2552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions src/mock_vws/_services_validators/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uuid
from collections.abc import Mapping
from http import HTTPStatus
from pathlib import Path

from beartype import beartype

Expand Down Expand Up @@ -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):
"""
Expand Down
7 changes: 3 additions & 4 deletions src/mock_vws/_services_validators/name_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,8 +34,8 @@
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.
"""
Expand All @@ -55,7 +54,7 @@

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)

Check warning on line 57 in src/mock_vws/_services_validators/name_validators.py

View check run for this annotation

Codecov / codecov/patch

src/mock_vws/_services_validators/name_validators.py#L57

Added line #L57 was not covered by tests

_LOGGER.warning(msg="Characters are out of range.")
raise TargetNameExistError
Expand Down
42 changes: 0 additions & 42 deletions src/mock_vws/resources/oops_error_occurred_response.html

This file was deleted.

45 changes: 7 additions & 38 deletions tests/mock_vws/test_add_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -65,32 +63,6 @@
)


@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.
Expand Down Expand Up @@ -378,17 +350,14 @@
"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)

Check warning on line 357 in tests/mock_vws/test_add_target.py

View check run for this annotation

Codecov / codecov/patch

tests/mock_vws/test_add_target.py#L356-L357

Added lines #L356 - L357 were not covered by tests
else:
with pytest.raises(expected_exception=FailError) as exc:

Check warning on line 359 in tests/mock_vws/test_add_target.py

View check run for this annotation

Codecov / codecov/patch

tests/mock_vws/test_add_target.py#L359

Added line #L359 was not covered by tests
_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,
Expand Down
Loading