fix: exclude provider records from source exports
All checks were successful
CI/CD Pipeline / Code Quality Checks (push) Successful in 2m21s
CI/CD Pipeline / Run Tests (push) Successful in 3m35s
CI/CD Pipeline / Build and Push Dev Images (push) Successful in 1m14s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 34s

This commit is contained in:
2026-08-04 09:07:08 +02:00
parent 05292a1c16
commit c481d35b8c
3 changed files with 73 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ from rest_framework import status
from rest_framework.test import APITestCase
from tests.apps.external_data.factories import (
BankruptcyProcedureFactory,
FinancialReportFactory,
FinancialReportLineFactory,
IndustrialCertificateFactory,
@@ -106,6 +107,42 @@ class SourceRecordExportApiTest(APITestCase):
financial_rows = json.loads(financial_path.read_text(encoding="utf-8"))
self.assertEqual(financial_rows[0]["financial_lines"][0]["line_code"], "1600")
def test_generation_excludes_provider_records_and_keeps_okpo(self):
organization = OrganizationFactory.create(okpo="11223344")
excluded_record = BankruptcyProcedureFactory.create(
organization=organization,
external_id="checko-fedresurs:123",
source_url="https://api.checko.ru/v2/bankruptcy/123",
)
included_record = BankruptcyProcedureFactory.create(
organization=organization,
external_id="checkout-reference:456",
source_url="https://fedresurs.ru/message/456",
)
generation = build_source_record_export_artifacts()
self.assertEqual(generation.records_count, 1)
artifacts = [
artifact
for artifact in generation.artifacts
if artifact.source_group == "bankruptcy"
]
self.assertEqual(
{artifact.file_format for artifact in artifacts}, {"csv", "xlsx", "json"}
)
for artifact in artifacts:
if artifact.file_format == "json":
exported_values = json.loads(artifact.path.read_text(encoding="utf-8"))
elif artifact.file_format == "csv":
exported_values = artifact.path.read_text(encoding="utf-8-sig")
else:
workbook = load_workbook(artifact.path, read_only=True)
exported_values = list(workbook["data"].iter_rows(values_only=True))
self.assertNotIn(str(excluded_record.id), str(exported_values))
self.assertIn(str(included_record.id), str(exported_values))
self.assertIn("11223344", str(exported_values))
def test_management_command_bootstraps_first_generation(self):
command_output = StringIO()