Skip to content

Commit

Permalink
fix(robot-server): Say "Flex" instead of "OT-3 Standard" in upload er…
Browse files Browse the repository at this point in the history
…ror message (#13609)

* Map internal strings to user-facing strings.

* Resolve todo in integration test.
  • Loading branch information
SyntaxColoring authored Sep 20, 2023
1 parent 719ac54 commit 04da21d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
13 changes: 11 additions & 2 deletions robot-server/robot_server/protocols/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ async def create_protocol(
if source.robot_type != robot_type:
raise ProtocolRobotTypeMismatch(
detail=(
f"This protocol is for {source.robot_type} robots."
f"This protocol is for {_user_facing_robot_type(source.robot_type)} robots."
f" It can't be analyzed or run on this robot,"
f" which is an {robot_type}."
f" which is {_user_facing_robot_type(robot_type, include_article=True)}."
)
).as_error(status.HTTP_422_UNPROCESSABLE_ENTITY)

Expand Down Expand Up @@ -557,3 +557,12 @@ async def get_protocol_analysis_as_document(
) from error

return PlainTextResponse(content=analysis, media_type="application/json")


def _user_facing_robot_type(
robot_type: RobotType, include_article: bool = False
) -> str:
if robot_type == "OT-2 Standard":
return "an OT-2" if include_article else "OT-2"
elif robot_type == "OT-3 Standard":
return "a Flex" if include_article else "Flex"
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,35 @@ stages:
errors:
- id: ProtocolRobotTypeMismatch
title: Protocol For Different Robot Type
detail: "This protocol is for OT-3 Standard robots. It can't be analyzed or run on this robot, which is an OT-2 Standard."
detail: "This protocol is for Flex robots. It can't be analyzed or run on this robot, which is an OT-2."
errorCode: '4000'

# TODO(mm, 2022-12-12): Also make sure an OT-3 server rejects OT-2 protocols.
---

test_name: Make sure an OT-3 server rejects OT-2 protocols.

marks:
- ot3_only
- usefixtures:
- ot3_server_base_url
- parametrize:
key: protocol_file_path
vals:
- 'tests/integration/protocols/empty_ot2.json'
- 'tests/integration/protocols/empty_ot2.py'

stages:
- name: Upload the protocol.
request:
url: '{ot3_server_base_url}/protocols'
method: POST
files:
files: "{protocol_file_path}"
response:
status_code: 422
json:
errors:
- id: ProtocolRobotTypeMismatch
title: Protocol For Different Robot Type
detail: "This protocol is for OT-2 robots. It can't be analyzed or run on this robot, which is a Flex."
errorCode: '4000'
16 changes: 16 additions & 0 deletions robot-server/tests/integration/protocols/empty_ot2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$otSharedSchema": "#/protocol/schemas/6",
"schemaVersion": 6,
"metadata": {},
"robot": {
"model": "OT-2 Standard",
"deckId": "ot2_standard"
},
"pipettes": {},
"modules": {},
"labware": {},
"liquids": {},
"labwareDefinitions": {},
"commands": [],
"commandAnnotations": []
}
8 changes: 8 additions & 0 deletions robot-server/tests/integration/protocols/empty_ot2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
requirements = {
"robotType": "OT-2",
"apiLevel": "2.15",
}


def run(protocol):
pass

0 comments on commit 04da21d

Please sign in to comment.