Skip to content

Commit

Permalink
feature : updated the file reporter and support new API v2 client
Browse files Browse the repository at this point in the history
  • Loading branch information
gibiw committed Oct 29, 2024
1 parent eec33e3 commit 3ddb7e6
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 50 deletions.
6 changes: 6 additions & 0 deletions qase-python-commons/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [email protected]

## What's new

Updated the `file` reporter and support new API v2 client

# [email protected]

## What's new
Expand Down
4 changes: 2 additions & 2 deletions qase-python-commons/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"}]
Expand All @@ -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"
]

Expand Down
10 changes: 8 additions & 2 deletions qase-python-commons/src/qase/commons/client/api_v1_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 8 additions & 6 deletions qase-python-commons/src/qase/commons/client/api_v2_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions qase-python-commons/src/qase/commons/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +9,6 @@
Result,
Run,
Attachment,
Suite,
Relation,
Step,
Runtime,
Expand Down
22 changes: 16 additions & 6 deletions qase-python-commons/src/qase/commons/models/relation.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 3 additions & 18 deletions qase-python-commons/src/qase/commons/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
13 changes: 0 additions & 13 deletions qase-python-commons/src/qase/commons/models/suite.py

This file was deleted.

8 changes: 7 additions & 1 deletion qase-python-commons/src/qase/commons/reporters/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3ddb7e6

Please sign in to comment.