Skip to content

Commit ce22ef0

Browse files
committed
link conversion tests
1 parent 5b6b1d4 commit ce22ef0

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

temporalio/nexus/_link_conversion.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ def _event_reference_to_query_params(
9494
event_type_name.removeprefix("EVENT_TYPE_")
9595
)
9696
return urllib.parse.urlencode(
97-
{"eventType": event_type_name, "referenceType": "EventReference"}
97+
{
98+
"referenceType": "EventReference",
99+
"eventType": event_type_name,
100+
"eventID": event_ref.event_id,
101+
}
98102
)
99103

100104

tests/nexus/test_link_conversion.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,77 @@
1+
import urllib.parse
2+
from typing import Any
3+
4+
import pytest
5+
6+
import temporalio.api.common.v1
7+
import temporalio.api.enums.v1
18
import temporalio.nexus._link_conversion
29

310

11+
@pytest.mark.parametrize(
12+
["query_param_str", "expected_event_ref"],
13+
[
14+
(
15+
"eventType=NexusOperationScheduled&referenceType=EventReference&eventID=7",
16+
{
17+
"event_type": temporalio.api.enums.v1.EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
18+
"event_id": 7,
19+
},
20+
),
21+
# event ID is optional in query params; we set it to 0 in the event ref if missing
22+
(
23+
"eventType=NexusOperationScheduled&referenceType=EventReference",
24+
{
25+
"event_type": temporalio.api.enums.v1.EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
26+
"event_id": 0,
27+
},
28+
),
29+
# Older server sends EVENT_TYPE_CONSTANT_CASE event type name
30+
(
31+
"eventType=EVENT_TYPE_NEXUS_OPERATION_SCHEDULED&referenceType=EventReference",
32+
{
33+
"event_type": temporalio.api.enums.v1.EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
34+
"event_id": 0,
35+
},
36+
),
37+
],
38+
)
39+
def test_query_params_to_event_reference(
40+
query_param_str: str, expected_event_ref: dict[str, Any]
41+
):
42+
event_ref = temporalio.nexus._link_conversion._query_params_to_event_reference(
43+
query_param_str
44+
)
45+
for k, v in expected_event_ref.items():
46+
assert getattr(event_ref, k) == v
47+
48+
49+
@pytest.mark.parametrize(
50+
["event_ref", "expected_query_param_str"],
51+
[
52+
# We always send PascalCase event type names (no EventType prefix)
53+
(
54+
{
55+
"event_type": temporalio.api.enums.v1.EventType.EVENT_TYPE_NEXUS_OPERATION_SCHEDULED,
56+
"event_id": 7,
57+
},
58+
"eventType=NexusOperationScheduled&referenceType=EventReference&eventID=7",
59+
),
60+
],
61+
)
62+
def test_event_reference_to_query_params(
63+
event_ref: dict[str, Any], expected_query_param_str: str
64+
):
65+
query_params_str = (
66+
temporalio.nexus._link_conversion._event_reference_to_query_params(
67+
temporalio.api.common.v1.Link.WorkflowEvent.EventReference(**event_ref)
68+
)
69+
)
70+
query_params = urllib.parse.parse_qs(query_params_str)
71+
expected_query_params = urllib.parse.parse_qs(expected_query_param_str)
72+
assert query_params == expected_query_params
73+
74+
475
def test_link_conversion_utilities():
576
p2c = temporalio.nexus._link_conversion._event_type_pascal_case_to_constant_case
677
c2p = temporalio.nexus._link_conversion._event_type_constant_case_to_pascal_case

0 commit comments

Comments
 (0)