Skip to content

Commit 94fb61d

Browse files
committed
test(converter): update enrich_rs_ri_with_rs_srs tests
1 parent cb5258a commit 94fb61d

1 file changed

Lines changed: 52 additions & 23 deletions

File tree

converter/tests/cisu/test_resources_info_cisu_helper.py

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@
33
)
44

55

6-
def _make_rs_ri(resources: list[dict]) -> dict:
7-
"""Wrap a resource list in a minimal RS-RI use-case dict."""
8-
return {"resource": resources}
6+
def _wrap_edxl(
7+
use_case: dict, message_type: str, distribution_id: str = "dist-test"
8+
) -> dict:
9+
"""Wrap a use-case dict in a minimal EDXL envelope."""
10+
return {
11+
"distributionID": distribution_id,
12+
"content": [
13+
{
14+
"jsonContent": {
15+
"embeddedJsonContent": {"message": {message_type: use_case}}
16+
}
17+
}
18+
],
19+
}
20+
21+
22+
def _make_rs_ri_edxl(resources: list[dict], distribution_id: str = "dist-ri") -> dict:
23+
"""Wrap a resource list in a minimal RS-RI EDXL envelope."""
24+
25+
return _wrap_edxl({"resource": resources}, "resourcesInfo", distribution_id)
26+
27+
28+
def _make_rs_sr_edxl(use_case: dict, distribution_id: str = "dist-sr") -> dict:
29+
"""Wrap an RS-SR use-case in a minimal EDXL envelope."""
30+
return _wrap_edxl(use_case, "resourcesStatus", distribution_id)
931

1032

1133
def test_no_persisted_rs_sr():
@@ -15,16 +37,14 @@ def test_no_persisted_rs_sr():
1537
ne pas modifier la ressource originale.
1638
"""
1739

18-
rs_ri = _make_rs_ri(
40+
rs_ri_edxl = _make_rs_ri_edxl(
1941
[
2042
{"resourceId": "r1"},
2143
{"resourceId": "r2"},
2244
]
2345
)
2446

25-
rs_sr_list = []
26-
27-
result = enrich_rs_ri_with_rs_srs(rs_ri, rs_sr_list)
47+
result = enrich_rs_ri_with_rs_srs(rs_ri_edxl, [])
2848

2949
assert result is not None
3050
assert result["resource"][0] == {"resourceId": "r1"}
@@ -38,19 +58,19 @@ def test_no_current_state_but_persisted_rs_sr():
3858
remplacer le status de la ressource original par celui de la ressource persistée
3959
"""
4060

41-
rs_ri = _make_rs_ri(
61+
rs_ri_edxl = _make_rs_ri_edxl(
4262
[
4363
{"resourceId": "r1"},
4464
{"resourceId": "r2"},
4565
]
4666
)
4767

48-
rs_sr_list = [
49-
{"resourceId": "r1", "state": {"status": "OK"}},
50-
{"resourceId": "r2", "state": {"status": "KO"}},
68+
rs_sr_edxl_list = [
69+
_make_rs_sr_edxl({"resourceId": "r1", "state": {"status": "OK"}}, "dist-sr-1"),
70+
_make_rs_sr_edxl({"resourceId": "r2", "state": {"status": "KO"}}, "dist-sr-2"),
5171
]
5272

53-
result = enrich_rs_ri_with_rs_srs(rs_ri, rs_sr_list)
73+
result = enrich_rs_ri_with_rs_srs(rs_ri_edxl, rs_sr_edxl_list)
5474

5575
assert result is not None
5676
assert result["resource"][0]["state"] == [{"status": "OK"}]
@@ -64,7 +84,7 @@ def test_current_state_and_persisted_rs_sr():
6484
remplacer le status de la ressource original par le status le plus récent en se basant sur le champ datetime contenu dans le status.
6585
"""
6686

67-
rs_ri = _make_rs_ri(
87+
rs_ri_edxl = _make_rs_ri_edxl(
6888
[
6989
{
7090
"resourceId": "r1",
@@ -79,18 +99,27 @@ def test_current_state_and_persisted_rs_sr():
7999
]
80100
)
81101

82-
rs_sr_list = [
83-
{
84-
"resourceId": "r1",
85-
"state": {"status": "PENDING2", "datetime": "2025-05-18T17:00:00+02:00"},
86-
},
87-
{
88-
"resourceId": "r2",
89-
"state": {"status": "DONE2", "datetime": "2025-05-18T20:00:00+02:00"},
90-
},
102+
rs_sr_edxl_list = [
103+
_make_rs_sr_edxl(
104+
{
105+
"resourceId": "r1",
106+
"state": {
107+
"status": "PENDING2",
108+
"datetime": "2025-05-18T17:00:00+02:00",
109+
},
110+
},
111+
"dist-sr-1",
112+
),
113+
_make_rs_sr_edxl(
114+
{
115+
"resourceId": "r2",
116+
"state": {"status": "DONE2", "datetime": "2025-05-18T20:00:00+02:00"},
117+
},
118+
"dist-sr-2",
119+
),
91120
]
92121

93-
result = enrich_rs_ri_with_rs_srs(rs_ri, rs_sr_list)
122+
result = enrich_rs_ri_with_rs_srs(rs_ri_edxl, rs_sr_edxl_list)
94123

95124
assert result is not None
96125
assert result["resource"][0]["state"][0]["status"] == "PENDING"

0 commit comments

Comments
 (0)