Skip to content

Commit

Permalink
Merge pull request #29 from nachandr/parametrize_insights_test
Browse files Browse the repository at this point in the history
[RFR] Generate Insights by analyzing app with source-only mode
  • Loading branch information
sshveta authored Sep 17, 2024
2 parents ca70ca4 + 20683fb commit 318c86b
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions tests/test_insights.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
import pytest

from utils import constants
from utils.command import build_analysis_command
Expand All @@ -8,40 +9,52 @@
# Polarion TC 598
def test_insights_binary_app(analysis_data):
application_data = analysis_data['jee_example_app']

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
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()

# Polarion TC 3504, 3505, 3506
def test_custom_rules(analysis_data):
# Polarion TC 3503, 3504, 3505, 3506
@pytest.mark.parametrize('analysis_mode', ["source-only", "full"])
def test_custom_rules(analysis_data, analysis_mode):
application_data = analysis_data['tackle-testapp-project']
custom_rule_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/yaml', 'custom_rule_insights.yaml')

command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'rules': custom_rule_path}
)

output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout
custom_rule_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/yaml',
'custom_rule_insights.yaml')

if analysis_mode == 'source-only':
command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'rules': custom_rule_path},
**{'mode': 'source-only'},
)
else:
command = build_analysis_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'rules': custom_rule_path}
)
output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE,
encoding='utf-8').stdout
assert 'generating static report' in output

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

for insight in insights.values():
if rule['name'] == 'custom-ruleset':
if insight['description'] in ('Properties file (Insights TC0)', 'Properties file (Insights TC1)',
'Properties file (Insights TC2)'):
if insight['description'] in ('Properties file (Insights TC0)',
'Properties file (Insights TC1)', 'Properties file (Insights TC2)'):
# Assert insight occurrence is > 0 for each insight
assert len(insight['incidents']) > 0, "No insights were generated"

0 comments on commit 318c86b

Please sign in to comment.