Skip to content

Commit

Permalink
Add test for zip report export (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Brugarolas <abrugaro@redhat.com>
  • Loading branch information
abrugaro authored May 17, 2023
1 parent 98c8b14 commit c24b8cc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
28 changes: 28 additions & 0 deletions tests/test_advanced_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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}
)
21 changes: 19 additions & 2 deletions utils/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit c24b8cc

Please sign in to comment.