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
6 changes: 0 additions & 6 deletions apps/polarion/exceptions.py

This file was deleted.

15 changes: 8 additions & 7 deletions apps/polarion/polarion_set_automated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import logging
import os
from simple_logger.logger import get_logger

import sys
import click

from apps.polarion.exceptions import PolarionTestCaseApprovalError
from apps.polarion.polarion_utils import get_polarion_project_id, find_polarion_ids, update_polarion_ids
from typing import List, Dict, Optional

Expand Down Expand Up @@ -48,16 +47,18 @@ def remove_approved_tests(
@click.option("--verbose", default=False, is_flag=True)
def polarion_approve_automate(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None:
if verbose:
LOGGER.setLevel(logging.INFO)
else:
logging.disable(logging.ERROR)
LOGGER.setLevel(logging.DEBUG)
# since the utilities are in apps.polarion.polarion_utils, we need to change log level
# for apps.polarion.polarion_utils as well
logging.getLogger("apps.polarion.polarion_utils").setLevel(logging.DEBUG)

polarion_project_id = project_id or get_polarion_project_id(
config_file_path=config_file_path, util_name="pyutils-polarion-set-automated"
)
added_polarions = {}
if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch):
added_polarions = approve_tests(polarion_project_id=polarion_project_id, added_ids=added_ids)
LOGGER.info(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}")
LOGGER.debug(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}")

removed_polarions = remove_approved_tests(
polarion_project_id=polarion_project_id, added_ids=added_ids, branch=branch
Expand All @@ -69,7 +70,7 @@ def polarion_approve_automate(config_file_path: str, project_id: str, branch: st
if added_polarions.get("failed"):
error += f" Added ids:: {added_polarions.get('failed')}."
LOGGER.error(error)
raise PolarionTestCaseApprovalError(error)
sys.exit(1)


if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions apps/polarion/polarion_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations
import re

import click
import sys
from simple_logger.logger import get_logger
import shlex
import subprocess
Expand All @@ -23,7 +22,7 @@ def git_diff(branch: str) -> str:
def git_diff_lines(branch: str) -> Dict[str, List[str]]:
diff: Dict[str, List[str]] = {}
for line in git_diff(branch=branch).splitlines():
LOGGER.info(line)
LOGGER.debug(line)
if line.startswith("+"):
diff.setdefault("added", []).append(line)
if line.startswith("-"):
Expand All @@ -42,7 +41,7 @@ def validate_polarion_requirements(

for _id in polarion_test_ids:
has_req = False
LOGGER.info(f"Checking if {_id} verifies any requirement")
LOGGER.debug(f"Checking if {_id} verifies any requirement")
tc = TestCase(project_id=polarion_project_id, work_item_id=_id)
for link in tc.linked_work_items:
try:
Expand Down Expand Up @@ -70,7 +69,7 @@ def get_polarion_project_id(util_name: str, config_file_path: str) -> str:
polarion_project_id = get_util_config(util_name=util_name, config_file_path=config_file_path).get("project_id")
if not polarion_project_id:
LOGGER.error("Polarion project id must be passed via config file or command line")
raise click.Abort()
sys.exit(1)
return polarion_project_id


Expand All @@ -91,7 +90,7 @@ def update_polarion_ids(
if is_approved:
tc.status = APPROVED
tc.update()
LOGGER.info(f"Polarion {id}: marked as: {automation_status}, approved status set: {is_approved}")
LOGGER.debug(f"Polarion {id}: marked as: {automation_status}, approved status set: {is_approved}")
updated_ids.setdefault("updated", []).append(id)
except PyleroLibException as polarion_exception:
error = f"{id}: {polarion_exception}"
Expand Down
17 changes: 9 additions & 8 deletions apps/polarion/polarion_verify_tc_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from simple_logger.logger import get_logger
import os
import click
import sys

from apps.polarion.exceptions import PolarionTestCaseWithoutRequirementError
from apps.polarion.polarion_utils import validate_polarion_requirements, find_polarion_ids, get_polarion_project_id

LOGGER = get_logger(name="polarion-verify-tc-requirements")
Expand All @@ -21,21 +21,22 @@
@click.option("--verbose", default=False, is_flag=True)
def has_verify(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None:
if verbose:
LOGGER.setLevel(logging.INFO)
else:
logging.disable(logging.ERROR)
LOGGER.setLevel(logging.DEBUG)
# since the utilities are in apps.polarion.polarion_utils, we need to change log level
# for apps.polarion.polarion_utils as well
logging.getLogger("apps.polarion.polarion_utils").setLevel(logging.DEBUG)

polarion_project_id = project_id or get_polarion_project_id(
config_file_path=config_file_path, util_name="pyutils-polarion-verify-tc-requirements"
)
if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch):
LOGGER.info(f"Checking following ids: {added_ids}")
LOGGER.debug(f"Checking following ids: {added_ids}")
if tests_with_missing_requirements := validate_polarion_requirements(
polarion_test_ids=added_ids,
polarion_project_id=polarion_project_id,
):
raise PolarionTestCaseWithoutRequirementError(
f"TestCases with missing requirement: {tests_with_missing_requirements}"
)
LOGGER.error(f"TestCases with missing requirement: {tests_with_missing_requirements}")
sys.exit(1)


if __name__ == "__main__":
Expand Down
9 changes: 4 additions & 5 deletions apps/unused_code/unused_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
import os
import subprocess
import sys

import click
from simple_logger.logger import get_logger

Expand Down Expand Up @@ -69,10 +71,7 @@ def is_ignore_function_list(ignore_prefix_list: List[str], function: ast.Functio
def get_unused_functions(
config_file_path: Any, exclude_files: Any, exclude_function_prefixes: Any, verbose: bool
) -> Any:
if verbose:
LOGGER.setLevel(logging.DEBUG)
else:
logging.disable(logging.CRITICAL)
LOGGER.setLevel(logging.DEBUG if verbose else logging.INFO)

_unused_functions = []
unused_code_config = get_util_config(util_name="pyutils-unusedcode", config_file_path=config_file_path)
Expand Down Expand Up @@ -104,7 +103,7 @@ def get_unused_functions(
)
if _unused_functions:
click.echo("\n".join(_unused_functions))
raise click.Abort()
sys.exit(1)


if __name__ == "__main__":
Expand Down