diff --git a/tests/test_advanced_options.py b/tests/test_advanced_options.py index da74777..e3ce427 100644 --- a/tests/test_advanced_options.py +++ b/tests/test_advanced_options.py @@ -7,6 +7,7 @@ from utils.command import build_command from utils.report import assert_story_points_from_report_file from utils.report import assert_valid_csv +from zipfile import ZipFile def test_skip_report(analysis_data): @@ -155,3 +156,30 @@ def test_skip_source_code_reports(analysis_data): assert os.path.exists(report_path + '/api') is True assert os.path.exists(report_path + '/api/files') is False + + +def test_export_zip_report(analysis_data): + application_data = analysis_data['jee_example_app'] + report_path = os.getenv('REPORT_OUTPUT_PATH') + zip_report_path = os.path.join(report_path, 'reports.zip') + unzipped_report_path = os.path.join(report_path, 'unzippedReport') + + command = build_command( + application_data['file_name'], + application_data['source'], + application_data['target'], + **{'exportZipReport': ''} + ) + output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout + + assert 'Report created' in output + + assert os.path.exists(zip_report_path) is True + + with ZipFile(zip_report_path, 'r') as zip_file: + zip_file.extractall(unzipped_report_path) + + assert_story_points_from_report_file( + application_data['story_points'], + **{'report_path': unzipped_report_path} + ) diff --git a/utils/report.py b/utils/report.py index 1ba674a..99cb7b4 100644 --- a/utils/report.py +++ b/utils/report.py @@ -5,8 +5,25 @@ from bs4 import BeautifulSoup -def assert_story_points_from_report_file(story_points): +def assert_story_points_from_report_file(story_points, **kwargs): + """ + Asserts that the story points in the report file match the provided value. + + Args: + story_points (int): The expected story points value to match. + **kwargs: Optional keyword arguments. + report_path (str): The path to the report file. If not provided, + the function will use the value of the 'REPORT_OUTPUT_PATH' environment variable. + + Raises: + AssertionError: If the story points in the report file do not match the provided value. + + Returns: + None. + + """ report_path = os.getenv('REPORT_OUTPUT_PATH') + report_path = kwargs.get('report_path', report_path) with open(report_path + "/api/applications.json") as file: json_data = json.load(file) @@ -21,7 +38,7 @@ def assert_valid_csv(csv_file_path, **kwargs): Args: csv_file_path (str): The file path of the CSV file to validate. - **kwargs (str): Optional keyword arguments. + **kwargs: Optional keyword arguments. delimiter (str): The delimiter used in the CSV file. Defaults to ','. Raises: