feat: address QA analytics and report upload feedback
All checks were successful
CI/CD Pipeline / Run Tests (push) Successful in 2m26s
CI/CD Pipeline / Code Quality Checks (push) Successful in 5m3s
CI/CD Pipeline / Build and Push Dev Images (push) Successful in 32s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 31s

This commit is contained in:
2026-07-19 13:32:56 +02:00
parent b025f12856
commit 9eb41f6fd4
28 changed files with 938 additions and 82 deletions

View File

@@ -11,6 +11,8 @@ from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from tests.apps.form_1.factories import FormF1RecordFactory
from tests.apps.organization.factories import OrganizationFactory
from tests.apps.user.factories import UserFactory
@@ -32,6 +34,8 @@ class ReportUploadApiTest(APITestCase):
),
form="f1",
user=self.user,
report_year=2026,
report_month=9,
)
def test_service_persists_original_bytes_and_finalizes_batch(self):
@@ -101,3 +105,69 @@ class ReportUploadApiTest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_410_GONE)
self.assertEqual(response.data["errors"][0]["code"], "source_file_gone")
def test_history_returns_upload_before_records_are_parsed(self):
report_upload = self._create_upload()
ReportUploadService.mark_queued(report_upload.id, job_id="job-42")
self.client.force_authenticate(self.user)
response = self.client.get("/api/v1/forms/uploads/history/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 1)
row = response.data["results"][0]
self.assertEqual(row["upload_id"], str(report_upload.id))
self.assertEqual(row["form"], "f1")
self.assertEqual(row["report_year"], 2026)
self.assertEqual(row["report_month"], 9)
self.assertEqual(row["status"], "queued")
self.assertEqual(row["job_id"], "job-42")
self.assertIsNone(row["organization_id"])
self.assertFalse(row["download_available"])
def test_history_projects_successful_upload_per_organization(self):
organization = OrganizationFactory.create(
name="Тестовая компания 1",
inn="7709000010",
gk_code="rosatom",
gk_name="Госкорпорация Росатом",
)
report_upload = self._create_upload()
FormF1RecordFactory.create(
organization=organization,
load_batch=42,
report_year=2026,
report_month=9,
)
ReportUploadService.finalize(report_upload.id, {"batch_id": 42})
self.client.force_authenticate(self.user)
response = self.client.get(
"/api/v1/forms/uploads/history/",
{
"corporation_scope": "rosatom",
"organization_inn": organization.inn,
"report_year": 2026,
},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 1)
row = response.data["results"][0]
self.assertEqual(row["organization_id"], str(organization.id))
self.assertEqual(row["organization_name"], organization.name)
self.assertEqual(row["organization_inn"], organization.inn)
self.assertEqual(row["corporation_scope"], "rosatom")
self.assertEqual(row["report_period_display"], "Сентябрь 2026")
self.assertEqual(row["records_count"], 1)
self.assertTrue(row["download_available"])
self.assertEqual(row["download_url"], "/api/v1/forms/f1/uploads/42/download/")
def test_history_does_not_expose_another_users_uploads(self):
self._create_upload()
self.client.force_authenticate(UserFactory.create_user())
response = self.client.get("/api/v1/forms/uploads/history/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["count"], 0)