Skip to content

Commit

Permalink
added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Aug 20, 2024
1 parent 09b8a88 commit 7fe8fdc
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 25 deletions.
8 changes: 0 additions & 8 deletions api/src/opentrons/protocol_engine/state/command_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ def get_filtered_command_ids(
}
return list(filtered_command.keys())

def get_filtered_queue_ids(self, all_commands: bool) -> list[str]:
print(list(self.get_fixit_queue_ids()))
return [
i
for i in self._all_command_ids
if i not in list(self.get_fixit_queue_ids())
]

def get_all_ids(self) -> List[str]:
"""Get all command IDs."""
return self._all_command_ids
Expand Down
79 changes: 66 additions & 13 deletions api/tests/opentrons/protocol_engine/state/test_command_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@


def create_queued_command_entry(
command_id: str = "command-id", index: int = 0
command_id: str = "command-id",
intent: CommandIntent = CommandIntent.PROTOCOL,
index: int = 0,
) -> CommandEntry:
"""Create a command entry for a queued command."""
return CommandEntry(create_queued_command(command_id=command_id), index)
return CommandEntry(
create_queued_command(command_id=command_id, intent=intent), index
)


def create_fixit_command_entry(
Expand Down Expand Up @@ -94,17 +98,6 @@ def test_get_all_commands(command_history: CommandHistory) -> None:
]


def test_get_all_filtered_commands(command_history: CommandHistory) -> None:
"""It should return a list of all commapnds."""
assert command_history.get_filtered_queue_ids(all_commands=False) == []
command_entry_1 = create_queued_command_entry()
command_entry_2 = create_queued_command_entry(index=1)
command_history._add("0", command_entry_1)
command_history._add("1", command_entry_2)
command_history._add_to_fixit_queue("1")
assert command_history.get_filtered_queue_ids(all_commands=False) == ["0"]


def test_get_all_ids(command_history: CommandHistory) -> None:
"""It should return a list of all command IDs."""
assert command_history.get_all_ids() == []
Expand Down Expand Up @@ -273,3 +266,63 @@ def test_remove_id_from_setup_queue(command_history: CommandHistory) -> None:
command_history._add_to_setup_queue("1")
command_history._remove_setup_queue_id("0")
assert command_history.get_setup_queue_ids() == OrderedSet(["1"])


def test_get_filtered_commands(command_history: CommandHistory) -> None:
"""It should return a list of all commands without fixit commands."""
assert list(command_history.get_filtered_command_ids()) == []
command_entry_1 = create_queued_command(command_id="0")
command_entry_2 = create_queued_command(command_id="1")
fixit_command_entry_1 = create_queued_command(
intent=CommandIntent.FIXIT, command_id="fixit-1"
)
command_history.append_queued_command(command_entry_1)
command_history.append_queued_command(command_entry_2)
command_history.append_queued_command(fixit_command_entry_1)
assert list(command_history.get_filtered_command_ids()) == ["0", "1"]


def test_get_all_filtered_commands(command_history: CommandHistory) -> None:
"""It should return a list of all commands without fixit commands."""
assert (
list(
command_history.get_filtered_command_ids(
command_intents=[
CommandIntent.FIXIT,
CommandIntent.PROTOCOL,
CommandIntent.SETUP,
]
)
)
== []
)
command_entry_1 = create_queued_command_entry()
command_entry_2 = create_queued_command_entry(index=1, intent=CommandIntent.SETUP)
fixit_command_entry_1 = create_queued_command_entry(intent=CommandIntent.FIXIT)
command_history._add("0", command_entry_1)
command_history._add("1", command_entry_2)
command_history._add("fixit-1", fixit_command_entry_1)
assert list(
command_history.get_filtered_command_ids(
command_intents=[
CommandIntent.FIXIT,
CommandIntent.PROTOCOL,
CommandIntent.SETUP,
]
)
) == ["0", "1", "fixit-1"]


def test_get_slice_with_filtered_list(command_history: CommandHistory) -> None:
"""It should return a slice of filtered commands."""
assert command_history.get_slice(0, 2) == []
command_entry_1 = create_queued_command_entry()
command_entry_2 = create_queued_command_entry(index=1)
command_entry_3 = create_queued_command_entry(index=2)
command_history._add("0", command_entry_1)
command_history._add("1", command_entry_2)
command_history._add("2", command_entry_3)
filtered_list = ["0", "1"]
assert command_history.get_slice(1, 3, command_ids=filtered_list) == [
command_entry_2.command,
]
45 changes: 45 additions & 0 deletions api/tests/opentrons/protocol_engine/state/test_command_view_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,48 @@ def test_get_errors_slice() -> None:
cursor=0,
total_length=4,
)


def test_get_slice_without_fixit() -> None:
"""It should select a cursor based on the running command, if present."""
command_1 = create_succeeded_command(command_id="command-id-1")
command_2 = create_succeeded_command(command_id="command-id-2")
command_3 = create_running_command(command_id="command-id-3")
command_4 = create_queued_command(command_id="command-id-4")
command_5 = create_queued_command(command_id="command-id-5")
command_6 = create_queued_command(
command_id="fixit-id-1", intent=cmd.CommandIntent.FIXIT
)
command_7 = create_queued_command(
command_id="fixit-id-2", intent=cmd.CommandIntent.FIXIT
)

subject = get_command_view(
commands=[
command_1,
command_2,
command_3,
command_4,
command_5,
command_6,
command_7,
],
queued_command_ids=[
"command-id-1",
"command-id-2",
"command-id-3",
"command-id-4",
"command-id-5",
"fixit-id-1",
"fixit-id-2",
],
queued_fixit_command_ids=["fixit-id-1", "fixit-id-2"],
)

result = subject.get_slice(cursor=None, length=7, include_fixit_commands=False)

assert result == CommandSlice(
commands=[command_1, command_2, command_3, command_4, command_5],
cursor=0,
total_length=5,
)
9 changes: 5 additions & 4 deletions robot-server/tests/runs/router/test_commands_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ async def test_get_run_commands(
run_data_manager=mock_run_data_manager,
cursor=None,
pageLength=42,
includeFixitCommands=True
includeFixitCommands=True,
)

assert result.content.data == [
Expand Down Expand Up @@ -421,7 +421,7 @@ async def test_get_run_commands_empty(
run_data_manager=mock_run_data_manager,
cursor=21,
pageLength=42,
includeFixitCommands=True
includeFixitCommands=True,
)

assert result.content.data == []
Expand All @@ -440,15 +440,16 @@ async def test_get_run_commands_not_found(
decoy.when(
mock_run_data_manager.get_commands_slice(
run_id="run-id", cursor=21, length=42, include_fixit_commands=True
) ).then_raise(not_found_error)
)
).then_raise(not_found_error)

with pytest.raises(ApiError) as exc_info:
await get_run_commands(
runId="run-id",
run_data_manager=mock_run_data_manager,
cursor=21,
pageLength=42,
includeFixitCommands=True
includeFixitCommands=True,
)

assert exc_info.value.status_code == 404
Expand Down

0 comments on commit 7fe8fdc

Please sign in to comment.