fix: exclude provider records from source exports
All checks were successful
All checks were successful
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user