Skip to content

Commit

Permalink
merge(#4208): from 4208-change-test_python_flawspy-to-accept-branch-o…
Browse files Browse the repository at this point in the history
…r-commit-in-the-same-argument

Change test_python_flaws.py arguments
  • Loading branch information
Rebits authored May 29, 2023
2 parents fb45f37 + 6a00b07 commit 4877670
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

### Feature
- Change test_python_flaws.py to accept branch or commit in the same argument. ([#4209](https:/wazuh/wazuh-qa/pull/4207)) (Tests)

## [4.4.3] - 25-06-2023

Wazuh commit: https:/wazuh/wazuh/commit/f7080df56081adaeaad94529522233e2f0bbd577
Expand Down
15 changes: 7 additions & 8 deletions tests/scans/code_analysis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,38 @@ def clone_wazuh_repository(pytestconfig):
"""
# Get Wazuh repository and branch
repository_name = pytestconfig.getoption('repo')
branch = pytestconfig.getoption('branch')
commit = pytestconfig.getoption('commit')
reference = pytestconfig.getoption('reference')

# Create temporary dir
repository_path = tempfile.mkdtemp()

try:
# Clone into temporary dir
# depth=1 creates a shallow clone with a history truncated to 1 commit. Implies single_branch=True.
if not commit:
try:
Repo.clone_from(f"https:/wazuh/{repository_name}.git",
repository_path,
depth=1,
branch=branch)
else:
branch=reference)
except:
repo = Repo.clone_from(f"https:/wazuh/{repository_name}.git",
repository_path, branch='master', no_single_branch=True)

# Get all branches that contains the commit
git_local = Git(repository_path)
commit_branch = git_local.branch('-a', '--contains', commit).split('\n')
commit_branch = git_local.branch('-a', '--contains', reference).split('\n')
commit_branch_head = False

for branch in commit_branch:
# Remove * in case of branch is the master
branch_name = branch.replace('*', '').strip()
repo.git.checkout(branch_name)
# Check if the commit is the head of the branch
if(str(repo.head.commit) == commit):
if(str(repo.head.commit) == reference):
commit_branch_head = True
break
if not commit_branch_head:
raise Exception(f"{commit} was not found as any head branch")
raise Exception(f"{reference} was not found as any head branch")

yield repository_path

Expand Down
10 changes: 4 additions & 6 deletions tests/scans/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
DEFAULT_BRANCH = 'master'
DEFAULT_REFERENCE = 'master'
DEFAULT_REPOSITORY = 'wazuh'


def pytest_addoption(parser):
parser.addoption("--branch", action="store", default=DEFAULT_BRANCH,
help=f"Set the repository used. Default: {DEFAULT_REPOSITORY}")
parser.addoption("--reference", action="store", default=DEFAULT_REFERENCE,
help=f"Set the reference used. Default: {DEFAULT_REPOSITORY}")
parser.addoption("--repo", action="store", default=DEFAULT_REPOSITORY,
help=f"Set the repository branch. Default: {DEFAULT_BRANCH}")
parser.addoption("--commit", action="store", default=None,
help=f"Set the repository commit. Default: None")
help=f"Set the repository used. Default: {DEFAULT_REPOSITORY}")

0 comments on commit 4877670

Please sign in to comment.