Skip to content

Commit

Permalink
Merge pull request #89 from saritasa-nest/feature/update-qaseio-client
Browse files Browse the repository at this point in the history
Replace `qaseio` client to `qase-api-client`
  • Loading branch information
M1troll authored Jan 8, 2025
2 parents 19d182a + 2efdd2e commit 6057b8d
Show file tree
Hide file tree
Showing 8 changed files with 410 additions and 353 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -22,12 +22,12 @@ repos:

# Typo search tool
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.3.0
rev: v8.17.0
hooks:
- id: cspell

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
rev: v0.8.6
hooks:
- id: ruff
args: [ --fix ]
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

We follow [Semantic Versions](https://semver.org/).

# Version 2.2.0
- Replace `qaseio` to `qase-api-client` because first one was [deprecated](https://github.com/qase-tms/qase-python#deprecated)

# Version 2.1.2
- Update `DebugInfo.generate_debug_comment`: set default values for `screenshot_url`
and `html_url`
Expand Down
665 changes: 355 additions & 310 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pytest-qaseio"
description = "Pytest plugin for Qase.io integration"
version = "2.1.2"
version = "2.2.0"
license = "MIT"

authors = [
Expand Down Expand Up @@ -37,11 +37,11 @@ pytest_qaseio = "pytest_qaseio.plugin"

[tool.poetry.dependencies]
python = "^3.11"
qaseio = "^4.0.0"
selenium = "^4.21.0"
arrow = "^1.2.3"
filelock = "^3.14.0"
pytest = ">=7.2.2,<9.0.0"
qase-api-client = "^1.1.1"

[tool.poetry.group.dev.dependencies]
# Improved REPL
Expand Down
42 changes: 24 additions & 18 deletions pytest_qaseio/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
import sys
from typing import cast

import qaseio
from qaseio import configuration as qaseio_config
from qaseio import models
from qase.api_client_v1 import configuration as qaseio_config
from qase.api_client_v1.api.cases_api import CasesApi
from qase.api_client_v1.api.results_api import ResultsApi
from qase.api_client_v1.api.runs_api import RunsApi
from qase.api_client_v1.api_client import ApiClient
from qase.api_client_v1.models.id_response_all_of_result import IdResponseAllOfResult
from qase.api_client_v1.models.result_create import ResultCreate
from qase.api_client_v1.models.run import Run
from qase.api_client_v1.models.run_create import RunCreate


class QaseClient:
Expand All @@ -21,7 +27,7 @@ def __init__(
self._logger.addHandler(
logging.StreamHandler(sys.stderr),
)
self._client = qaseio.ApiClient(
self._client = ApiClient(
configuration=qaseio_config.Configuration(
api_key={
"TokenAuth": token,
Expand All @@ -33,23 +39,23 @@ def __init__(
def get_run(
self,
run_id: int,
) -> models.Run:
run_response = qaseio.RunsApi(self._client).get_run(
) -> Run:
run_response = RunsApi(self._client).get_run(
code=self._project_code,
id=run_id,
)
return cast(models.Run, run_response.result)
return cast(Run, run_response.result)

def create_run(
self,
run_data: models.RunCreate,
) -> models.Run:
run_data: RunCreate,
) -> Run:
"""Create test run in Qase."""
response = qaseio.RunsApi(self._client).create_run(
response = RunsApi(self._client).create_run(
code=self._project_code,
run_create=run_data,
)
created_run = cast(models.IdResponseAllOfResult, response.result)
created_run = cast(IdResponseAllOfResult, response.result)

return self.get_run(cast(int, created_run.id))

Expand All @@ -59,13 +65,13 @@ def load_cases_ids(
"""Load all cases ids of project."""
limit = 100
cases: list[int] = []
response = qaseio.CasesApi(self._client).get_cases(
response = CasesApi(self._client).get_cases(
code=self._project_code,
limit=limit,
offset=len(cases),
)
while True:
response = qaseio.CasesApi(self._client).get_cases(
response = CasesApi(self._client).get_cases(
code=self._project_code,
limit=limit,
offset=len(cases),
Expand All @@ -79,12 +85,12 @@ def load_cases_ids(

def report_test_results(
self,
run: models.Run,
report_data: models.ResultCreate,
) -> tuple[str, models.ResultCreate]:
run: Run,
report_data: ResultCreate,
) -> tuple[str, ResultCreate]:
"""Report test results back to Qase."""
result = (
qaseio.ResultsApi(self._client)
ResultsApi(self._client)
.create_result(
code=self._project_code,
id=cast(int, run.id),
Expand All @@ -93,4 +99,4 @@ def report_test_results(
.result
)
assert result
return cast(str, result.hash), cast(models.ResultCreate, report_data.status)
return cast(str, result.hash), cast(ResultCreate, report_data.status)
21 changes: 11 additions & 10 deletions pytest_qaseio/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import sys

import pytest
from qaseio import models
from qase.api_client_v1.models.result_create import ResultCreate
from qase.api_client_v1.models.run_create import RunCreate

from . import constants, debug_info, plugin_exceptions, storage

Expand Down Expand Up @@ -34,7 +35,7 @@ def prepare_run_data(
self,
cases_ids_from_api: list[int],
items: list[pytest.Function],
) -> tuple[models.RunCreate, dict[str, int | None]]:
) -> tuple[RunCreate, dict[str, int | None]]:
"""Prepare data needed to create test run."""
cases, tests = self._prepare_cases_for_run(
cases_ids_from_api=cases_ids_from_api,
Expand All @@ -45,7 +46,7 @@ def prepare_run_data(
browser=self._browser.capitalize(),
date=datetime.datetime.now(tz=datetime.UTC).strftime("%m/%d/%Y %H:%M:%S"),
)
run_data = models.RunCreate(
run_data = RunCreate(
title=title,
cases=cases,
)
Expand All @@ -58,7 +59,7 @@ def prepare_report_data(
run_id: int,
item: pytest.Function,
report: pytest.TestReport,
) -> models.ResultCreate:
) -> ResultCreate:
"""Create a test result based on results from pytest."""
if hasattr(report, "wasxfail"):
return self._prepare_skipped_test_report(
Expand Down Expand Up @@ -89,9 +90,9 @@ def _prepare_passed_test_report(
self,
case_id: int,
report: pytest.TestReport,
) -> models.ResultCreate:
) -> ResultCreate:
"""Prepare result report for passed test."""
return models.ResultCreate(
return ResultCreate(
case_id=case_id,
status="passed",
comment=constants.TEST_PASSED,
Expand All @@ -102,13 +103,13 @@ def _prepare_skipped_test_report(
self,
case_id: int,
report: pytest.TestReport,
) -> models.ResultCreate:
) -> ResultCreate:
"""Prepare result report for skipped test."""
if hasattr(report, "wasxfail"):
skip_reason = report.wasxfail
else:
*_, skip_reason = report.longrepr # type: ignore
return models.ResultCreate(
return ResultCreate(
case_id=case_id,
status="skipped",
comment=skip_reason,
Expand All @@ -121,7 +122,7 @@ def _prepare_failed_test_report(
run_id: int,
item: pytest.Function,
report: pytest.TestReport,
) -> models.ResultCreate:
) -> ResultCreate:
"""Prepare result report for failed test."""
comment = constants.TEST_FAILED.format(when=report.when)
debug_information = (
Expand All @@ -145,7 +146,7 @@ def _prepare_failed_test_report(
)
comment += f"\n{debug_comment}"

return models.ResultCreate(
return ResultCreate(
case_id=case_id,
status="failed",
comment=comment,
Expand Down
13 changes: 7 additions & 6 deletions pytest_qaseio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import filelock
import pytest
from _pytest.terminal import TerminalReporter
from qaseio import models
from qaseio.exceptions import ApiException
from qase.api_client_v1.exceptions import ApiException
from qase.api_client_v1.models.result_create import ResultCreate
from qase.api_client_v1.models.run import Run

from . import api_client, converter, plugin_exceptions, storage

Expand Down Expand Up @@ -117,7 +118,7 @@ def __init__(
project_code=os.environ["QASE_PROJECT_CODE"],
)
self._cases_ids_from_api: list[int] = self._client.load_cases_ids()
self._current_run: models.Run | None = None
self._current_run: Run | None = None
self._converter = converter.QaseConverter(
browser=browser,
env=os.environ["ENVIRONMENT"],
Expand All @@ -128,7 +129,7 @@ def __init__(
# Mapping of pytest items ids and case id
self._tests: dict[str, int | None] = dict()
# Mapping of case ids and result hash from qase with status
self._qase_results: dict[str, tuple[str, models.ResultCreate]] = dict()
self._qase_results: dict[str, tuple[str, ResultCreate]] = dict()

def pytest_sessionstart(self, session: pytest.Session) -> None:
"""Clear previously saved run, prepare lock file."""
Expand Down Expand Up @@ -198,7 +199,7 @@ def pytest_runtest_makereport(self, item: pytest.Function): # noqa: ANN201
case_id = self._tests[item.nodeid]
# No need to report same passed status,
# while skipped and failed should be always reported
if not case_id or item.nodeid in self._qase_results and report.passed:
if not case_id or (item.nodeid in self._qase_results and report.passed):
return
if not self._current_run:
raise plugin_exceptions.RunNotConfigured()
Expand Down Expand Up @@ -230,7 +231,7 @@ def pytest_runtest_makereport(self, item: pytest.Function): # noqa: ANN201

def _load_run_from_file(
self,
) -> models.Run | None:
) -> Run | None:
"""Load run id and then load it from qase."""
if not self.__run_file.exists():
return None
Expand Down
9 changes: 5 additions & 4 deletions pytest_qaseio/storage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import io
from typing import Protocol, cast

import qaseio
from qaseio import configuration as qaseio_config
from qase.api_client_v1 import configuration as qaseio_config
from qase.api_client_v1.api.attachments_api import AttachmentsApi
from qase.api_client_v1.api_client import ApiClient


class FileStorage(Protocol):
Expand Down Expand Up @@ -37,7 +38,7 @@ def __init__(
qase_project_code: str,
):
"""Prepare ApiClient for qase io using credentials."""
self._client = qaseio.ApiClient(
self._client = ApiClient(
configuration=qaseio_config.Configuration(
api_key={
"TokenAuth": qase_token,
Expand All @@ -51,7 +52,7 @@ def save_file_obj(self, content: bytes, filename: str) -> str:
file_obj = FileIO(content, filename=filename)

attachment_response_result = (
qaseio.AttachmentsApi(
AttachmentsApi(
self._client,
)
.upload_attachment(
Expand Down

0 comments on commit 6057b8d

Please sign in to comment.