From 9b02831e9ad3e5a09edc2b160be18df754d2c4c1 Mon Sep 17 00:00:00 2001 From: ahiuchingau <20424172+ahiuchingau@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:52:41 -0400 Subject: [PATCH] robot-server: fix one test --- .../robot_server/errors/global_errors.py | 2 +- .../robot/calibration/check/models.py | 4 +-- .../robot_server/service/json_api/response.py | 2 +- .../service/legacy/models/control.py | 4 +-- .../tests/errors/test_exception_handlers.py | 28 +++++++++---------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/robot-server/robot_server/errors/global_errors.py b/robot-server/robot_server/errors/global_errors.py index 73e460854ba..5f7d73eb234 100644 --- a/robot-server/robot_server/errors/global_errors.py +++ b/robot-server/robot_server/errors/global_errors.py @@ -53,7 +53,7 @@ def from_exc( ) -> "FirmwareUpdateRequired": """Build a FirmwareUpdateRequired from a specific exception. Preserves metadata.""" parent_inst = ErrorDetails.from_exc(exc, **supplemental_kwargs) - inst = FirmwareUpdateRequired(**parent_inst.dict()) + inst = FirmwareUpdateRequired(**parent_inst.model_dump()) if not inst.meta: inst.meta = {"update_url": "/subsystems/update"} else: diff --git a/robot-server/robot_server/robot/calibration/check/models.py b/robot-server/robot_server/robot/calibration/check/models.py index d301b413606..4b7fbf783a8 100644 --- a/robot-server/robot_server/robot/calibration/check/models.py +++ b/robot-server/robot_server/robot/calibration/check/models.py @@ -14,8 +14,8 @@ Field, ..., description="An offset vector in deck coordinates (x, y, z)", - min_items=3, - max_items=3, + min_length=3, + max_length=3, ) diff --git a/robot-server/robot_server/service/json_api/response.py b/robot-server/robot_server/service/json_api/response.py index 51bd097fe08..6d3bdb4f5a1 100644 --- a/robot-server/robot_server/service/json_api/response.py +++ b/robot-server/robot_server/service/json_api/response.py @@ -48,7 +48,7 @@ def dict(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: returned in a response, which would violate the spec. """ kwargs["exclude_none"] = True - return super().dict(*args, **kwargs) + return super().model_dump(*args, **kwargs) def json(self, *args: Any, **kwargs: Any) -> str: """See notes in `.dict()`.""" diff --git a/robot-server/robot_server/service/legacy/models/control.py b/robot-server/robot_server/service/legacy/models/control.py index ba94c121fa6..c375ed9d949 100644 --- a/robot-server/robot_server/service/legacy/models/control.py +++ b/robot-server/robot_server/service/legacy/models/control.py @@ -28,8 +28,8 @@ class HomeTarget(str, Enum): Field, ..., description="A point in deck coordinates (x, y, z)", - min_items=3, - max_items=3, + min_length=3, + max_length=3, ) diff --git a/robot-server/tests/errors/test_exception_handlers.py b/robot-server/tests/errors/test_exception_handlers.py index eff6b5e041c..1fcab1e729e 100644 --- a/robot-server/tests/errors/test_exception_handlers.py +++ b/robot-server/tests/errors/test_exception_handlers.py @@ -22,13 +22,7 @@ class Item(BaseModel): @pytest.fixture def app() -> FastAPI: """Get a FastAPI app with our exception handlers.""" - app = FastAPI() - - # TODO(mc, 2021-05-10): upgrade to FastAPI > 0.61.2 to use `exception_handlers` arg - # see https://github.com/tiangolo/fastapi/pull/1924 - for exc_cls, handler in exception_handlers.items(): - app.add_exception_handler(exc_cls, handler) - + app = FastAPI(exception_handlers=exception_handlers) return app @@ -159,21 +153,23 @@ def create_item(item: Item) -> Item: "errorCode": "4000", "id": "InvalidRequest", "title": "Invalid Request", - "detail": "field required", + "detail": "Field required", "source": {"pointer": "/string_field"}, }, { "errorCode": "4000", "id": "InvalidRequest", "title": "Invalid Request", - "detail": "value is not a valid integer", + "detail": "Input should be a valid integer, unable to parse " + "string as an integer", "source": {"pointer": "/int_field"}, }, { "errorCode": "4000", "id": "InvalidRequest", "title": "Invalid Request", - "detail": "value could not be parsed to a boolean", + "detail": "Input should be a valid boolean, unable to interpret " + "input", "source": {"pointer": "/array_field/0"}, }, ] @@ -196,7 +192,8 @@ def get_item(count: int) -> Item: "errorCode": "4000", "id": "InvalidRequest", "title": "Invalid Request", - "detail": "value is not a valid integer", + "detail": "Input should be a valid integer, unable to parse " + "string as an integer", "source": {"parameter": "count"}, }, ] @@ -219,7 +216,7 @@ def get_item(header_name: str = Header(...)) -> Item: "errorCode": "4000", "id": "InvalidRequest", "title": "Invalid Request", - "detail": "field required", + "detail": "Field required", "source": {"header": "header-name"}, }, ] @@ -242,8 +239,9 @@ def create_item_legacy(item: Item) -> Item: assert response.json() == { "errorCode": "4000", "message": ( - "body.string_field: none is not an allowed value; " - "body.int_field: value is not a valid integer; " - "body.array_field.0: value could not be parsed to a boolean" + "body.string_field: Input should be a valid string; " + "body.int_field: Input should be a valid integer, unable to parse " + "string as an integer; body.array_field.0: Input should be a valid " + "boolean, unable to interpret input" ), }