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

@@ -151,6 +151,27 @@ class CheckoSectionContractTests(TestCase):
== "partial"
)
def test_nullable_publisher_survives_public_list_and_detail(self):
first = fixture("messages-page-1.json")
first["data"]["Записи"][0]["Публикатор"] = None
with patch.object(
snapshots,
"_client",
return_value=client_with(first, fixture("messages-page-2.json")),
):
snapshots.refresh_checko_section(source="checko_messages", load_batch=1)
response = self.client.get(self.url, {"source_group": "company_messages"})
assert response.status_code == 200, response.data
row = next(
row
for row in response.data["data"]
if row["payload"]["publisher_identifier"] is None
)
detail = self.client.get(self.url + row["uid"] + "/")
assert detail.status_code == 200, detail.data
assert detail.data["payload"] == row["payload"]
assert row["payload"]["participant_identifiers"] == [self.org.inn]
def test_no_completed_failure_exposes_rejected_counters(self):
source = "checko_messages"
claim_monthly_collection(organization_id=str(self.org.uid), source=source)

View File

@@ -141,12 +141,12 @@ def _canonical_records():
)
sections = []
for source in ("checko_leasing", "checko_messages", "checko_licenses"):
message_page = fixture("messages-page-1.json")
message_page["data"]["Записи"][0]["Публикатор"] = None
client = (
client_with(fixture("license.json"))
if source == "checko_licenses"
else client_with(
fixture("messages-page-1.json"), fixture("messages-page-2.json")
)
else client_with(message_page, fixture("messages-page-2.json"))
)
row = next(collect_checko_section(client, organization=fssp_org, source=source))
row.payload["upstream"]["future_nested"] = {

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