Skip to content

Commit 171437b

Browse files
committed
Added test coverage + few fixes
1 parent 2d2a2f9 commit 171437b

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

leapp/utils/report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def generate_report_file(messages_to_report, context, path, report_schema=None):
110110
if report_schema == '1.0.0':
111111
# report-schema 1.0.0 doesn't have a stable report key
112112
# copy list of messages here not to mess the initial structure for possible further invocations
113-
messages_to_report_copy = list(messages_to_report)
114-
for m in messages_to_report_copy:
113+
messages_to_report = list(messages_to_report)
114+
for m in messages_to_report:
115115
m.pop('key')
116-
json.dump({'entries': messages_to_report_copy, 'leapp_run_id': context}, f, indent=2)
116+
json.dump({'entries': messages_to_report, 'leapp_run_id': context}, f, indent=2)

tests/scripts/test_reporting.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import json
44
import os
5+
import tempfile
56

67
import jsonschema
78
import pytest
@@ -14,6 +15,7 @@
1415
_create_report_object,
1516
Audience, Key, Title, Summary, Severity, RelatedResource
1617
)
18+
from leapp.utils.report import generate_report_file
1719

1820

1921
ReportPrimitive = namedtuple('ReportPrimitive', ['data', 'path', 'value', 'is_leaf_list'])
@@ -220,3 +222,33 @@ def _load_json(a_file):
220222
# schemas directory contain a symlink to report json-schemas
221223
schema_data = _load_json(os.path.join(reports_dir, 'schemas', schema))
222224
jsonschema.validate(report_data, schema_data)
225+
226+
227+
def test_report_backwards_compatibility():
228+
msg1 = {u'groups': [u'selinux', u'security'],
229+
u'title': u'SElinux relabeling has been scheduled',
230+
'timeStamp': u'2021-02-10T13:13:40.576437Z',
231+
'hostname': u'ivasilev-tagsflagsgroups',
232+
'actor': u'check_se_linux',
233+
u'summary': u'SElinux relabeling has been scheduled as the status was permissive/enforcing.',
234+
u'audience': u'sysadmin',
235+
u'key': u'c12a05a22be0b5bc0af3f1119898ea6d8639d9c4',
236+
'id': '29279fc2e3100cfdf8ac30f48b293185192672d5a5ae9e0cfbc76cbfc919d807',
237+
u'severity': u'info'}
238+
report = [msg1]
239+
# make sure normal mode works
240+
for report_format in ['.json', '.txt']:
241+
reportfile = tempfile.NamedTemporaryFile(suffix=report_format)
242+
generate_report_file(report, 'leapp-run-id', reportfile.name)
243+
# make sure report output conversion to specific version works as well
244+
for report_format in ['.json', '.txt']:
245+
reportfile = tempfile.NamedTemporaryFile(suffix=report_format)
246+
generate_report_file(report, 'leapp-run-id', reportfile.name, '1.0.0')
247+
with open(reportfile.name) as f:
248+
data = f.read()
249+
if report_format == '.json':
250+
a_report = json.loads(data)
251+
msg = a_report['entries'][0]
252+
assert 'key' not in msg
253+
else:
254+
assert 'Key' not in data

0 commit comments

Comments
 (0)