mirror of
https://github.com/seanbetts/steam-hardware-watch.git
synced 2026-10-06 01:00:18 +02:00
Harden customs shipment edge cases
This commit is contained in:
1 parent
3cfcc8bb44
commit
4f624dc8bd
5 files changed
+162
-6
No files matched your search
@@ -197,6 +197,22 @@ class CustomsShipmentParserTests(unittest.TestCase):
|
||||
self.assertEqual("CEVA C/O VALVE CORPORATION", rows[0]["consignee"])
|
||||
self.assertEqual("GAME CONSOLE", rows[0]["commodity"])
|
||||
|
||||
def test_filters_generic_logistics_product_rows_without_valve_signal(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
html = tmp_path / "generic-logistics.html"
|
||||
html.write_text(
|
||||
IMPORTINFO_HTML.replace("CEVA C/O VALVE CORPORATION", "CEVA LOGISTICS US INC."),
|
||||
encoding="utf-8",
|
||||
)
|
||||
reports = tmp_path / "reports"
|
||||
|
||||
result = run_parser(["--input", f"tech-front-game-console={html}"], reports)
|
||||
|
||||
self.assertEqual("", result.stderr)
|
||||
self.assertEqual(0, result.returncode)
|
||||
self.assertEqual([], read_rows(reports))
|
||||
|
||||
def test_manifest_inputs_dedupe_duplicate_bols(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
@@ -299,6 +315,48 @@ class CheckCustomsShipmentsShellTests(unittest.TestCase):
|
||||
)
|
||||
self.assertIn("failed to fetch", errors)
|
||||
|
||||
def test_records_200_challenge_page_without_key_lines(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
run_dir = tmp_path / "run"
|
||||
fake_bin = tmp_path / "bin"
|
||||
fake_bin.mkdir()
|
||||
write_executable(
|
||||
fake_bin / "curl",
|
||||
"""
|
||||
#!/bin/sh
|
||||
cat <<'HTML'
|
||||
<html><body><h1>Checking your browser</h1><p>Please verify you are human.</p></body></html>
|
||||
HTML
|
||||
""",
|
||||
)
|
||||
env = os.environ.copy()
|
||||
env["PATH"] = f"{fake_bin}{os.pathsep}{env['PATH']}"
|
||||
|
||||
result = subprocess.run(
|
||||
[str(ROOT / "scripts" / "check_customs_shipments.sh"), str(run_dir)],
|
||||
cwd=ROOT,
|
||||
env=env,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
)
|
||||
|
||||
self.assertEqual("", result.stderr)
|
||||
self.assertEqual(0, result.returncode)
|
||||
errors = (run_dir / "reports" / "customs-shipments-errors.txt").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertIn("unexpected or blocked content from", errors)
|
||||
self.assertFalse(
|
||||
(run_dir / "api" / "customs" / "importinfo-ceva-valve.html").exists()
|
||||
)
|
||||
key_lines = (
|
||||
run_dir / "reports" / "customs-shipments-key-lines.txt"
|
||||
).read_text(encoding="utf-8")
|
||||
self.assertEqual("", key_lines)
|
||||
|
||||
|
||||
class CustomsSummaryIntegrationTests(unittest.TestCase):
|
||||
def test_run_summary_and_status_draft_include_customs_lines(self):
|
||||
@@ -348,6 +406,48 @@ class CustomsSummaryIntegrationTests(unittest.TestCase):
|
||||
self.assertIn("Customs / Shipments", status_draft)
|
||||
self.assertIn("GAME CONSOLE", status_draft)
|
||||
|
||||
def test_status_draft_reports_missing_customs_outputs_as_unavailable(self):
|
||||
with TemporaryDirectory() as tmp:
|
||||
run_dir = Path(tmp) / "2026-05-05"
|
||||
reports = run_dir / "reports"
|
||||
reports.mkdir(parents=True)
|
||||
|
||||
draft = subprocess.run(
|
||||
[
|
||||
"python3",
|
||||
str(ROOT / "scripts" / "draft_status_update.py"),
|
||||
"--run-dir",
|
||||
str(run_dir),
|
||||
],
|
||||
cwd=ROOT,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
)
|
||||
summary = subprocess.run(
|
||||
[
|
||||
"python3",
|
||||
str(ROOT / "scripts" / "write_run_summary.py"),
|
||||
"--run-dir",
|
||||
str(run_dir),
|
||||
],
|
||||
cwd=ROOT,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
)
|
||||
|
||||
self.assertEqual(0, draft.returncode)
|
||||
self.assertEqual(0, summary.returncode)
|
||||
status_draft = (reports / "status-draft.md").read_text(encoding="utf-8")
|
||||
run_summary = (reports / "run-summary.md").read_text(encoding="utf-8")
|
||||
self.assertIn("Customs / Shipments", status_draft)
|
||||
self.assertIn("not generated", status_draft)
|
||||
self.assertNotIn("No relevant customs shipment rows found.", status_draft)
|
||||
self.assertIn("Customs shipments status: `unavailable`", run_summary)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user