Skip to content

Commit

Permalink
Update libs
Browse files Browse the repository at this point in the history
- qaseio (latest spec)
- qase-python-common: send results using the new  format and endpoints
  • Loading branch information
pyscht committed Aug 3, 2023
1 parent 34da50a commit fe1907b
Show file tree
Hide file tree
Showing 85 changed files with 6,473 additions and 71 deletions.
2 changes: 2 additions & 0 deletions qase-python-commons/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ __pycache__/*
.*.swp
*/.ipynb_checkpoints/*
.DS_Store
*.iml

# Project files
.ropeproject
Expand Down Expand Up @@ -48,3 +49,4 @@ MANIFEST

# Per-project virtualenvs
.venv*/
/build/
2 changes: 1 addition & 1 deletion qase-python-commons/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
attrs==21.4.0
cattrs==1.1.2
certifi==2022.12.7
qaseio==3.2.1
qaseio==3.3.0
more-itertools==9.1.0
5 changes: 2 additions & 3 deletions qase-python-commons/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ author-email = [email protected]
license = apache
long-description = file: README.md
long-description-content-type = text/markdown; charset=UTF-8; variant=GFM
url = https://github.com/qase-tms/qase-python/tree/master/qase-python-commons
platforms = any
version = 2.0.2
version = 2.1.0
classifiers =
Development Status :: 5 - Production/Stable
Programming Language :: Python
Expand All @@ -24,7 +23,7 @@ package_dir =
setup_requires = pyscaffold>=3.2a0,<3.3a0
install_requires =
certifi>=2022.12.7
qaseio>=3.2.1
qaseio>=3.3.0
attrs>=19.3.0
more_itertools
python_requires = >=3.7
Expand Down
4 changes: 3 additions & 1 deletion qase-python-commons/src/qaseio/commons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from qaseio.commons.testops import QaseTestOps
from qaseio.commons.testopsv2 import QaseTestOpsV2
from qaseio.commons.report import QaseReport
from qaseio.commons.utils import QaseUtils
from qaseio.commons.interceptor import Interceptor
Expand All @@ -7,9 +8,10 @@

__all__ = [
QaseTestOps,
QaseTestOpsV2,
QaseReport,
QaseUtils,
Interceptor,
ConfigManager,
TestOpsPlanLoader,
]
]
114 changes: 114 additions & 0 deletions qase-python-commons/src/qaseio/commons/testopsv2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import json

from qaseio.api_client import ApiClient
from qaseio.api.result_api import ResultApi
from qaseio.configuration import Configuration
from qaseio.model.create_results_request_v2 import CreateResultsRequestV2
from qaseio.model.create_results_request_v2_results_inner import CreateResultsRequestV2ResultsInner
from qaseio.model.result_execution import ResultExecution
from qaseio.model.result_attachment import ResultAttachment
from qaseio.model.result_step import ResultStep
from qaseio.model.result_relations import ResultRelations
from qaseio.commons.testops import QaseTestOps

import more_itertools
import certifi

from pkg_resources import DistributionNotFound, get_distribution


def package_version(name):
try:
version = get_distribution(name).version
except DistributionNotFound:
version = "unknown"
return version


class TestOpsRunNotFoundException(Exception):
pass


class QaseTestOpsV2(QaseTestOps):

def __init__(self,
api_token,
project_code,
run_id=None,
plan_id=None,
bulk=True,
run_title=None,
environment=None,
host="qase.io",
complete_run=False,
defect=False,
chunk_size=200) -> None:

configuration = Configuration()
configuration.api_key['TokenAuth'] = api_token
configuration.host = f'https://api.{host}'
configuration.ssl_ca_cert = certifi.where()

self.clientv2 = ApiClient(configuration)

super().__init__(
api_token=api_token,
project_code=project_code,
run_id=run_id,
plan_id=plan_id,
bulk=bulk,
run_title=run_title,
environment=environment,
host=host,
complete_run=complete_run,
defect=defect,
chunk_size=chunk_size
)

def _send_bulk_results(self):
def filter_dict(dct):
return {k: v for k, v in dct.items() if v}

def to_dict(obj):
return json.loads(
json.dumps(obj, default=lambda o: filter_dict(getattr(o, '__dict__', str(o))))
)

if self.enabled and self.results:
print(f"[Qase] Uploading attachments for Run ID: {self.run_id}...")
results = []
for result in self.results:
d = to_dict(result)

if 'execution' in d:
d['execution'] = ResultExecution(d['execution'])
if 'attachment' in d:
d['attachment'] = ResultAttachment(d['attachment'])
if 'step' in d:
d['step'] = ResultStep(d['step'])
if 'relations' in d:
d['relations'] = ResultRelations(d['relations'])

results.append(CreateResultsRequestV2ResultsInner(d))

api_results = ResultApi(self.clientv2)
print(f"[Qase] Sending results to test run {self.run_id}. Total results: {len(results)}. Results in a "
f"chunk: {self.chunk_size}.")

i = 1

for chunk in more_itertools.chunked(results, self.chunk_size):
try:
print(f"[Qase] Sending chunk #{i}. Chunk size: {len(chunk)}... ")
api_results.create_results_v2(
self.project_code,
self.run_id,
CreateResultsRequestV2(
results=chunk
)
)
print(f"[Qase] Chunk #{i} was sent successfully.")
i = i+1
except Exception as e:
print(f"[Qase] ⚠️ Error at sending results for run {self.run_id} (Chunk #{i}): {e}")
raise e
2 changes: 2 additions & 0 deletions qaseio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ target/

#Ipython Notebook
.ipynb_checkpoints

*.iml
Loading

0 comments on commit fe1907b

Please sign in to comment.