feat: restore report files and export claim amounts
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 5m33s
CI/CD Pipeline / Run Tests (push) Failing after 5m33s
CI/CD Pipeline / Build and Push Dev Images (push) Has been skipped
CI/CD Pipeline / Deploy Dev via Compose (push) Has been skipped

This commit is contained in:
2026-08-09 12:23:37 +02:00
parent 2259ee1209
commit eb170ff914
12 changed files with 251 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
from __future__ import annotations
import hashlib
import tempfile
from pathlib import Path
from apps.core.models import ReportUpload, ReportUploadStatus
from django.core.management import call_command
from django.test import TestCase, override_settings
class RestoreReportUploadFilesCommandTest(TestCase):
def _upload(self, *, content: bytes) -> ReportUpload:
digest = hashlib.sha256(content).hexdigest()
upload = ReportUpload.objects.create(
form="f1",
load_batch=101,
original_file="report_uploads/f1/restored/report.xlsx",
file_name="report.xlsx",
content_type=(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
),
file_size=len(content),
file_hash=digest,
status=ReportUploadStatus.SUCCESS,
)
return upload
def test_dry_run_then_restore_and_repeat(self):
content = b"exact original workbook bytes"
upload = self._upload(content=content)
with tempfile.TemporaryDirectory() as media_dir, tempfile.TemporaryDirectory() as source_dir:
source_path = Path(source_dir) / "original.xlsx"
source_path.write_bytes(content)
with override_settings(MEDIA_ROOT=media_dir):
dry_run_result = call_command(
"restore_report_upload_files",
source_dir=[source_dir],
dry_run=True,
)
self.assertIn('"restored": 1', dry_run_result)
self.assertFalse(
upload.original_file.storage.exists(upload.original_file.name)
)
restore_result = call_command(
"restore_report_upload_files",
source_dir=[source_dir],
)
self.assertIn('"restored": 1', restore_result)
with upload.original_file.storage.open(
upload.original_file.name, "rb"
) as handle:
self.assertEqual(handle.read(), content)
repeat_result = call_command(
"restore_report_upload_files",
source_dir=[source_dir],
)
self.assertIn('"already_present": 1', repeat_result)
def test_existing_hash_mismatch_is_not_overwritten(self):
content = b"expected workbook"
upload = self._upload(content=content)
with tempfile.TemporaryDirectory() as media_dir, tempfile.TemporaryDirectory() as source_dir:
(Path(source_dir) / "original.xlsx").write_bytes(content)
target_path = Path(media_dir) / upload.original_file.name
target_path.parent.mkdir(parents=True)
target_path.write_bytes(b"different bytes")
with override_settings(MEDIA_ROOT=media_dir):
result = call_command(
"restore_report_upload_files",
source_dir=[source_dir],
)
self.assertIn('"hash_mismatch": 1', result)
self.assertEqual(target_path.read_bytes(), b"different bytes")

View File

@@ -316,6 +316,7 @@ def build_exchange_payload() -> dict[str, list[dict[str, object]]]:
"party_role": "ответчик",
"status": "in_progress",
"decision_date": "2026-03-25",
"claim_amount": "1250000.50",
}
],
"bankruptcy_procedures": [
@@ -463,6 +464,10 @@ class ExchangePackageApiTest(APITestCase):
self.assertEqual(FinancialReport.objects.count(), 1)
self.assertEqual(FinancialReportLine.objects.count(), 1)
self.assertEqual(ArbitrationCase.objects.count(), 1)
self.assertEqual(
ArbitrationCase.objects.get().claim_amount,
Decimal("1250000.50"),
)
self.assertEqual(BankruptcyProcedure.objects.count(), 1)
self.assertEqual(
BankruptcyProcedure._meta.get_field("status").max_length,

View File

@@ -101,6 +101,9 @@ class ArbitrationCaseFactory(factory.django.DjangoModelFactory):
court_name = "Арбитражный суд города Москвы"
party_role = "defendant"
status = "hearing_scheduled"
claim_amount = factory.LazyAttribute(
lambda _: fake.pydecimal(left_digits=8, right_digits=2, positive=True)
)
decision_date = factory.LazyAttribute(lambda _: fake.date_this_year())

View File

@@ -124,6 +124,7 @@ class ExternalDataApiTest(APITestCase):
self.assertEqual(procurement_response.data["count"], 1)
self.assertEqual(arbitration_response.status_code, status.HTTP_200_OK)
self.assertEqual(arbitration_response.data["count"], 1)
self.assertIn("claim_amount", arbitration_response.data["results"][0])
def test_corporation_memberships_filter(self):
InformationSecurityRegistryEntryFactory(

View File

@@ -164,6 +164,14 @@ class SourceRecordExportApiTest(APITestCase):
arbitration_row["record_date"], arbitration_case.decision_date.isoformat()
)
self.assertEqual(arbitration_row["status"], arbitration_row["payload.status"])
self.assertEqual(
arbitration_row["amount"],
str(arbitration_case.claim_amount),
)
self.assertEqual(
arbitration_row["payload.claim_amount"],
str(arbitration_case.claim_amount),
)
self.assertEqual(arbitration_row["payload.role"], "defendant")
self.assertIn("payload.court", arbitration_row)
self.assertEqual(arbitration_row["payload.source"], "arbitration")