|
| 1 | +import orjson |
| 2 | +import pytest |
| 3 | +from shared.reports.resources import Report |
| 4 | +from shared.utils.sessions import Session |
| 5 | + |
| 6 | +from services.report import raw_upload_processor as process |
| 7 | +from services.report.parser.legacy import LegacyReportParser |
| 8 | + |
| 9 | +# The intention of these tests is to easily reproduce production problems with real reports. |
| 10 | +# |
| 11 | +# In order to run them, comment out the `skip` annotation. |
| 12 | +# |
| 13 | +# For both tests, download the raw upload, or the `report_json`/`chunks` from storage, |
| 14 | +# and paste in the filename before running the test directly. |
| 15 | +# |
| 16 | +# As these tests do not depend on any external service, you can run them directly with: |
| 17 | +# > pytest -vvs "tests/test_debug.py::test_process_upload" |
| 18 | +# |
| 19 | +# Then either hook up an interactive debugger, or do "print-debugging" to your liking. |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.skip(reason="this is supposed to be invoked manually") |
| 23 | +def test_process_upload(): |
| 24 | + upload_file = "..." |
| 25 | + with open(upload_file, "rb") as d: |
| 26 | + contents = d.read() |
| 27 | + |
| 28 | + parsed_upload = LegacyReportParser().parse_raw_report_from_bytes(contents) |
| 29 | + report = process.process_raw_upload(None, parsed_upload, Session()) |
| 30 | + |
| 31 | + file = report.get("interesting_file") |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.skip(reason="this is supposed to be invoked manually") |
| 35 | +def test_inspect_report(): |
| 36 | + report_json_file = "..." |
| 37 | + chunks_file = "..." |
| 38 | + with open(report_json_file, "rb") as d: |
| 39 | + report_json = d.read() |
| 40 | + with open(chunks_file, "rb") as d: |
| 41 | + chunks = d.read() |
| 42 | + |
| 43 | + report_json = orjson.loads(report_json) |
| 44 | + report = Report.from_chunks( |
| 45 | + chunks=chunks, |
| 46 | + files=report_json["files"], |
| 47 | + sessions=report_json["sessions"], |
| 48 | + totals=report_json.get("totals"), |
| 49 | + ) |
| 50 | + |
| 51 | + file = report.get("interesting_file") |
0 commit comments