Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/etos_client/etos/v0/schema/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS v0 schema."""
"""ETOS v0 request schema."""
import json
from uuid import UUID

Expand Down
2 changes: 1 addition & 1 deletion cli/src/etos_client/etos/v0/schema/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS v0 response."""
"""ETOS v0 response schema."""
from uuid import UUID
from pydantic import BaseModel

Expand Down
4 changes: 2 additions & 2 deletions cli/src/etos_client/etos/v1alpha/etos.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from etos_client.etos.v0.test_results import TestResults
from etos_client.etos.v0.event_repository import graphql
from etos_client.etos.v0.test_run import TestRun
from etos_client.etos.v0.schema.response import ResponseSchema
from etos_client.etos.v0.schema.request import RequestSchema
from etos_client.etos.v1alpha.schema.response import ResponseSchema
from etos_client.etos.v1alpha.schema.request import RequestSchema


# Max total time for a ping request including delays with backoff factor 0.5 will be:
Expand Down
16 changes: 16 additions & 0 deletions cli/src/etos_client/etos/v1alpha/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright Axis Communications AB.
#
# For a full list of individual contributors, please see the commit history.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOSv0 schemas."""
73 changes: 73 additions & 0 deletions cli/src/etos_client/etos/v1alpha/schema/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright Axis Communications AB.
#
# For a full list of individual contributors, please see the commit history.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS v1 request schema."""
import json
from uuid import UUID

from typing import Optional, Union
from pydantic import BaseModel, ValidationInfo, field_validator


class RequestSchema(BaseModel):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the only difference from the v0 schema is the absence of parent_activity. The code is duplicated so that it is easier to modify it (i. e. independently from v0).

"""Schema for ETOSv1 API requests."""

artifact_id: Optional[str]
artifact_identity: Optional[str]
test_suite_url: str
dataset: Optional[Union[dict, list]] = {}
execution_space_provider: Optional[str] = "default"
iut_provider: Optional[str] = "default"
log_area_provider: Optional[str] = "default"

@classmethod
def from_args(cls, args: dict) -> "RequestSchema":
"""Create a RequestSchema from an argument list from argparse."""
return RequestSchema(
artifact_id=args["--identity"],
artifact_identity=args["--identity"],
test_suite_url=args["--test-suite"],
dataset=args["--dataset"],
execution_space_provider=args["--execution-space-provider"] or "default",
iut_provider=args["--iut-provider"] or "default",
log_area_provider=args["--log-area-provider"] or "default",
)

@field_validator("artifact_identity")
def trim_identity_if_necessary(
cls, artifact_identity: Optional[str], info: ValidationInfo
) -> Optional[str]:
"""Trim identity if id is set."""
if info.data.get("artifact_id") is not None:
return None
return artifact_identity

@field_validator("artifact_id")
def is_uuid(cls, artifact_id: Optional[str]) -> Optional[str]:
"""Test if string is a valid UUID v4."""
try:
UUID(artifact_id, version=4)
except ValueError:
return None
return artifact_id

@field_validator("dataset")
def dataset_list_trimming(cls, dataset: Optional[Union[dict, list]]) -> list[dict]:
"""Trim away list completely should the dataset only contain a single index."""
if dataset is None:
return [{}]
if len(dataset) == 1:
return json.loads(dataset[0])
return [json.loads(data) for data in dataset]
37 changes: 37 additions & 0 deletions cli/src/etos_client/etos/v1alpha/schema/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright Axis Communications AB.
#
# For a full list of individual contributors, please see the commit history.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""ETOS v1 response schema."""
from uuid import UUID
from pydantic import BaseModel


class ResponseSchema(BaseModel):
"""Response model for the ETOS start API."""

event_repository: str
tercc: UUID
artifact_id: UUID
artifact_identity: str

@classmethod
def from_response(cls, response: dict) -> "ResponseSchema":
"""Create a ResponseSchema from a dictionary. Typically used for ETOS API http response."""
return ResponseSchema(
event_repository=response.get("event_repository"), # type: ignore
tercc=response.get("tercc"), # type: ignore
artifact_id=response.get("artifact_id"), # type: ignore
artifact_identity=response.get("artifact_identity"), # type: ignore
)