diff --git a/qase-python-commons/changelog.md b/qase-python-commons/changelog.md index b815ca01..69da3910 100644 --- a/qase-python-commons/changelog.md +++ b/qase-python-commons/changelog.md @@ -1,3 +1,9 @@ +# qase-python-commons@3.2.0 + +## What's new + +Updated the `file` reporter and support new API v2 client + # qase-python-commons@3.1.9 ## What's new diff --git a/qase-python-commons/pyproject.toml b/qase-python-commons/pyproject.toml index dd00ef1b..334635c6 100644 --- a/qase-python-commons/pyproject.toml +++ b/qase-python-commons/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "qase-python-commons" -version = "3.1.9" +version = "3.2.0" description = "A library for Qase TestOps and Qase Report" readme = "README.md" authors = [{name = "Qase Team", email = "support@qase.io"}] @@ -31,7 +31,7 @@ dependencies = [ "certifi>=2024.2.2", "attrs>=23.2.0", "qase-api-client~=1.1.1", - "qase-api-v2-client~=1.0.0", + "qase-api-v2-client~=1.1.0", "more_itertools" ] diff --git a/qase-python-commons/src/qase/commons/client/api_v1_client.py b/qase-python-commons/src/qase/commons/client/api_v1_client.py index 982ec2df..70f5442e 100644 --- a/qase-python-commons/src/qase/commons/client/api_v1_client.py +++ b/qase-python-commons/src/qase/commons/client/api_v1_client.py @@ -171,8 +171,14 @@ def _prepare_result(self, project_code: str, result: Result) -> Dict: case_data["layer"] = result.get_field('layer') suite = None - if result.get_suite_title(): - suite = "\t".join(result.get_suite_title().split(".")) + if result.relations is not None and result.relations.suite is not None and len( + result.relations.suite.data) != 0: + suites = [] + + for raw in result.relations.suite.data: + suites.append(raw.title) + + suite = "\t".join(suites) if result.get_field('suite'): suite = result.get_field('suite') diff --git a/qase-python-commons/src/qase/commons/client/api_v2_client.py b/qase-python-commons/src/qase/commons/client/api_v2_client.py index fd16b7d5..0b5ab514 100644 --- a/qase-python-commons/src/qase/commons/client/api_v2_client.py +++ b/qase-python-commons/src/qase/commons/client/api_v2_client.py @@ -1,7 +1,7 @@ from typing import Dict import certifi -from qase.api_client_v2 import ResultsApi +from qase.api_client_v2 import ResultsApi, ResultCreateFields from qase.api_client_v2.api_client import ApiClient from qase.api_client_v2.configuration import Configuration from qase.api_client_v2.models.create_results_request_v2 import CreateResultsRequestV2 @@ -75,23 +75,25 @@ def _prepare_result(self, project_code: str, result: Result) -> ResultCreate: execution=ResultExecution(start_time=result.execution.start_time, end_time=result.execution.end_time, status=result.execution.status, duration=result.execution.duration, stacktrace=result.execution.stacktrace, thread=result.execution.thread), - fields=result.fields, + fields=ResultCreateFields.from_dict(result.fields), attachments=[attach.hash for attach in attached], steps=steps, - step_type=ResultStepsType.CLASSIC, + steps_type=ResultStepsType.CLASSIC, params=result.params, + param_groups=result.param_groups, muted=False, message=result.message, ) - if result.get_suite_title(): + if result.relations is not None and result.relations.suite is not None and len( + result.relations.suite.data) != 0: data = [] root_suite = self.config.root_suite if root_suite: data.append(RelationSuiteItem(title=root_suite)) - for suite in result.get_suite_title().split("."): - data.append(RelationSuiteItem(title=suite)) + for raw in result.relations.suite.data: + data.append(RelationSuiteItem(title=raw.title)) result_model_v2.relations = ResultRelations(suite=RelationSuite(data=data)) diff --git a/qase-python-commons/src/qase/commons/models/__init__.py b/qase-python-commons/src/qase/commons/models/__init__.py index 941c853e..ae4119ab 100644 --- a/qase-python-commons/src/qase/commons/models/__init__.py +++ b/qase-python-commons/src/qase/commons/models/__init__.py @@ -1,7 +1,6 @@ from .result import Result, Field from .run import Run from .attachment import Attachment -from .suite import Suite from .relation import Relation from .step import Step from .runtime import Runtime @@ -10,7 +9,6 @@ Result, Run, Attachment, - Suite, Relation, Step, Runtime, diff --git a/qase-python-commons/src/qase/commons/models/relation.py b/qase-python-commons/src/qase/commons/models/relation.py index 2d9c3bf0..421ba4ab 100644 --- a/qase-python-commons/src/qase/commons/models/relation.py +++ b/qase-python-commons/src/qase/commons/models/relation.py @@ -1,13 +1,23 @@ from .basemodel import BaseModel -class RelationSuite(BaseModel): - def __init__(self, suite_id: int, title: str) -> None: - self.suite_id = suite_id +class SuiteData(BaseModel): + def __init__(self, title: str) -> None: + self.public_id = None self.title = title +class RelationSuite(BaseModel): + def __init__(self) -> None: + self.data = [] + + def add_data(self, data: SuiteData) -> None: + self.data.append(data) + + class Relation(BaseModel): - def __init__(self, type: str, data: RelationSuite): - self.type = type - self.data = data + def __init__(self): + self.suite = RelationSuite() + + def add_suite(self, suite: SuiteData) -> None: + self.suite.add_data(suite) diff --git a/qase-python-commons/src/qase/commons/models/result.py b/qase-python-commons/src/qase/commons/models/result.py index 8f1118d8..33a95354 100644 --- a/qase-python-commons/src/qase/commons/models/result.py +++ b/qase-python-commons/src/qase/commons/models/result.py @@ -4,7 +4,6 @@ from typing import Type, Optional, Union, Dict, List from .basemodel import BaseModel from .step import Step -from .suite import Suite from .attachment import Attachment from .relation import Relation from .. import QaseUtils @@ -79,10 +78,9 @@ def __init__(self, title: str, signature: str) -> None: self.params: Optional[dict] = {} self.param_groups: Optional[List[List[str]]] = [] self.author: Optional[str] = None - self.relations: List[Type[Relation]] = [] + self.relations: Type[Relation] = None self.muted: bool = False self.message: Optional[str] = None - self.suite: Optional[Type[Suite]] = None QaseUtils.get_host_data() def add_message(self, message: str) -> None: @@ -97,20 +95,14 @@ def add_steps(self, steps: List[Type[Step]]) -> None: def add_attachment(self, attachment: Attachment) -> None: self.attachments.append(attachment) - def add_relation(self, relation: Type[Relation]) -> None: - self.relations.append(relation) - def add_param(self, key: str, value: str) -> None: self.params[key] = value def add_param_groups(self, values: List[str]) -> None: self.param_groups.append(values) - def add_relation(self, relation: Type[Relation]) -> None: - self.relations.append(relation) - - def add_suite(self, suite: Type[Suite]) -> None: - self.suite = suite + def set_relation(self, relation: Relation) -> None: + self.relations = relation def get_status(self) -> Optional[str]: return self.execution.status @@ -127,17 +119,10 @@ def get_field(self, name: str) -> Optional[Type[Field]]: return None def get_testops_id(self) -> Optional[int]: - if self.testops_id is None: - # Hack for old API - return 0 return self.testops_id def get_duration(self) -> int: return self.execution.duration - def get_suite_title(self) -> Optional[str]: - if self.suite: - return self.suite.title - def set_run_id(self, run_id: str) -> None: self.run_id = run_id diff --git a/qase-python-commons/src/qase/commons/models/suite.py b/qase-python-commons/src/qase/commons/models/suite.py deleted file mode 100644 index 8d82c1e8..00000000 --- a/qase-python-commons/src/qase/commons/models/suite.py +++ /dev/null @@ -1,13 +0,0 @@ -import uuid - -from typing import List, Optional - -from .basemodel import BaseModel - - -class Suite(BaseModel): - def __init__(self, title: str, description: Optional[str] = None, parent_id: Optional[str] = None): - self.title = title - self.description = description - self.parent_id = parent_id - self.id = str(uuid.uuid4()) diff --git a/qase-python-commons/src/qase/commons/reporters/report.py b/qase-python-commons/src/qase/commons/reporters/report.py index ee485c1a..db5cb179 100644 --- a/qase-python-commons/src/qase/commons/reporters/report.py +++ b/qase-python-commons/src/qase/commons/reporters/report.py @@ -68,13 +68,19 @@ def _persist_attachment(self, attachment: Attachment): mode = "w" if isinstance(attachment.content, bytes): mode = "wb" - with open(f"{self.report_path}/attachments/{attachment.id}-{attachment.file_name}", mode) as f: + + file_path = f"{self.report_path}/attachments/{attachment.id}-{attachment.file_name}" + with open(file_path, mode) as f: f.write(attachment.content) # Clear content to save memory and avoid double writing attachment.content = None + attachment.file_path = file_path + elif attachment.file_path: + file_path = f"{self.report_path}/attachments/{attachment.id}-{attachment.file_name}" shutil.copy2(os.path.abspath(attachment.file_path), f"{self.report_path}/attachments/{attachment.id}-{attachment.file_name}") + attachment.file_path = file_path def _persist_attachments_in_steps(self, steps: list): for step in steps: