fix: create organizations from form uploads
All checks were successful
All checks were successful
This commit is contained in:
127
tests/apps/forms/test_parser_organization_creation.py
Normal file
127
tests/apps/forms/test_parser_organization_creation.py
Normal file
@@ -0,0 +1,127 @@
|
||||
"""Tests for organization creation during form imports."""
|
||||
|
||||
from apps.form_1.services import FormF1Parser
|
||||
from apps.form_2.services import FormF2Parser
|
||||
from apps.form_3.services import FormF3Parser
|
||||
from apps.form_4.services import FormF4Parser
|
||||
from apps.form_5.services import FormF5Parser
|
||||
from apps.form_6.services import FormF6Parser
|
||||
from apps.organization.models import Organization
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class FormParserOrganizationCreationTest(TestCase):
|
||||
"""Tests that report rows may create organizations without exchange preload."""
|
||||
|
||||
CASES = (
|
||||
(
|
||||
"f1",
|
||||
FormF1Parser,
|
||||
{"report_year": 2026, "report_month": 9},
|
||||
601,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-1",
|
||||
"inn": "7100000001",
|
||||
"ogrn": "1020000000001",
|
||||
"kpp": "770100001",
|
||||
"okpo": "11110001",
|
||||
"military_output_actual": 100.0,
|
||||
"civilian_output_actual": 200.0,
|
||||
},
|
||||
),
|
||||
(
|
||||
"f2",
|
||||
FormF2Parser,
|
||||
{"report_year": 2026, "report_quarter": 1},
|
||||
602,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-2",
|
||||
"inn": "7100000002",
|
||||
"ogrn": "1020000000002",
|
||||
"kpp": "770100002",
|
||||
"okpo": "11110002",
|
||||
"total_assets": 1000000.0,
|
||||
"revenue": 500000.0,
|
||||
},
|
||||
),
|
||||
(
|
||||
"f3",
|
||||
FormF3Parser,
|
||||
{"report_year": 2026, "report_quarter": 1},
|
||||
603,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-3",
|
||||
"inn": "7100000003",
|
||||
"ogrn": "1020000000003",
|
||||
"kpp": "770100003",
|
||||
"okpo": "11110003",
|
||||
"avg_employees": 100,
|
||||
"total_equipment": 50,
|
||||
},
|
||||
),
|
||||
(
|
||||
"f4",
|
||||
FormF4Parser,
|
||||
{"report_year": 2026, "report_half_year": 1},
|
||||
604,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-4",
|
||||
"inn": "7100000004",
|
||||
"ogrn": "1020000000004",
|
||||
"kpp": "770100004",
|
||||
"okpo": "11110004",
|
||||
"revenue_rsbu": 1000000.0,
|
||||
"net_profit_rsbu": 50000.0,
|
||||
},
|
||||
),
|
||||
(
|
||||
"f5",
|
||||
FormF5Parser,
|
||||
{"report_year": 2026, "report_quarter": 1},
|
||||
605,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-5",
|
||||
"inn": "7100000005",
|
||||
"ogrn": "1020000000005",
|
||||
"kpp": "770100005",
|
||||
"okpo": "11110005",
|
||||
"equipment_id": "EQ-001",
|
||||
"equipment_name": "Токарный станок",
|
||||
},
|
||||
),
|
||||
(
|
||||
"f6",
|
||||
FormF6Parser,
|
||||
{"report_year": 2026, "report_quarter": 1},
|
||||
606,
|
||||
{
|
||||
"organization_name": "Тестовая организация Ф-6",
|
||||
"inn": "7100000006",
|
||||
"ogrn": "1020000000006",
|
||||
"kpp": "770100006",
|
||||
"okpo": "11110006",
|
||||
"row_code": "001",
|
||||
"category": "Металлорежущее",
|
||||
"total_equipment": 100,
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def test_create_record_creates_missing_organization_from_row_identifiers(self):
|
||||
for form_name, parser_class, parser_kwargs, batch_id, row_data in self.CASES:
|
||||
with self.subTest(form=form_name):
|
||||
parser = parser_class(**parser_kwargs)
|
||||
parser.load_batch = batch_id
|
||||
|
||||
self.assertFalse(
|
||||
Organization.objects.filter(inn=row_data["inn"]).exists()
|
||||
)
|
||||
|
||||
record = parser.create_record(row_data)
|
||||
|
||||
organization = Organization.objects.get(inn=row_data["inn"])
|
||||
self.assertEqual(record.organization_id, organization.id)
|
||||
self.assertEqual(organization.name, row_data["organization_name"])
|
||||
self.assertEqual(organization.ogrn, row_data["ogrn"])
|
||||
self.assertEqual(organization.kpp, row_data["kpp"])
|
||||
self.assertEqual(organization.okpo, row_data["okpo"])
|
||||
Reference in New Issue
Block a user