Skip to content

Commit 9e7dfaf

Browse files
Merge pull request #2552 from VWS-Python/no-more-oops
Remove Oops error which no longer occurs
2 parents b419167 + de4fe54 commit 9e7dfaf

File tree

4 files changed

+10
-127
lines changed

4 files changed

+10
-127
lines changed

src/mock_vws/_services_validators/exceptions.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import uuid
88
from collections.abc import Mapping
99
from http import HTTPStatus
10-
from pathlib import Path
1110

1211
from beartype import beartype
1312

@@ -265,48 +264,6 @@ def __init__(self) -> None:
265264
}
266265

267266

268-
@beartype
269-
class OopsErrorOccurredResponseError(ValidatorError):
270-
"""Exception raised when VWS returns an HTML page which says "Oops, an
271-
error occurred".
272-
273-
This has been seen to happen when the given name includes a bad
274-
character.
275-
"""
276-
277-
def __init__(self) -> None:
278-
"""
279-
Attributes:
280-
status_code: The status code to use in a response if this is
281-
raised.
282-
response_text: The response text to use in a response if this is
283-
raised.
284-
"""
285-
super().__init__()
286-
self.status_code = HTTPStatus.INTERNAL_SERVER_ERROR
287-
resources_dir = Path(__file__).parent.parent / "resources"
288-
filename = "oops_error_occurred_response.html"
289-
oops_resp_file = resources_dir / filename
290-
text = str(object=oops_resp_file.read_text())
291-
self.response_text = text
292-
date = email.utils.formatdate(
293-
timeval=None,
294-
localtime=False,
295-
usegmt=True,
296-
)
297-
self.headers = {
298-
"Connection": "keep-alive",
299-
"Content-Type": "text/html; charset=UTF-8",
300-
"server": "envoy",
301-
"Date": date,
302-
"x-envoy-upstream-service-time": "5",
303-
"Content-Length": str(object=len(self.response_text)),
304-
"strict-transport-security": "max-age=31536000",
305-
"x-aws-region": "us-east-2, us-west-2",
306-
"x-content-type-options": "nosniff",
307-
}
308-
309-
310267
@beartype
311268
class BadImageError(ValidatorError):
312269
"""

src/mock_vws/_services_validators/name_validators.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from mock_vws._database_matchers import get_database_matching_server_keys
1313
from mock_vws._services_validators.exceptions import (
1414
FailError,
15-
OopsErrorOccurredResponseError,
1615
TargetNameExistError,
1716
)
1817
from mock_vws.database import VuforiaDatabase
@@ -35,8 +34,8 @@ def validate_name_characters_in_range(
3534
request_path: The path to the endpoint.
3635
3736
Raises:
38-
OopsErrorOccurredResponseError: Characters are out of range and the
39-
request is trying to make a new target.
37+
FailError: Characters are out of range and the request is trying to
38+
make a new target.
4039
TargetNameExistError: Characters are out of range and the request is
4140
for another endpoint.
4241
"""
@@ -55,7 +54,7 @@ def validate_name_characters_in_range(
5554

5655
if (request_method, request_path) == (HTTPMethod.POST, "/targets"):
5756
_LOGGER.warning(msg="Characters are out of range.")
58-
raise OopsErrorOccurredResponseError
57+
raise FailError(status_code=HTTPStatus.INTERNAL_SERVER_ERROR)
5958

6059
_LOGGER.warning(msg="Characters are out of range.")
6160
raise TargetNameExistError

src/mock_vws/resources/oops_error_occurred_response.html

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/mock_vws/test_add_target.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
import pytest
1313
from beartype import beartype
14-
from dirty_equals import IsInstance
1514
from vws import VWS
1615
from vws.exceptions.custom_exceptions import (
17-
OopsAnErrorOccurredPossiblyBadNameError,
16+
ServerError,
1817
)
1918
from vws.exceptions.vws_exceptions import (
2019
AuthenticationFailureError,
@@ -30,7 +29,6 @@
3029
from mock_vws._constants import ResultCodes
3130
from tests.mock_vws.utils import make_image_file
3231
from tests.mock_vws.utils.assertions import (
33-
assert_valid_date_header,
3432
assert_vws_failure,
3533
assert_vws_response,
3634
)
@@ -65,32 +63,6 @@ def _add_target_to_vws(
6563
)
6664

6765

68-
@beartype
69-
def _assert_oops_response(response: Response) -> None:
70-
"""Assert that the response is in the format of Vuforia's "Oops, an error
71-
occurred" HTML response.
72-
73-
Raises:
74-
AssertionError: The given response is not expected format.
75-
"""
76-
assert_valid_date_header(response=response)
77-
assert "Oops, an error occurred" in response.text
78-
assert "This exception has been logged with id" in response.text
79-
80-
expected_headers = {
81-
"Connection": "keep-alive",
82-
"Content-Type": "text/html; charset=UTF-8",
83-
"Date": response.headers["Date"],
84-
"server": "envoy",
85-
"Content-Length": "1190",
86-
"x-envoy-upstream-service-time": IsInstance(expected_type=str),
87-
"strict-transport-security": "max-age=31536000",
88-
"x-aws-region": IsInstance(expected_type=str),
89-
"x-content-type-options": "nosniff",
90-
}
91-
assert response.headers == expected_headers
92-
93-
9466
def assert_success(response: Response) -> None:
9567
"""Assert that the given response is a success response for adding a
9668
target.
@@ -378,17 +350,14 @@ def test_name_invalid(
378350
"active_flag": True,
379351
}
380352

353+
exc: pytest.ExceptionInfo[FailError | ServerError]
354+
381355
if status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
382-
with pytest.raises(
383-
expected_exception=OopsAnErrorOccurredPossiblyBadNameError,
384-
) as oops_exc:
356+
with pytest.raises(expected_exception=ServerError) as exc:
357+
_add_target_to_vws(vws_client=vws_client, data=data)
358+
else:
359+
with pytest.raises(expected_exception=FailError) as exc:
385360
_add_target_to_vws(vws_client=vws_client, data=data)
386-
assert oops_exc.value.response.status_code == status_code
387-
_assert_oops_response(response=oops_exc.value.response)
388-
return
389-
390-
with pytest.raises(expected_exception=FailError) as exc:
391-
_add_target_to_vws(vws_client=vws_client, data=data)
392361

393362
assert_vws_failure(
394363
response=exc.value.response,

0 commit comments

Comments
 (0)