Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Aug 12, 2024
1 parent 38b1ebe commit 7319a5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from typing import Any

from models_library.api_schemas_webserver.catalog import (
ServiceInputGet,
ServiceOutputGet,
)
from models_library.services import BaseServiceIOModel, ServiceInput, ServiceOutput
from pint import PintError, UnitRegistry

Expand Down Expand Up @@ -45,20 +41,25 @@ async def replace_service_input_outputs(
):
"""Thin wrapper to replace i/o ports in returned service model"""
# This is a fast solution until proper models are available for the web API
for input_key in service["inputs"]:
new_input: ServiceInputGet = (
await ServiceInputGetFactory.from_catalog_service_api_model(
service=service, input_key=input_key, ureg=unit_registry
)
new_inputs = [
await ServiceInputGetFactory.from_catalog_service_api_model(
service=service, input_key=input_key, ureg=unit_registry
)
service["inputs"][input_key] = new_input.dict(**export_options)
for input_key in service["inputs"]
]

for output_key in service["outputs"]:
new_output: ServiceOutputGet = (
await ServiceOutputGetFactory.from_catalog_service_api_model(
service=service, output_key=output_key, ureg=unit_registry
)
new_outputs = [
await ServiceOutputGetFactory.from_catalog_service_api_model(
service=service, output_key=output_key, ureg=unit_registry
)
for output_key in service["outputs"]
]

# replace if above is successful
for input_key, new_input in zip(service["inputs"], new_inputs, strict=True):
service["inputs"][input_key] = new_input.dict(**export_options)

for output_key, new_output in zip(service["outputs"], new_outputs, strict=True):
service["outputs"][output_key] = new_output.dict(**export_options)


Expand Down
11 changes: 7 additions & 4 deletions services/web/server/tests/unit/isolated/test_catalog_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import asyncio
import json
from copy import deepcopy

Expand Down Expand Up @@ -69,14 +70,16 @@ def test_from_catalog_to_webapi_service(
"owner": "[email protected]",
}

def _run():
def _run_async_test():
s = deepcopy(catalog_service)
replace_service_input_outputs(
s, unit_registry=unit_registry, **RESPONSE_MODEL_POLICY
asyncio.get_event_loop().run_until_complete(
replace_service_input_outputs(
s, unit_registry=unit_registry, **RESPONSE_MODEL_POLICY
)
)
return s

result = benchmark(_run)
result = benchmark(_run_async_test)

# check result
got = json.dumps(result, indent=1)
Expand Down

0 comments on commit 7319a5c

Please sign in to comment.