feat: add ROPK sanctions file source
All checks were successful
All checks were successful
This commit is contained in:
@@ -22,6 +22,7 @@ from organizations.models import (
|
||||
OrganizationSourceFinancialLine,
|
||||
OrganizationSourceRecord,
|
||||
PlannedInspectionExtension,
|
||||
SanctionsExtension,
|
||||
SourceGroup,
|
||||
)
|
||||
from organizations.source_record_export import (
|
||||
@@ -92,9 +93,93 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase):
|
||||
call_command("build_source_record_exports", stdout=command_output)
|
||||
|
||||
generation = load_current_source_record_export_generation()
|
||||
self.assertEqual(generation.artifacts_count, 31)
|
||||
self.assertEqual(generation.artifacts_count, 34)
|
||||
self.assertEqual(generation.export_year, timezone.localdate().year)
|
||||
self.assertIn('"artifacts_count": 31', command_output.getvalue())
|
||||
self.assertIn('"artifacts_count": 34', command_output.getvalue())
|
||||
|
||||
def test_sanctions_xlsx_export_uses_source_contract_columns_and_boolean_flags(self):
|
||||
organization = Organization.objects.create(
|
||||
name="АО Экспорт Санкции",
|
||||
inn="0012345678",
|
||||
ogrn="1027700132195",
|
||||
okpo="00123456",
|
||||
)
|
||||
extension = SanctionsExtension.objects.create(
|
||||
organization=organization,
|
||||
title="РОПК — Санкции",
|
||||
)
|
||||
OrganizationSourceRecord.objects.create(
|
||||
extension=extension,
|
||||
source="ropk_sanctions",
|
||||
record_type="organization_sanctions",
|
||||
external_id="000001",
|
||||
title=organization.name,
|
||||
status="active",
|
||||
payload={
|
||||
"rn": "000001",
|
||||
"uk_hm_treasury": True,
|
||||
"european_union": False,
|
||||
"united_states": True,
|
||||
"switzerland": False,
|
||||
"united_states_sectoral": True,
|
||||
"uk_uksl": False,
|
||||
"ukraine": True,
|
||||
},
|
||||
)
|
||||
build_source_record_export_artifacts()
|
||||
self.client.force_authenticate(UserFactory.create_superuser())
|
||||
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"sources": [SourceGroup.SANCTIONS.value], "format": "xlsx"},
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
with zipfile.ZipFile(BytesIO(self._response_body(response))) as archive:
|
||||
self.assertEqual(archive.namelist(), ["ropk-sanctions.xlsx"])
|
||||
workbook = load_workbook(
|
||||
BytesIO(archive.read("ropk-sanctions.xlsx")),
|
||||
read_only=True,
|
||||
data_only=True,
|
||||
)
|
||||
rows = list(workbook["data"].iter_rows(values_only=True))
|
||||
workbook.close()
|
||||
|
||||
self.assertEqual(
|
||||
rows[0],
|
||||
(
|
||||
"Наименование",
|
||||
"rn",
|
||||
"ogrn",
|
||||
"inn",
|
||||
"okpo",
|
||||
"Санкции - Великобритания HM Treasury",
|
||||
"Санкции - Евросоюз",
|
||||
"Санкции - США",
|
||||
"Санкции - Швейцария",
|
||||
"Санкции секторальные - США",
|
||||
"Санкции - Великобритания UKSL",
|
||||
"Санкции - Украина",
|
||||
),
|
||||
)
|
||||
self.assertEqual(
|
||||
rows[1],
|
||||
(
|
||||
"АО Экспорт Санкции",
|
||||
"000001",
|
||||
"1027700132195",
|
||||
"0012345678",
|
||||
"00123456",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
),
|
||||
)
|
||||
|
||||
def test_generation_contains_only_records_from_its_calendar_year(self):
|
||||
export_year = 2026
|
||||
@@ -313,7 +398,7 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase):
|
||||
self.assertEqual(
|
||||
response["X-Source-Export-Generated-At"], generation.generated_at
|
||||
)
|
||||
self.assertEqual(generation.artifacts_count, 31)
|
||||
self.assertEqual(generation.artifacts_count, 34)
|
||||
self.assertIn(
|
||||
'filename="planned-inspections__financial-indicators_',
|
||||
response["Content-Disposition"],
|
||||
@@ -508,8 +593,8 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase):
|
||||
key=lambda item: item.file_name,
|
||||
)
|
||||
|
||||
self.assertEqual(generation.artifacts_count, 31)
|
||||
self.assertEqual(generation.files_count, 32)
|
||||
self.assertEqual(generation.artifacts_count, 34)
|
||||
self.assertEqual(generation.files_count, 35)
|
||||
self.assertEqual(
|
||||
[item.file_name for item in artifacts],
|
||||
[
|
||||
@@ -707,7 +792,7 @@ class OrganizationSourceRecordExportApiV2Test(APITestCase):
|
||||
first_generation = build_source_record_export_artifacts()
|
||||
current_generation = load_current_source_record_export_generation()
|
||||
|
||||
self.assertEqual(first_generation.artifacts_count, 31)
|
||||
self.assertEqual(first_generation.artifacts_count, 34)
|
||||
self.assertEqual(
|
||||
current_generation.generation_id, first_generation.generation_id
|
||||
)
|
||||
|
||||
@@ -145,7 +145,7 @@ class SourceRecordExportArtifactsTaskTest(TestCase):
|
||||
result = refresh_source_record_export_artifacts()
|
||||
|
||||
self.assertEqual(result["status"], "success")
|
||||
self.assertEqual(result["artifacts_count"], 31)
|
||||
self.assertEqual(result["artifacts_count"], 34)
|
||||
self.assertEqual(result["export_year"], timezone.localdate().year)
|
||||
self.assertIsNone(cache.get(settings.SOURCE_RECORD_EXPORT_LOCK_KEY))
|
||||
|
||||
|
||||
@@ -64,7 +64,11 @@ class TestCompaniesCommandsTest(TestCase):
|
||||
)
|
||||
|
||||
expected_groups = {choice.value for choice in SourceGroup}
|
||||
expected_sources = {choice.value for choice in ParserLoadLog.Source}
|
||||
expected_sources = {
|
||||
choice.value
|
||||
for choice in ParserLoadLog.Source
|
||||
if choice is not ParserLoadLog.Source.ROPK_SANCTIONS
|
||||
}
|
||||
for company in companies:
|
||||
self.assertEqual(
|
||||
set(company.source_extensions.values_list("source_group", flat=True)),
|
||||
|
||||
Reference in New Issue
Block a user