Skip to content

Commit

Permalink
Merge pull request #23 from nachandr/kantra_insights
Browse files Browse the repository at this point in the history
[RFR] Insights test for binary application
  • Loading branch information
sshveta authored Aug 21, 2024
2 parents 0bffb9a + bf14bb3 commit ba85cb1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_insights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import subprocess

from utils import constants
from utils.command import build_analysis_command
from utils.report import assert_insights_from_report_file

# Polarion TC 598
def test_insights_binary_app(analysis_data):
application_data = analysis_data['jee_example_app']
custom_rule_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/xml', 'weblogic-custom.windup.yaml')

command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target']
)

output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout

assert 'generating static report' in output
assert_insights_from_report_file()
30 changes: 30 additions & 0 deletions utils/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,33 @@ def assert_story_points_from_report_file():
story_points += len(violation['incidents']) * violation['effort']

assert story_points >= 0, "Non valid value found in Story Points from Report: " + str(story_points)

def assert_insights_from_report_file():
"""
Asserts that the Insights occurrence count in the report file is > 0.
Args:
**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_data = get_json_from_report_output_file()

occurrences = -1
for rule in report_data['rulesets']:
insights = rule.get('insights', {})

for insight in insights.values():
if 'incidents' in insight:
if occurrences == -1:
occurrences = 0
occurrences += len(insight['incidents'])

assert occurrences >= 0, "Invalid value found for Insights occurrences in Report: " + str(occurrences)

0 comments on commit ba85cb1

Please sign in to comment.