diff --git a/src/vws/exceptions/vws_exceptions.py b/src/vws/exceptions/vws_exceptions.py index 86e28ba79..bd42ae7b8 100644 --- a/src/vws/exceptions/vws_exceptions.py +++ b/src/vws/exceptions/vws_exceptions.py @@ -143,7 +143,7 @@ class TargetNameExistError(VWSError): def target_name(self) -> str: """The target name which already exists.""" response_body = self.response.request_body - if not isinstance(response_body, str | bytes): # pragma: no cover + if not isinstance(response_body, str | bytes): msg = "A target-name error response must have a request body." raise TypeError(msg) request_json = json_object(value=response_body) diff --git a/tests/test_vws_exceptions.py b/tests/test_vws_exceptions.py index 594ba858c..6479a2703 100644 --- a/tests/test_vws_exceptions.py +++ b/tests/test_vws_exceptions.py @@ -241,6 +241,26 @@ def test_target_name_exist( assert exc.value.target_name == "x" +def test_target_name_exist_requires_request_body() -> None: + """A target-name error without a request body is rejected.""" + response = Response( + text="", + url="https://vws.vuforia.com/targets", + status_code=HTTPStatus.FORBIDDEN, + headers={}, + request_body=None, + tell_position=0, + content=b"", + ) + error = TargetNameExistError(response=response) + + with pytest.raises( + expected_exception=TypeError, + match="must have a request body", + ): + _ = error.target_name + + def test_project_inactive( high_quality_image: io.BytesIO, ) -> None: