Skip to content

Commit

Permalink
robot-server: fix one test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Apr 12, 2024
1 parent 52b5899 commit 9b02831
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion robot-server/robot_server/errors/global_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions robot-server/robot_server/robot/calibration/check/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
2 changes: 1 addition & 1 deletion robot-server/robot_server/service/json_api/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()`."""
Expand Down
4 changes: 2 additions & 2 deletions robot-server/robot_server/service/legacy/models/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
28 changes: 13 additions & 15 deletions robot-server/tests/errors/test_exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"},
},
]
Expand All @@ -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"},
},
]
Expand All @@ -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"},
},
]
Expand All @@ -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"
),
}

0 comments on commit 9b02831

Please sign in to comment.