Skip to content

Commit 6a8eec5

Browse files
committed
test: add fixture plugin and test for BatchCommitCommandEffect
Verifies that a plugin can import BatchCommitCommandEffect, construct command instances with command_uuid, and produce the correct effect payload through the RestrictedPython sandbox.
1 parent 39aa934 commit 6a8eec5

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"sdk_version": "0.1.4",
3+
"plugin_version": "0.0.1",
4+
"name": "test_batch_commit",
5+
"description": "Test plugin for BatchCommitCommandEffect",
6+
"components": {
7+
"protocols": [
8+
{
9+
"class": "test_batch_commit.protocols.my_protocol:Protocol",
10+
"description": "Returns a BatchCommitCommandEffect",
11+
"data_access": {
12+
"event": "",
13+
"read": [],
14+
"write": []
15+
}
16+
}
17+
],
18+
"commands": [],
19+
"content": [],
20+
"effects": [],
21+
"views": []
22+
},
23+
"secrets": [],
24+
"tags": {},
25+
"references": [],
26+
"license": "",
27+
"diagram": false,
28+
"readme": "./README.md"
29+
}

plugin_runner/tests/fixtures/plugins/test_batch_commit/__init__.py

Whitespace-only changes.

plugin_runner/tests/fixtures/plugins/test_batch_commit/protocols/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from canvas_sdk.commands import AssessCommand, PlanCommand
2+
from canvas_sdk.effects import Effect
3+
from canvas_sdk.effects.batch_commit import BatchCommitCommandEffect
4+
from canvas_sdk.events import EventType
5+
from canvas_sdk.protocols import BaseProtocol
6+
7+
8+
class Protocol(BaseProtocol):
9+
"""Test protocol that returns a BatchCommitCommandEffect."""
10+
11+
RESPONDS_TO = EventType.Name(EventType.UNKNOWN)
12+
13+
def compute(self) -> list[Effect]:
14+
"""Return a batch commit effect with two commands."""
15+
commands = [
16+
PlanCommand(command_uuid="cmd-001"),
17+
AssessCommand(command_uuid="cmd-002"),
18+
]
19+
return [BatchCommitCommandEffect(commands=commands).apply()]

plugin_runner/tests/test_plugin_runner.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,32 @@ def test_payment_processor(
792792
]
793793

794794
assert result[0].effects == expected_effects
795+
796+
797+
@pytest.mark.parametrize("install_test_plugin", ["test_batch_commit"], indirect=True)
798+
def test_batch_commit_effect_through_plugin_runner(
799+
install_test_plugin: Path,
800+
plugin_runner: PluginRunner,
801+
load_test_plugins: None,
802+
db: None,
803+
) -> None:
804+
"""Test that a plugin can import and return a BatchCommitCommandEffect."""
805+
result = list(plugin_runner.HandleEvent(EventRequest(type=EventType.UNKNOWN), None))
806+
807+
assert len(result) == 1
808+
assert result[0].success is True
809+
assert len(result[0].effects) == 1
810+
811+
effect = result[0].effects[0]
812+
assert effect.type == EffectType.BATCH_COMMIT_COMMANDS
813+
814+
payload = json.loads(effect.payload)
815+
assert len(payload["data"]["commands"]) == 2
816+
assert payload["data"]["commands"][0] == {
817+
"type": "COMMIT_PLAN_COMMAND",
818+
"command": "cmd-001",
819+
}
820+
assert payload["data"]["commands"][1] == {
821+
"type": "COMMIT_ASSESS_COMMAND",
822+
"command": "cmd-002",
823+
}

0 commit comments

Comments
 (0)