generated from RedHatQE/python-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 2
base PR for set polarion as automated #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5e7a062
Revert "Revert "base PR for set polarion as automated (#30)" (#34)"
dbasunag bf0b2c2
Update apps/polarion/polarion_set_automated.py
dbasunag 83893aa
updates to review comments
dbasunag fcdae02
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 21dceb6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fcc3c3a
use typing
dbasunag 6365f54
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 21bee83
Merge branch 'revert-34-revert-30-approve' of github.com:RedHatQE/pyt…
dbasunag 6689a01
Merge branch 'main' into revert-34-revert-30-approve
dbasunag cec03b7
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 790946c
Merge branch 'main' of github.com:RedHatQE/python-utility-scripts int…
dbasunag 967dd6d
coverage report percentage change
dbasunag e634d52
Merge branch 'revert-34-revert-30-approve' of github.com:RedHatQE/pyt…
dbasunag 806e080
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 39e5257
updates based on review comments
dbasunag 733bd39
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 1b944d7
Merge branch 'main' into revert-34-revert-30-approve
dbasunag 88bcf60
Merge branch 'main' into revert-34-revert-30-approve
dbasunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class PolarionTestCaseApprovalError(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class PolarionTestCaseWithoutRequirementError(Exception): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from __future__ import annotations | ||
| import logging | ||
| import os | ||
| from simple_logger.logger import get_logger | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
| LOGGER = get_logger(name=__name__) | ||
|
|
||
|
|
||
| def approve_tests(polarion_project_id: str, added_ids: List[str]) -> Dict[str, List[str]]: | ||
| LOGGER.debug(f"Following polarion ids were added: {added_ids}") | ||
| return update_polarion_ids( | ||
| polarion_ids=list(added_ids), project_id=polarion_project_id, is_automated=True, is_approved=True | ||
| ) | ||
|
|
||
|
|
||
| def remove_approved_tests(polarion_project_id: str, added_ids: Optional[List[str]] = None) -> Dict[str, List[str]]: | ||
| removed_polarions = {} | ||
| added_ids = added_ids or [] | ||
| if removed_ids := set(find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="removed")) - set( | ||
| added_ids | ||
| ): | ||
| LOGGER.info(f"Following polarion ids were removed: {removed_ids}") | ||
| removed_polarions = update_polarion_ids( | ||
| polarion_ids=list(removed_ids), project_id=polarion_project_id, is_automated=False | ||
| ) | ||
| LOGGER.error(f"Following polarion ids marked not automated: {removed_polarions.get('updated')}") | ||
| return removed_polarions | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option( | ||
| "--config-file-path", | ||
| help="Provide absolute path to the config file. Any CLI option(s) would override YAML file", | ||
| type=click.Path(), | ||
| default=os.path.expanduser("~/.config/python-utility-scripts/config.yaml"), | ||
| ) | ||
| @click.option("--project-id", "-p", help="Provide the polarion project id") | ||
| @click.option("--verbose", default=False, is_flag=True) | ||
| def polarion_approve_automate(config_file_path: str, project_id: str, verbose: bool) -> None: | ||
| if verbose: | ||
| LOGGER.setLevel(logging.INFO) | ||
| else: | ||
| logging.disable(logging.ERROR) | ||
| 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"): | ||
| 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')}") | ||
|
|
||
| removed_polarions = remove_approved_tests(polarion_project_id=polarion_project_id, added_ids=added_ids) | ||
| if removed_polarions.get("failed") or added_polarions.get("failed"): | ||
| error = "Following polarion ids updates failed." | ||
| if removed_polarions.get("failed"): | ||
| error += f" Removed ids: {removed_polarions.get('failed')}." | ||
| if added_polarions.get("failed"): | ||
| error += f" Added ids:: {added_polarions.get('failed')}." | ||
| LOGGER.error(error) | ||
| raise PolarionTestCaseApprovalError(error) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| polarion_approve_automate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import shlex | ||
| import subprocess | ||
| from pyhelper_utils.shell import run_command | ||
|
|
||
| BASE_COMMAND = "poetry run python apps/polarion/polarion_set_automated.py --verbose" | ||
|
|
||
|
|
||
| def test_missing_project_id_set_automated(): | ||
| rc, _, err = run_command( | ||
| command=shlex.split(BASE_COMMAND), | ||
| verify_stderr=False, | ||
| check=False, | ||
| capture_output=False, | ||
| stderr=subprocess.PIPE, | ||
| ) | ||
| assert "Polarion project id must be passed via config file or command line" in err | ||
| assert not rc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.