fix: serve latest organization analytics data
Some checks failed
CI/CD Pipeline / Run Tests (push) Failing after 2m53s
CI/CD Pipeline / Code Quality Checks (push) Successful in 3m12s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped

This commit is contained in:
2026-06-01 12:09:03 +02:00
parent cd74427741
commit b64425b31d
5 changed files with 178 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ from django.test import override_settings
from rest_framework import status
from rest_framework.test import APITestCase
from tests.apps.external_data.factories import FinancialReportFactory
from tests.apps.form_1.factories import FormF1RecordFactory
from tests.apps.form_2.factories import FormF2RecordFactory
from tests.apps.form_3.factories import FormF3RecordFactory
@@ -244,6 +245,16 @@ class OrganizationAnalyticsApiTest(APITestCase):
)
)
def test_economics_uses_latest_available_year_when_requested_range_is_empty(self):
response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/economics/"
"?group=efficiency&from_year=2022&to_year=2024"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["periods"], [2026])
self.assertEqual(response.data["series"][0]["points"][0]["period"], 2026)
def test_personnel_contract(self):
personnel_response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/personnel/"
@@ -271,6 +282,29 @@ class OrganizationAnalyticsApiTest(APITestCase):
)
self.assertIn("employees_count", personnel_response.data["age_distribution"][0])
def test_yearly_analytics_use_latest_available_year_when_requested_year_is_empty(
self,
):
personnel_response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/personnel/"
"?report_year=2024&history_years=2"
)
equipment_response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/equipment/"
"?report_year=2024"
)
products_response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/products/"
"?frequency=quarterly&price_mode=actual&report_year=2024"
)
self.assertEqual(personnel_response.status_code, status.HTTP_200_OK)
self.assertEqual(equipment_response.status_code, status.HTTP_200_OK)
self.assertEqual(products_response.status_code, status.HTTP_200_OK)
self.assertEqual(personnel_response.data["report_year"], 2026)
self.assertEqual(equipment_response.data["report_year"], 2026)
self.assertEqual(products_response.data["report_year"], 2026)
def test_equipment_contract(self):
response = self.client.get(
f"/api/v1/organizations/{self.organization.id}/analytics/equipment/"
@@ -457,6 +491,23 @@ class OrganizationAnalyticsApiTest(APITestCase):
self.assertIn("risk_level", response.data)
self.assertIn("updated_at", response.data)
def test_risk_profile_uses_available_related_report_data(self):
organization = OrganizationFactory.create(
financial_reports_available=False,
tax_reports_available=False,
)
FinancialReportFactory.create(organization=organization, status="success")
FormF2RecordFactory.create(organization=organization, income_tax="1000.00")
response = self.client.get(
f"/api/v1/organizations/{organization.id}/risk-profile/"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(response.data["financial_reports_available"])
self.assertTrue(response.data["tax_reports_available"])
self.assertEqual(response.data["risk_level"], "low")
def test_dashboard_endpoint(self):
response = self.client.get(
"/api/v1/analytics/dashboard/?corporation_scope=rosatom"

View File

@@ -9,6 +9,8 @@ from django.test import override_settings
from rest_framework import status
from rest_framework.test import APITestCase
from tests.apps.external_data.factories import FinancialReportFactory
from tests.apps.form_2.factories import FormF2RecordFactory
from tests.apps.organization.factories import OrganizationFactory
from tests.apps.user.factories import UserFactory
@@ -120,6 +122,20 @@ class OrganizationApiTest(APITestCase):
"Иванов Иван Иванович",
)
def test_detail_summary_uses_available_related_report_data(self):
organization = OrganizationFactory.create(
financial_reports_available=False,
tax_reports_available=False,
)
FinancialReportFactory.create(organization=organization, status="success")
FormF2RecordFactory.create(organization=organization, income_tax="1200.00")
response = self.client.get(f"/api/v1/organizations/{organization.id}/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(response.data["summary"]["financial_reports_available"])
self.assertTrue(response.data["summary"]["tax_reports_available"])
def test_registry_filter_uses_only_active_memberships(self):
active_organization = OrganizationFactory.create(name="АО Актив")
closed_organization = OrganizationFactory.create(name="АО Закрыт")