Skip to content

Commit

Permalink
add helper function to determine if all outputs exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelbaker-cisa committed Jul 9, 2024
1 parent a6640f8 commit 3097a6c
Showing 1 changed file with 58 additions and 24 deletions.
82 changes: 58 additions & 24 deletions Testing/Functional/SmokeTests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,62 @@
"""

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

# 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
except FileNotFoundError:
assert False, f"The directory {output_path} does not exist"
except Exception as e:
assert False, f"An error occurred, {e}"

required_contents = [
"BaselineReports.html",
"IndividualReports",
"ProviderSettingsExport.json",
"TestResults.json",
"images",
"CalendarReport.html",
"ChatReport.html",
"ClassroomReport.html",
"CommoncontrolsReport.html",
"DriveReport.html",
"GmailReport.html",
"GroupsReport.html",
"MeetReport.html",
"RulesReport.html",
"SitesReport.html",
"cisa_logo.png",
"triangle-exclamation-solid.svg"
]

def verify_all_outputs_exist(contents):

try:
print(contents)
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}"


class TestScuba:
#def test_venv_setup(self):
# command = f"scubagoggles gws "
Expand All @@ -42,31 +98,9 @@ def test_cli(self, subjectemail):
individual_reports_path = f"{output_path}/IndividualReports"
print(individual_reports_path)

def check_output_contents(output_path):
try:
entries = os.listdir(output_path)
print(entries)
for entry in entries:
child_path = os.path.join(output_path, entry)

# Directory case
if os.path.isdir(child_path):
assert os.path.isdir(child_path)
check_output_contents(child_path)

# File case
elif os.path.isfile(child_path):
assert os.path.isfile(child_path)

# Neither a directory or file (symlink, etc.)
else:
assert False
except FileNotFoundError:
assert False, f"The directory {output_path} does not exist"
except Exception as e:
assert False, f"An error occurred, {e}"

check_output_contents(output_path)
contents = verify_output_type(output_path, [])
verify_all_outputs_exist(contents)

#assert "BaselineReports.html" in entries and os.path.isfile(f"{output_path}/BaselineReports.html")
#assert "IndividualReports" in entries and os.path.isdir(individual_reports_path)
Expand Down

0 comments on commit 3097a6c

Please sign in to comment.