feat: expand registry ingestion and demo exchange
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 36s
CI/CD Pipeline / Build and Push Images (push) Successful in 15s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 24s

This commit is contained in:
2026-07-16 12:59:23 +02:00
parent cc5aa84556
commit 007cecc8d5
43 changed files with 3723 additions and 352 deletions

View File

@@ -332,6 +332,25 @@ class ProverkiDownloadParseTest(SimpleTestCase):
)
self.assertEqual(len(inspections), 1)
def test_download_and_parse_closes_playwright_when_portal_fails(self):
class _PortalClient(ProverkiClient):
playwright_closed = False
def _download_from_portal(self, *args, **kwargs): # type: ignore[override]
raise RuntimeError("navigation failed")
def _close_playwright(self): # type: ignore[override]
self.playwright_closed = True
client = _PortalClient(use_playwright=True)
with self.assertRaises(RuntimeError):
client._download_and_parse(
"http://portal.example.com", file_format="portal"
)
self.assertTrue(client.playwright_closed)
def test_download_from_portal_does_not_wait_for_networkidle(self):
archive = build_zip(
[("data.xml", _xml_with_tag("INSPECTION", _inspection_attrs()))]
@@ -654,6 +673,63 @@ class ProverkiParseXMLTest(SimpleTestCase):
self.assertEqual(inspections[0].inspection_type, inspection_type)
self.assertEqual(inspections[0].status, status)
def test_parse_xml_record_fz248_current_production_shape(self):
xml = b"""<?xml version="1.0" encoding="utf-8"?>
<INSPECTIONS>
<INSPECTION
ERPID="248000000000"
START_DATE="2026-07-01"
STOP_DATE="2026-07-15"
STATUS="Completed"
TYPE_NAME="Unscheduled inspection">
<SUBJECT
INN="7700000000"
OGRN="1027700000000"
NAME="Example Industrial Company" />
<KNO_ORGANIZATION VALUE="Example Supervisory Authority" />
<KIND_CONTROL VALUE="Federal industrial supervision" />
<KIND_KNM VALUE="On-site inspection" />
</INSPECTION>
</INSPECTIONS>
"""
client = ProverkiClient()
inspections = client._parse_xml_content(xml)
self.assertEqual(len(inspections), 1)
inspection = inspections[0]
self.assertEqual(inspection.registration_number, "248000000000")
self.assertEqual(inspection.inn, "7700000000")
self.assertEqual(inspection.ogrn, "1027700000000")
self.assertEqual(inspection.organisation_name, "Example Industrial Company")
self.assertEqual(
inspection.control_authority,
"Example Supervisory Authority",
)
self.assertEqual(inspection.inspection_type, "Unscheduled inspection")
self.assertEqual(inspection.inspection_form, "On-site inspection")
self.assertEqual(inspection.start_date, "2026-07-01")
self.assertEqual(inspection.end_date, "2026-07-15")
self.assertEqual(inspection.status, "Completed")
def test_parse_xml_record_fz248_kind_control_is_type_fallback(self):
element = ET.fromstring( # noqa: S314
"""
<INSPECTION ERPID="248000000001">
<KIND_CONTROL VALUE="Federal industrial supervision" />
</INSPECTION>
"""
)
client = ProverkiClient()
inspection = client._parse_xml_record(element)
self.assertIsNotNone(inspection)
self.assertEqual(
inspection.inspection_type,
"Federal industrial supervision",
)
def test_parse_xml_record_namespace_text_child_fallback(self):
ns = "http://example.com/ns"
inn = _digits(10)
@@ -1171,3 +1247,42 @@ class ProverkiPlaywrightStubTest(SimpleTestCase):
sys.modules.pop("playwright.sync_api", None)
else:
sys.modules["playwright.sync_api"] = original_module
def test_get_browser_launch_error_stops_playwright(self):
class _BrokenChromium:
def launch(self, **_kwargs):
raise RuntimeError("browser missing")
class _FakePlaywright:
chromium = _BrokenChromium()
def __init__(self):
self.stopped = False
def stop(self):
self.stopped = True
playwright = _FakePlaywright()
class _FakeSyncPlaywright:
def start(self):
return playwright
fake_module = types.SimpleNamespace(
sync_playwright=lambda: _FakeSyncPlaywright()
)
client = ProverkiClient()
original_module = sys.modules.get("playwright.sync_api")
sys.modules["playwright.sync_api"] = fake_module
try:
with self.assertRaises(ProverkiClientError):
client._get_browser()
finally:
if original_module is None:
sys.modules.pop("playwright.sync_api", None)
else:
sys.modules["playwright.sync_api"] = original_module
self.assertTrue(playwright.stopped)
self.assertIsNone(client._playwright)
self.assertIsNone(client._browser)