fix: align reporting forms and demo analytics
All checks were successful
All checks were successful
This commit is contained in:
41
tests/apps/core/test_demo_period_workbooks.py
Normal file
41
tests/apps/core/test_demo_period_workbooks.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""Integration checks for the versioned Excel demo-period fixtures."""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from apps.form_3.services import FormF3Parser
|
||||
from apps.form_4.services import FormF4Parser
|
||||
from apps.form_6.services import FormF6Parser
|
||||
from django.test import TestCase
|
||||
|
||||
DEMO_DIR = Path(__file__).resolve().parents[3] / "input" / "demo-periods"
|
||||
|
||||
|
||||
class DemoPeriodWorkbooksTest(TestCase):
|
||||
def test_form_f3_workbooks_match_current_schema(self):
|
||||
for path in sorted(DEMO_DIR.glob("Ф-3_*.xlsx")):
|
||||
year = int(re.search(r"_(\d{4})", path.name).group(1))
|
||||
with self.subTest(path=path.name), path.open("rb") as file:
|
||||
result = FormF3Parser(report_year=year).parse(file)
|
||||
self.assertEqual(result.loaded_count, 20)
|
||||
self.assertEqual(result.skipped_count, 0)
|
||||
|
||||
def test_form_f4_workbooks_match_current_schema(self):
|
||||
for path in sorted(DEMO_DIR.glob("Ф-4_*.xlsx")):
|
||||
match = re.search(r"_(\d{4})-H([12])", path.name)
|
||||
year, half_year = map(int, match.groups())
|
||||
with self.subTest(path=path.name), path.open("rb") as file:
|
||||
result = FormF4Parser(
|
||||
report_year=year,
|
||||
report_half_year=half_year,
|
||||
).parse(file)
|
||||
self.assertEqual(result.loaded_count, 20)
|
||||
self.assertEqual(result.skipped_count, 0)
|
||||
|
||||
def test_form_f6_workbooks_are_structurally_consistent(self):
|
||||
for path in sorted(DEMO_DIR.glob("Ф-6_*.xlsx")):
|
||||
year = int(re.search(r"_(\d{4})", path.name).group(1))
|
||||
with self.subTest(path=path.name), path.open("rb") as file:
|
||||
result = FormF6Parser(report_year=year).parse(file)
|
||||
self.assertEqual(result.loaded_count, 20)
|
||||
self.assertEqual(result.skipped_count, 0)
|
||||
@@ -59,6 +59,51 @@ class GenerateTestReportsCommandTest(TestCase):
|
||||
self.assertEqual(PublicProcurement.objects.count(), 3)
|
||||
self.assertEqual(ArbitrationCase.objects.count(), 3)
|
||||
|
||||
for record in FormF3Record.objects.all():
|
||||
self.assertEqual(
|
||||
sum(
|
||||
(
|
||||
record.employees_under_20,
|
||||
record.employees_20_29,
|
||||
record.employees_30_39,
|
||||
record.employees_40_49,
|
||||
record.employees_50_59,
|
||||
record.employees_over_60,
|
||||
)
|
||||
),
|
||||
int(record.avg_employees),
|
||||
)
|
||||
self.assertEqual(
|
||||
record.machine_tools_and_equipment,
|
||||
record.total_equipment,
|
||||
)
|
||||
|
||||
for record in FormF6Record.objects.all():
|
||||
self.assertEqual(
|
||||
sum(
|
||||
(
|
||||
record.age_under_5,
|
||||
record.age_5_10,
|
||||
record.age_10_15,
|
||||
record.age_15_20,
|
||||
record.age_over_20,
|
||||
)
|
||||
),
|
||||
record.total_equipment,
|
||||
)
|
||||
self.assertEqual(
|
||||
sum(
|
||||
(
|
||||
record.age_under_5_imported,
|
||||
record.age_5_10_imported,
|
||||
record.age_10_15_imported,
|
||||
record.age_15_20_imported,
|
||||
record.age_over_20_imported,
|
||||
)
|
||||
),
|
||||
record.imported_equipment,
|
||||
)
|
||||
|
||||
self.assertIn(
|
||||
"Ф-1: создано 12 записей, активных 9, архивных 3", stdout.getvalue()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user