feat: use authoritative organization directory
Some checks failed
CI/CD Pipeline / Quality Gate (push) Failing after 9s
CI/CD Pipeline / Build and Push Images (push) Has been skipped
CI/CD Pipeline / Deploy Dev via Compose (push) Has been skipped
CI/CD Pipeline / Internal Notify (push) Successful in 0s

This commit is contained in:
2026-06-07 16:04:43 +02:00
parent 79f0f8ebf7
commit 6ba8fa8d88
41 changed files with 2781 additions and 1058 deletions

View File

@@ -7,9 +7,8 @@ Unit-тесты для ProcurementService.
from apps.parsers.clients.zakupki.schemas import Procurement
from apps.parsers.models import ParserLoadLog, ProcurementRecord
from apps.parsers.services import ProcurementService
from apps.registers.models import Organization
from django.test import TestCase
from organizations.models import OrganizationSourceRecord
from organizations.models import Organization, OrganizationSourceRecord
from tests.apps.parsers.factories import ProcurementRecordFactory, fake
@@ -37,11 +36,23 @@ def _other_law(law_type: str) -> str:
def _create_registry_organization(*, inn: str, ogrn: str) -> Organization:
return Organization.objects.create(
pn_name=fake.company(),
mn_ogrn=int(ogrn),
mn_inn=int(inn),
in_kpp=int(_digits(9)),
mn_okpo=_digits(8),
name=fake.company(),
ogrn=ogrn,
inn=inn,
kpp=_digits(9),
okpo=_digits(8),
)
def _ensure_directory_organization_for_procurement(
procurement: Procurement,
) -> Organization:
return Organization.objects.create(
name=procurement.customer_name,
ogrn=procurement.customer_ogrn,
inn=procurement.customer_inn,
kpp=procurement.customer_kpp,
okpo=_digits(8),
)
@@ -82,6 +93,7 @@ def _save_procurement_source_record(
**overrides,
) -> Procurement:
procurement = _build_procurement(**overrides)
_ensure_directory_organization_for_procurement(procurement)
ProcurementService.save_procurements(
[procurement],
batch_id=batch_id,
@@ -111,6 +123,7 @@ class ProcurementServiceSaveTestCase(TestCase):
purchase_number=purchase_number,
customer_inn=customer_inn,
)
_ensure_directory_organization_for_procurement(procurement)
saved = ProcurementService.save_procurements(
[procurement],
@@ -134,6 +147,8 @@ class ProcurementServiceSaveTestCase(TestCase):
def test_save_multiple_procurements(self):
"""Сохранение нескольких закупок."""
procurements = [_build_procurement() for _ in range(5)]
for procurement in procurements:
_ensure_directory_organization_for_procurement(procurement)
saved = ProcurementService.save_procurements(procurements, batch_id=1)
@@ -169,6 +184,7 @@ class ProcurementServiceSaveTestCase(TestCase):
purchase_number=purchase_number,
customer_inn=_digits(10),
)
_ensure_directory_organization_for_procurement(procurement)
saved = ProcurementService.save_procurements([procurement], batch_id=2)
@@ -183,6 +199,8 @@ class ProcurementServiceSaveTestCase(TestCase):
def test_save_with_chunking(self):
"""Сохранение большого количества записей чанками."""
procurements = [_build_procurement() for _ in range(100)]
for procurement in procurements:
_ensure_directory_organization_for_procurement(procurement)
saved = ProcurementService.save_procurements(
procurements, batch_id=1, chunk_size=25