Skip to content

Commit e58518c

Browse files
committed
refactor
1 parent 75d3f71 commit e58518c

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

tests/e2e-playwright/tests/metamodeling/test_response_surface_modeling.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import json
12
import logging
23
import re
3-
from collections.abc import Callable
4+
from collections.abc import Callable, Iterator
45
from typing import Any, Final
56

7+
import pytest
68
from playwright.sync_api import Page
79
from pydantic import AnyUrl
810
from pytest_simcore.helpers.logging_tools import log_context
@@ -22,6 +24,44 @@
2224
_FUNCTION_NAME: Final[str] = "playwright_test_function"
2325

2426

27+
@pytest.fixture
28+
def create_function_from_project() -> Iterator[Callable[[Page, str], dict[str, Any]]]:
29+
def _create_function_from_project(
30+
page: Page,
31+
project_uuid: str,
32+
) -> dict[str, Any]:
33+
with log_context(
34+
logging.INFO,
35+
f"Convert {project_uuid=} / {_STUDY_FUNCTION_NAME} to a function",
36+
) as ctx:
37+
with page.expect_response(re.compile(rf"/projects/{project_uuid}")):
38+
page.get_by_test_id(f"studyBrowserListItem_{project_uuid}").click()
39+
page.wait_for_timeout(2000)
40+
page.get_by_text("create function").first.click()
41+
page.wait_for_timeout(2000)
42+
43+
with page.expect_response(
44+
lambda response: re.compile(r"/functions").search(response.url)
45+
is not None
46+
and response.request.method == "POST"
47+
) as create_function_response:
48+
page.get_by_test_id("create_function_page_btn").click()
49+
assert (
50+
create_function_response.value.ok
51+
), f"Failed to create function: {create_function_response.value.status}"
52+
function_data = create_function_response.value.json()
53+
54+
ctx.logger.info(
55+
"Created function: %s", f"{json.dumps(function_data['data'], indent=2)}"
56+
)
57+
58+
return function_data["data"]
59+
60+
yield _create_function_from_project
61+
62+
# cleanup the function
63+
64+
2565
def test_response_surface_modeling(
2666
page: Page,
2767
create_project_from_service_dashboard: Callable[
@@ -32,6 +72,7 @@ def test_response_surface_modeling(
3272
service_version: str | None,
3373
product_url: AnyUrl,
3474
is_service_legacy: bool,
75+
create_function_from_project: Callable[..., dict[str, Any]],
3576
):
3677
# 1. create the initial study with jsonifier
3778
with log_context(logging.INFO, "Create new study for function"):
@@ -104,29 +145,9 @@ def test_response_surface_modeling(
104145
assert (
105146
our_project["name"] == _STUDY_FUNCTION_NAME
106147
), f"Expected to find our project named {_STUDY_FUNCTION_NAME} in {project_listing}"
107-
our_project_uuid = our_project["uuid"]
108148

109149
# 3. convert it to a function
110-
with log_context(
111-
logging.INFO,
112-
f"Convert {our_project_uuid=} / {our_project['name']} to a function",
113-
) as ctx:
114-
with page.expect_response(re.compile(rf"/projects/{our_project_uuid}")):
115-
page.get_by_test_id(f"studyBrowserListItem_{our_project_uuid}").click()
116-
page.wait_for_timeout(2000)
117-
page.get_by_text("create function").first.click()
118-
page.wait_for_timeout(2000)
119-
120-
with page.expect_response(
121-
lambda response: re.compile(r"/functions").search(response.url) is not None
122-
and response.request.method == "POST"
123-
) as create_function_response:
124-
page.get_by_test_id("create_function_page_btn").click()
125-
assert (
126-
create_function_response.value.ok
127-
), f"Failed to create function: {create_function_response.value.status}"
128-
function_data = create_function_response.value.json()
129-
ctx.logger.info("Created function: %s", function_data)
150+
create_function_from_project(page, our_project["uuid"])
130151

131152
# 3. start a RSM with that function
132153

0 commit comments

Comments
 (0)