feat: automation context result view reporting and creating

This commit is contained in:
Gergő Jedlicska 2023-10-26 15:00:03 +02:00
Родитель 1ff3245531
Коммит a1831b57db
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 868C59E4F75C7534
2 изменённых файлов: 65 добавлений и 5 удалений

Просмотреть файл

@ -2,7 +2,7 @@
from dataclasses import dataclass, field
from pathlib import Path
import time
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Tuple, Union
import httpx
from gql import gql
@ -111,7 +111,7 @@ class AutomationContext:
def create_new_version_in_project(
self, root_object: Base, model_name: str, version_message: str = ""
) -> str:
) -> Tuple[str, str]:
"""Save a base model to a new version on the project.
Args:
@ -137,9 +137,11 @@ class AutomationContext:
self.automation_run_data.project_id,
model_name,
)
print(branch_create)
if isinstance(branch_create, Exception):
raise branch_create
model_id = branch_create
else:
model_id = branch.id
root_object_id = operations.send(
root_object,
@ -159,7 +161,31 @@ class AutomationContext:
raise version_id
self._automation_result.result_versions.append(version_id)
return version_id
return model_id, version_id
def set_context_view(
self,
# f"{model_id}@{version_id} or {model_id} "
resource_ids: Optional[List[str]] = None,
include_source_model_version: bool = True,
) -> None:
link_resources = (
[
f"{self.automation_run_data.model_id}@{self.automation_run_data.version_id}"
]
if include_source_model_version
else []
)
if resource_ids:
link_resources.append(*resource_ids)
if not link_resources:
raise Exception(
"We do not have enough resource ids to compose a context view"
)
self._automation_result.result_view = (
f"{self.automation_run_data.speckle_server_url}/projects"
f"/{self.automation_run_data.project_id}/models/{','.join(link_resources)}"
)
def report_run_status(self) -> None:
"""Report the current run status to the project of this automation."""

Просмотреть файл

@ -244,5 +244,39 @@ def test_create_version_in_project(
) -> None:
root_object = Base()
root_object.foo = "bar"
version_id = automation_context.create_new_version_in_project(root_object, "foobar")
model_id, version_id = automation_context.create_new_version_in_project(
root_object, "foobar"
)
assert model_id is not None
assert version_id is not None
def test_set_context_view(automation_context: AutomationContext) -> None:
automation_context.set_context_view()
assert automation_context._automation_result.result_view is not None
assert automation_context._automation_result.result_view.endswith(
f"models/{automation_context.automation_run_data.model_id}@{automation_context.automation_run_data.version_id}"
)
automation_context._automation_result.result_view = None
dummy_context = "foo@bar"
automation_context.set_context_view([dummy_context])
assert automation_context._automation_result.result_view is not None
assert automation_context._automation_result.result_view.endswith(
f"models/{automation_context.automation_run_data.model_id}@{automation_context.automation_run_data.version_id},{dummy_context}"
)
automation_context._automation_result.result_view = None
dummy_context = "foo@baz"
automation_context.set_context_view(
[dummy_context], include_source_model_version=False
)
assert automation_context._automation_result.result_view is not None
assert automation_context._automation_result.result_view.endswith(
f"models/{dummy_context}"
)