forked from openml/server-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflows_migration_test.py
More file actions
109 lines (93 loc) · 3.41 KB
/
flows_migration_test.py
File metadata and controls
109 lines (93 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import asyncio
import re
from http import HTTPStatus
from typing import Any
import deepdiff
import httpx
import pytest
from core.conversions import (
nested_remove_single_element_list,
nested_str_to_num,
)
from tests.conftest import Flow
@pytest.mark.mut
async def test_flow_exists_not(
py_api: httpx.AsyncClient,
php_api: httpx.AsyncClient,
) -> None:
path = "exists/foo/bar"
py_response, php_response = await asyncio.gather(
py_api.post("/flows/exists", json={"name": "foo", "external_version": "bar"}),
php_api.get(f"/flow/{path}"),
)
assert py_response.status_code == HTTPStatus.NOT_FOUND
assert php_response.status_code == HTTPStatus.OK
assert php_response.json() == {"flow_exists": {"exists": "false", "id": str(-1)}}
# RFC 9457: Python API now returns problem+json format
error = py_response.json()
assert re.match(
pattern=r"Flow with name \S+ and external version \S+ not found.",
string=error["detail"],
)
@pytest.mark.mut
async def test_flow_exists(
persisted_flow: Flow,
py_api: httpx.AsyncClient,
php_api: httpx.AsyncClient,
) -> None:
path = f"exists/{persisted_flow.name}/{persisted_flow.external_version}"
py_response, php_response = await asyncio.gather(
py_api.post(
"/flows/exists",
json={
"name": persisted_flow.name,
"external_version": persisted_flow.external_version,
},
),
php_api.get(f"/flow/{path}"),
)
assert py_response.status_code == php_response.status_code, php_response.content
expect_php = {"flow_exists": {"exists": "true", "id": str(persisted_flow.id)}}
assert php_response.json() == expect_php
assert py_response.json() == {"flow_id": persisted_flow.id}
@pytest.mark.parametrize(
"flow_id",
range(1, 16),
)
async def test_get_flow_equal(
flow_id: int, py_api: httpx.AsyncClient, php_api: httpx.AsyncClient
) -> None:
response, php_response = await asyncio.gather(
py_api.get(f"/flows/{flow_id}"),
php_api.get(f"/flow/{flow_id}"),
)
assert response.status_code == HTTPStatus.OK
new = response.json()
# PHP sets parameter default value to [], None is more appropriate, omission is considered
# Similar for the default "identifier" of subflows.
# Subflow field (old: component) is omitted if empty
def convert_flow_naming_and_defaults(flow: dict[str, Any]) -> dict[str, Any]:
for parameter in flow["parameter"]:
if parameter["default_value"] is None:
parameter["default_value"] = []
for subflow in flow["subflows"]:
subflow["flow"] = convert_flow_naming_and_defaults(subflow["flow"])
if subflow["identifier"] is None:
subflow["identifier"] = []
flow["component"] = flow.pop("subflows")
if flow["component"] == []:
flow.pop("component")
return flow
new = convert_flow_naming_and_defaults(new)
new = nested_remove_single_element_list(new)
expected = php_response.json()["flow"]
# The reason we don't transform "new" to str is that it becomes harder to ignore numeric type
# differences (e.g., '1.0' vs '1')
expected = nested_str_to_num(expected)
difference = deepdiff.diff.DeepDiff(
expected,
new,
ignore_order=True,
ignore_numeric_type_changes=True,
)
assert not difference