Skip to content

Commit

Permalink
refactor try/catch handlers into smoke test methods; remove ProviderS…
Browse files Browse the repository at this point in the history
…ettingsExport and switch to ScubaResults.json
  • Loading branch information
mitchelbaker-cisa committed Jul 26, 2024
1 parent 694b7da commit ab06197
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 55 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/run_smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,18 @@ jobs:
python -m venv .venv
.venv\Scripts\activate
- name: Install dependencies
- name: Install project dependencies and OPA
run: |
python -m pip install .
pip install -r requirements.txt
pip install pytest
pip uninstall numpy
pip install numpy==1.26.4
- name: Create credentials.json for service account
run: Set-Content -Path credentials.json -Value $env:GWS_GITHUB_AUTOMATION_CREDS

- name: Download OPA executable
run: python download_opa.py -v 0.60.0 -os windows
python download_opa.py -v 0.60.0 -os windows
- name: Execute ScubaGoggles and check for correct output
run: |
echo "In step to execute ScubaGoggles smoke test"
pip show scubagoggles
# Setup credentials for service account
Set-Content -Path credentials.json -Value $env:GWS_GITHUB_AUTOMATION_CREDS
pytest -s ./Testing/Functional/SmokeTests/ --subjectemail="$env:GWS_SUBJECT_EMAIL"
45 changes: 25 additions & 20 deletions Testing/Functional/SmokeTests/smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
run_smoke_test.py is a test script to verify `scubagoggles gws`
outputs (i.e., files) are generated.
smoke_test.py is a test script to verify `scubagoggles gws`
generates the correct outputs (i.e., directories, files).
"""

import pytest
Expand All @@ -11,27 +11,32 @@

class SmokeTest:
def test_venv_creation(self):
result = subprocess.run(["ls", ".venv"], shell=True, capture_output=True, text=True)
if "Scripts" in result.stdout:
assert True
else:
assert False, f"Scripts was not found in the virtual environment"
try:
result = subprocess.run(["ls", ".venv"], shell=True, capture_output=True, text=True)
if "Scripts" in result.stdout:
assert True
else:
assert False, f"Scripts was not found in the virtual environment"
except Exception as e:
pytest.fail(f"An error occurred, {e}")


def test_scubagoggles(self, subjectemail):
command = f"scubagoggles gws --subjectemail {subjectemail} --quiet"
subprocess.run(command, shell=True)

prefix = "GWSBaselineConformance"
directories = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)]
directories.sort(key=lambda d: os.path.getctime(d), reverse=True)
print(directories)

cwd = os.getcwd()
output_path = os.path.join(cwd, directories[0])
print(cwd, directories[0])
contents = verify_output_type(output_path, [])
verify_all_outputs_exist(contents)
try:
command = f"scubagoggles gws --subjectemail {subjectemail} --quiet"
subprocess.run(command, shell=True)

prefix = "GWSBaselineConformance"
directories = [d for d in os.listdir() if os.path.isdir(d) and d.startswith(prefix)]
directories.sort(key=lambda d: os.path.getctime(d), reverse=True)

cwd = os.getcwd()
output_path = os.path.join(cwd, directories[0])
contents = verify_output_type(output_path, [])
print(contents)
verify_all_outputs_exist(contents)
except Exception as e:
pytest.fail(f"An error occurred, {e}")



Expand Down
47 changes: 20 additions & 27 deletions Testing/Functional/SmokeTests/smoke_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
required_contents = [
"BaselineReports.html",
"IndividualReports",
"ProviderSettingsExport.json",
"ScubaResults.json",
"TestResults.json",
"images",
"CalendarReport.html",
Expand All @@ -21,33 +21,26 @@
]

def verify_all_outputs_exist(contents):
try:
for required_content in required_contents:
if required_content in contents:
assert True
else:
assert False, f"{required_content} was not found in the generated report"
except Exception as e:
assert False, f"An error occurred, {e}"
for required_content in required_contents:
if required_content in contents:
assert True
else:
assert False, f"{required_content} was not found in the generated report"

def verify_output_type(output_path, contents):
try:
entries = os.listdir(output_path)
for entry in entries:
contents.append(entry)
entries = os.listdir(output_path)

# Check if entry is a valid directory or file
child_path = os.path.join(output_path, entry)
if os.path.isdir(child_path):
assert True
verify_output_type(child_path, contents)
elif os.path.isfile(child_path):
assert True
else:
assert False, f"Entry is not a directory or file (symlink, etc.)"
for entry in entries:
contents.append(entry)

return contents
except FileNotFoundError:
assert False, f"The directory {output_path} does not exist"
except Exception as e:
assert False, f"An error occurred, {e}"
# Check if entry is a valid directory or file
child_path = os.path.join(output_path, entry)
if os.path.isdir(child_path):
assert True
verify_output_type(child_path, contents)
elif os.path.isfile(child_path):
assert True
else:
assert False, f"Entry is not a directory or file (symlink, etc.)"

return contents

0 comments on commit ab06197

Please sign in to comment.