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
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:
1
tests/apps/form_2/__init__.py
Normal file
1
tests/apps/form_2/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for form_2 app."""
|
||||
33
tests/apps/form_2/factories.py
Normal file
33
tests/apps/form_2/factories.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Factories for form_2 app."""
|
||||
|
||||
import factory
|
||||
from apps.form_2.models import FormF2Record
|
||||
from faker import Faker
|
||||
|
||||
from tests.apps.organization.factories import OrganizationFactory
|
||||
|
||||
fake = Faker("ru_RU")
|
||||
|
||||
|
||||
class FormF2RecordFactory(factory.django.DjangoModelFactory):
|
||||
"""Factory for FormF2Record model."""
|
||||
|
||||
class Meta:
|
||||
model = FormF2Record
|
||||
|
||||
organization = factory.SubFactory(OrganizationFactory)
|
||||
load_batch = factory.LazyAttribute(lambda _: fake.uuid4())
|
||||
|
||||
# Активы
|
||||
total_assets = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1000000, max_value=10000000000, left_digits=15, right_digits=2))
|
||||
fixed_assets = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=100000, max_value=1000000000, left_digits=15, right_digits=2))
|
||||
inventories = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=10000, max_value=100000000, left_digits=15, right_digits=2))
|
||||
cash_and_equivalents = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=10000, max_value=100000000, left_digits=15, right_digits=2))
|
||||
|
||||
# Пассивы
|
||||
total_liabilities = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1000000, max_value=10000000000, left_digits=15, right_digits=2))
|
||||
total_equity = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=100000, max_value=5000000000, left_digits=15, right_digits=2))
|
||||
|
||||
# Финрезультаты
|
||||
revenue = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1000000, max_value=50000000000, left_digits=15, right_digits=2))
|
||||
net_profit = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=-1000000000, max_value=5000000000, left_digits=15, right_digits=2))
|
||||
43
tests/apps/form_2/test_models.py
Normal file
43
tests/apps/form_2/test_models.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Tests for FormF2 model."""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .factories import FormF2RecordFactory
|
||||
|
||||
|
||||
class FormF2RecordModelTest(TestCase):
|
||||
"""Tests for FormF2Record model."""
|
||||
|
||||
def setUp(self):
|
||||
self.record = FormF2RecordFactory.create()
|
||||
|
||||
def test_record_creation(self):
|
||||
"""Test record creation."""
|
||||
self.assertIsNotNone(self.record.id)
|
||||
self.assertIsNotNone(self.record.organization)
|
||||
self.assertIsNotNone(self.record.total_assets)
|
||||
|
||||
def test_record_str_representation(self):
|
||||
"""Test string representation."""
|
||||
expected = f"Ф-2: {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("total_assets")
|
||||
self.assertEqual(field.max_digits, 18)
|
||||
self.assertEqual(field.decimal_places, 2)
|
||||
|
||||
def test_nullable_fields(self):
|
||||
"""Test that financial fields are nullable."""
|
||||
field = self.record._meta.get_field("ebitda")
|
||||
self.assertTrue(field.null)
|
||||
self.assertTrue(field.blank)
|
||||
|
||||
def test_load_batch_index(self):
|
||||
"""Test load_batch has db_index."""
|
||||
self.assertTrue(self.record._meta.get_field("load_batch").db_index)
|
||||
79
tests/apps/form_2/test_services.py
Normal file
79
tests/apps/form_2/test_services.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Tests for FormF2 services."""
|
||||
|
||||
from apps.form_2.services import FormF2Parser, FormF2Service
|
||||
from django.test import TestCase
|
||||
|
||||
from tests.apps.organization.factories import OrganizationFactory
|
||||
|
||||
from .factories import FormF2RecordFactory
|
||||
|
||||
|
||||
class FormF2ServiceTest(TestCase):
|
||||
"""Tests for FormF2Service."""
|
||||
|
||||
def test_get_by_organization(self):
|
||||
"""Test getting records by organization."""
|
||||
org = OrganizationFactory.create()
|
||||
FormF2RecordFactory.create(organization=org)
|
||||
FormF2RecordFactory.create(organization=org)
|
||||
FormF2RecordFactory.create()
|
||||
|
||||
results = FormF2Service.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-f2"
|
||||
FormF2RecordFactory.create(load_batch=batch_id)
|
||||
FormF2RecordFactory.create(load_batch=batch_id)
|
||||
|
||||
results = FormF2Service.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-f2"
|
||||
FormF2RecordFactory.create(load_batch=batch_id)
|
||||
FormF2RecordFactory.create(load_batch=batch_id)
|
||||
other = FormF2RecordFactory.create(load_batch="keep-batch")
|
||||
|
||||
count = FormF2Service.delete_by_load_batch(batch_id)
|
||||
self.assertEqual(count, 2)
|
||||
|
||||
from apps.form_2.models import FormF2Record
|
||||
|
||||
self.assertTrue(FormF2Record.objects.filter(pk=other.pk).exists())
|
||||
|
||||
|
||||
class FormF2ParserTest(TestCase):
|
||||
"""Tests for FormF2Parser."""
|
||||
|
||||
def test_get_column_mappings_returns_mappings(self):
|
||||
"""Test get_column_mappings returns correct mappings."""
|
||||
parser = FormF2Parser()
|
||||
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("total_assets", field_names)
|
||||
self.assertIn("revenue", field_names)
|
||||
|
||||
def test_create_record_creates_organization(self):
|
||||
"""Test create_record creates organization if not exists."""
|
||||
parser = FormF2Parser()
|
||||
parser.load_batch = "test-batch"
|
||||
|
||||
row_data = {
|
||||
"inn": "2234567890",
|
||||
"name": "Тестовая организация Ф-2",
|
||||
"total_assets": 1000000.0,
|
||||
"revenue": 500000.0,
|
||||
}
|
||||
|
||||
record = parser.create_record(row_data)
|
||||
|
||||
self.assertIsNotNone(record)
|
||||
self.assertEqual(record.organization.inn, "2234567890")
|
||||
Reference in New Issue
Block a user