Skip to content

Commit d7fd3ec

Browse files
Merge pull request #3231 from VWS-Python/test-target-name-error-missing-body
Cover missing bodies in target-name errors
2 parents b68340f + 92e12b4 commit d7fd3ec

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎src/vws/exceptions/vws_exceptions.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class TargetNameExistError(VWSError):
143143
def target_name(self) -> str:
144144
"""The target name which already exists."""
145145
response_body = self.response.request_body
146-
if not isinstance(response_body, str | bytes): # pragma: no cover
146+
if not isinstance(response_body, str | bytes):
147147
msg = "A target-name error response must have a request body."
148148
raise TypeError(msg)
149149
request_json = json_object(value=response_body)

‎tests/test_vws_exceptions.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ def test_target_name_exist(
241241
assert exc.value.target_name == "x"
242242

243243

244+
def test_target_name_exist_requires_request_body() -> None:
245+
"""A target-name error without a request body is rejected."""
246+
response = Response(
247+
text="",
248+
url="https://vws.vuforia.com/targets",
249+
status_code=HTTPStatus.FORBIDDEN,
250+
headers={},
251+
request_body=None,
252+
tell_position=0,
253+
content=b"",
254+
)
255+
error = TargetNameExistError(response=response)
256+
257+
with pytest.raises(
258+
expected_exception=TypeError,
259+
match="must have a request body",
260+
):
261+
_ = error.target_name
262+
263+
244264
def test_project_inactive(
245265
high_quality_image: io.BytesIO,
246266
) -> None:

0 commit comments

Comments
 (0)