Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit addc8bb

Browse files
authored
Move debugging test (#1176)
1 parent d160920 commit addc8bb

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

services/report/tests/unit/test_process.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from json import loads
2-
from pathlib import Path
32
from unittest.mock import patch
43

54
import pytest
@@ -21,41 +20,8 @@
2120
from services.report.report_builder import ReportBuilder
2221
from test_utils.base import BaseTestCase
2322

24-
here = Path(__file__)
25-
folder = here.parent
26-
27-
28-
@pytest.mark.skip(reason="this is supposed to be invoked manually")
29-
def test_manual():
30-
# The intention of this test is to easily reproduce production problems with real reports.
31-
# So download the relevant report, fill in its filename below, comment out the `skip` annotation,
32-
# and run this test directly.
33-
filename = "..."
34-
with open(filename, "rb") as d:
35-
contents = d.read()
36-
37-
parsed_report = LegacyReportParser().parse_raw_report_from_bytes(contents)
38-
master = process.process_raw_upload(None, parsed_report, Session())
39-
40-
assert not master.is_empty()
41-
4223

4324
class TestProcessRawUpload(BaseTestCase):
44-
def readjson(self, filename):
45-
with open(folder / filename, "r") as d:
46-
contents = loads(d.read())
47-
return contents
48-
49-
def get_v3_report(self):
50-
filename = "report.v3.json"
51-
with open(folder / filename, "r") as d:
52-
contents = loads(d.read())
53-
return Report(**contents)
54-
55-
@property
56-
def data(self):
57-
return {"yaml": {}}
58-
5925
@pytest.mark.parametrize("keys", ["nm", "n", "m", "nme", "ne", "M"])
6026
def test_process_raw_upload(self, keys):
6127
report = []

tests/test_debug.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)