Add initial implementations for forms and organization apps with serializers, factories, and admin configurations
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 5m5s
CI/CD Pipeline / Run Tests (push) Failing after 5m5s
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-02-17 09:26:08 +01:00
parent fd2adf9ab4
commit 8ed3e1175c
119 changed files with 9091 additions and 0 deletions

View File

@@ -0,0 +1 @@
"""Tests for form_4 app."""

View File

@@ -0,0 +1,39 @@
"""Factories for form_4 app."""
import factory
from apps.form_4.models import FormF4Record
from faker import Faker
from tests.apps.organization.factories import OrganizationFactory
fake = Faker("ru_RU")
class FormF4RecordFactory(factory.django.DjangoModelFactory):
"""Factory for FormF4Record model."""
class Meta:
model = FormF4Record
organization = factory.SubFactory(OrganizationFactory)
load_batch = factory.LazyAttribute(lambda _: fake.uuid4())
# Выручка
revenue_rsbu = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1000000, max_value=100000000000, left_digits=15, right_digits=2))
revenue_ifrs = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1000000, max_value=100000000000, left_digits=15, right_digits=2))
# Прибыль
net_profit_rsbu = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-10000000000, max_value=50000000000, left_digits=15, right_digits=2))
net_profit_ifrs = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-10000000000, max_value=50000000000, left_digits=15, right_digits=2))
# EBITDA
ebitda_rsbu = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=50000000000, left_digits=15, right_digits=2))
ebitda_ifrs = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=50000000000, left_digits=15, right_digits=2))
# Долг
net_debt_rsbu = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100000000000, left_digits=15, right_digits=2))
# Рентабельность
roe = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-100, max_value=100, left_digits=5, right_digits=2))
roa = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-100, max_value=100, left_digits=5, right_digits=2))
ros = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-100, max_value=100, left_digits=5, right_digits=2))

View File

@@ -0,0 +1,43 @@
"""Tests for FormF4 model."""
from django.test import TestCase
from .factories import FormF4RecordFactory
class FormF4RecordModelTest(TestCase):
"""Tests for FormF4Record model."""
def setUp(self):
self.record = FormF4RecordFactory.create()
def test_record_creation(self):
"""Test record creation."""
self.assertIsNotNone(self.record.id)
self.assertIsNotNone(self.record.organization)
self.assertIsNotNone(self.record.revenue_rsbu)
def test_record_str_representation(self):
"""Test string representation."""
expected = f"Ф-4: {self.record.organization} ({self.record.load_batch})"
self.assertEqual(str(self.record), expected)
def test_organization_relationship(self):
"""Test organization FK relationship."""
self.assertIsNotNone(self.record.organization.inn)
def test_decimal_fields_precision(self):
"""Test decimal fields precision."""
field = self.record._meta.get_field("revenue_rsbu")
self.assertEqual(field.max_digits, 18)
self.assertEqual(field.decimal_places, 2)
def test_ratio_fields_precision(self):
"""Test ratio fields precision."""
field = self.record._meta.get_field("roe")
self.assertEqual(field.max_digits, 8)
self.assertEqual(field.decimal_places, 2)
def test_load_batch_index(self):
"""Test load_batch has db_index."""
self.assertTrue(self.record._meta.get_field("load_batch").db_index)

View File

@@ -0,0 +1,79 @@
"""Tests for FormF4 services."""
from apps.form_4.services import FormF4Parser, FormF4Service
from django.test import TestCase
from tests.apps.organization.factories import OrganizationFactory
from .factories import FormF4RecordFactory
class FormF4ServiceTest(TestCase):
"""Tests for FormF4Service."""
def test_get_by_organization(self):
"""Test getting records by organization."""
org = OrganizationFactory.create()
FormF4RecordFactory.create(organization=org)
FormF4RecordFactory.create(organization=org)
FormF4RecordFactory.create()
results = FormF4Service.get_by_organization(org.id)
self.assertEqual(results.count(), 2)
def test_get_by_load_batch(self):
"""Test getting records by load batch."""
batch_id = "test-batch-f4"
FormF4RecordFactory.create(load_batch=batch_id)
FormF4RecordFactory.create(load_batch=batch_id)
results = FormF4Service.get_by_load_batch(batch_id)
self.assertEqual(results.count(), 2)
def test_delete_by_load_batch(self):
"""Test deleting records by load batch."""
batch_id = "delete-batch-f4"
FormF4RecordFactory.create(load_batch=batch_id)
FormF4RecordFactory.create(load_batch=batch_id)
other = FormF4RecordFactory.create(load_batch="keep-batch")
count = FormF4Service.delete_by_load_batch(batch_id)
self.assertEqual(count, 2)
from apps.form_4.models import FormF4Record
self.assertTrue(FormF4Record.objects.filter(pk=other.pk).exists())
class FormF4ParserTest(TestCase):
"""Tests for FormF4Parser."""
def test_get_column_mappings_returns_mappings(self):
"""Test get_column_mappings returns correct mappings."""
parser = FormF4Parser()
mappings = parser.get_column_mappings()
self.assertIsInstance(mappings, list)
self.assertTrue(len(mappings) > 0)
field_names = [m.field_name for m in mappings]
self.assertIn("inn", field_names)
self.assertIn("revenue_rsbu", field_names)
self.assertIn("net_profit_rsbu", field_names)
def test_create_record_creates_organization(self):
"""Test create_record creates organization if not exists."""
parser = FormF4Parser()
parser.load_batch = "test-batch"
row_data = {
"inn": "4234567890",
"name": "Тестовая организация Ф-4",
"revenue_rsbu": 1000000.0,
"net_profit_rsbu": 50000.0,
}
record = parser.create_record(row_data)
self.assertIsNotNone(record)
self.assertEqual(record.organization.inn, "4234567890")