Skip to content

Commit

Permalink
refactor into smoke_test_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelbaker-cisa committed Jul 10, 2024
1 parent 3097a6c commit 2f65e1b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 94 deletions.
109 changes: 15 additions & 94 deletions Testing/Functional/SmokeTests/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,117 +7,38 @@
import subprocess
import os

from smoke_test_utils import verify_all_outputs_exist, verify_output_type

"""
Test virtualenv setup, activation
Test installing dependencies for running scuba.py script
Test installing dependencies for running scubagoggles directly
"""
"""

class SmokeTest:
def test_venv_creation(self):
result = subprocess.run(["dir", ".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"

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 "
# result = subprocess.run(command, shell=True)
# print(result.stdout)
# print(result.stderr)


def test_cli(self, subjectemail):
command = f"scubagoggles gws --subjectemail {subjectemail} --quiet -b commoncontrols"
result = subprocess.run(command)

if result.returncode != 0:
raise AssertionError(f"Expected 0, but got {result.returncode}")
def test_scubagoggles(self, subjectemail):
command = f"scubagoggles gws --subjectemail {subjectemail} --quiet"
subprocess.run(command)

cwd = os.getcwd()
print(cwd)
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])
individual_reports_path = f"{output_path}/IndividualReports"
print(individual_reports_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)
#assert "ProviderSettingsExport.json" in entries and os.path.isfile(f"{output_path}/ProviderSettingsExport.json")
#assert "TestResults.json" in entries and os.path.isfile(f"{output_path}/TestResults.json")
#
#assert "CalendarReport.html" in os.listdir(individual_reports_path)
#assert "ChatReport.html" in os.listdir(individual_reports_path)
#assert "ClassroomReport.html" in os.listdir(individual_reports_path)
#assert "CommoncontrolsReport.html" in os.listdir(individual_reports_path)
#assert "DriveReport.html" in os.listdir(individual_reports_path)
#assert "GmailReport.html" in os.listdir(individual_reports_path)
#assert "GroupsReport.html" in os.listdir(individual_reports_path)
#assert "MeetReport.html" in os.listdir(individual_reports_path)
#assert "RulesReport.html" in os.listdir(individual_reports_path)
#assert "SitesReport.html" in os.listdir(individual_reports_path)




Expand Down
53 changes: 53 additions & 0 deletions Testing/Functional/SmokeTests/smoke_test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os

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:
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}"

def verify_output_type(output_path, contents):
try:
entries = os.listdir(output_path)
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}"
2 changes: 2 additions & 0 deletions Testing/Functional/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
python_classes = *Test

0 comments on commit 2f65e1b

Please sign in to comment.