fix: accept nullable message publishers and scoped dev SPB trust
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m3s
Mostovik Backend CI/CD / Deploy dev (push) Has been cancelled
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been cancelled
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been cancelled

This commit is contained in:
Aleksandr Meshchryakov
2026-10-05 19:23:03 +02:00
parent 0dd763109b
commit 1a82345ab3
13 changed files with 131 additions and 15 deletions

View File

@@ -177,7 +177,7 @@ def test_overlapping_pages_cannot_prove_total_before_leasing_filter(source):
response["data"]["ЗапВсего"] = 4
with pytest.raises(SnapshotValidationError) as error:
collect(client_with(first, second), source)
assert str(error.value.__cause__) == "incomplete_checko_record_count"
assert str(error.value) == "incomplete_checko_record_count"
def test_license_unknown_raw_fields_survive():
@@ -200,3 +200,23 @@ def test_malformed_license_section_rejected(value):
response["data"]["Лиценз"] = value
with pytest.raises(SnapshotValidationError):
collect(client_with(response), "checko_licenses")
@pytest.mark.parametrize("source", ["checko_messages", "checko_leasing"])
def test_nullable_publisher_keeps_message_when_canonical_subject_is_participant(source):
first = fixture("messages-page-1.json")
first["data"]["Записи"][0]["Публикатор"] = None
rows = collect(client_with(first, fixture("messages-page-2.json")), source)
assert rows[0].payload["publisher_identifier"] is None
assert rows[0].payload["participant_identifiers"] == [ORG.inn]
assert rows[0].payload["upstream"]["Публикатор"] is None
def test_nullable_publisher_does_not_admit_message_for_another_subject():
first = fixture("messages-page-1.json")
first["data"]["Записи"][0]["Публикатор"] = None
first["data"]["Записи"][0]["Участники"] = ["0000000000"]
with pytest.raises(
SnapshotValidationError, match="^checko_message_subject_mismatch$"
):
collect(client_with(first, fixture("messages-page-2.json")))

View File

@@ -105,7 +105,8 @@ def test_tls_trust_stays_default():
@pytest.mark.django_db
def test_download_checksum_date_private_file_and_three_bounded_reads(tmp_path):
@pytest.mark.parametrize("trusted", [False, True])
def test_download_checksum_date_private_file_and_three_bounded_reads(tmp_path, trusted):
import hashlib
from contextlib import contextmanager
from unittest.mock import patch
@@ -117,6 +118,9 @@ def test_download_checksum_date_private_file_and_three_bounded_reads(tmp_path):
@contextmanager
def response(session, url, **kwargs):
from apps.parsers.clients.common.structured import EIS_CA_BUNDLE_PATH
assert session.verify == (str(EIS_CA_BUNDLE_PATH) if trusted else True)
urls.append(url)
class Response:
@@ -125,14 +129,16 @@ def test_download_checksum_date_private_file_and_three_bounded_reads(tmp_path):
yield Response()
with override_settings(PARSER_PRIVATE_ARTIFACT_ROOT=str(tmp_path)), patch.object(
module, "registry_response", response
):
with override_settings(
PARSER_PRIVATE_ARTIFACT_ROOT=str(tmp_path),
EXCHANGE_SPB_RUSSIAN_TRUST_ENABLED=trusted,
), patch.object(module, "registry_response", response):
artifact = module.download_spb_artifact(load_batch=1)
assert artifact.sha256 == hashlib.sha256(body).hexdigest()
assert artifact.source_published_at.isoformat() == "2026-10-05"
assert artifact.metadata["input_only"] is True
assert len(urls) == 3
assert module.registry_session().verify is True
with pytest.raises(ValueError):
_ = artifact.file.url