mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-18 20:58:06 +00:00
initial public release
This commit is contained in:
36
src/api-service/tests/test_report_parse.py
Executable file
36
src/api-service/tests/test_report_parse.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from onefuzztypes.models import Report
|
||||
|
||||
from __app__.onefuzzlib.reports import parse_report
|
||||
|
||||
|
||||
class TestReportParse(unittest.TestCase):
|
||||
def test_sample(self) -> None:
|
||||
report_path = Path(__file__).parent / "data" / "report.json"
|
||||
with open(report_path, "r") as handle:
|
||||
data = json.load(handle)
|
||||
|
||||
invalid = {"unused_field_1": 3}
|
||||
report = parse_report(json.dumps(data))
|
||||
self.assertIsInstance(report, Report)
|
||||
|
||||
with self.assertLogs(level="ERROR"):
|
||||
self.assertIsNone(parse_report('"invalid"'))
|
||||
|
||||
with self.assertLogs(level="WARNING") as logs:
|
||||
self.assertIsNone(parse_report(json.dumps(invalid)))
|
||||
|
||||
self.assertTrue(any(["unable to parse report" in x for x in logs.output]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Reference in New Issue
Block a user