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_6 app."""

View File

@@ -0,0 +1,43 @@
"""Factories for form_6 app."""
import factory
from apps.form_6.models import FormF6Record
from faker import Faker
from tests.apps.organization.factories import OrganizationFactory
fake = Faker("ru_RU")
class FormF6RecordFactory(factory.django.DjangoModelFactory):
"""Factory for FormF6Record model."""
class Meta:
model = FormF6Record
organization = factory.SubFactory(OrganizationFactory)
load_batch = factory.LazyAttribute(lambda _: fake.uuid4())
# Категоризация
row_code = factory.LazyAttribute(lambda _: fake.numerify("###"))
category = factory.LazyAttribute(lambda _: fake.random_element(["Металлорежущее", "Кузнечно-прессовое", "Литейное", "Сварочное"]))
# Общие данные
total_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=10, max=500))
domestic_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=5, max=250))
imported_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=5, max=250))
# Возрастная структура
age_under_5 = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=50))
age_5_10 = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=100))
age_10_15 = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=100))
age_15_20 = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=100))
age_over_20 = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=150))
# С ЧПУ
cnc_total = factory.LazyAttribute(lambda _: fake.random_int(min=0, max=100))
# Показатели
avg_shift_work = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=1, max_value=3, left_digits=1, right_digits=2))
utilization_rate = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))
physical_wear_percent = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))

View File

@@ -0,0 +1,47 @@
"""Tests for FormF6 model."""
from django.test import TestCase
from .factories import FormF6RecordFactory
class FormF6RecordModelTest(TestCase):
"""Tests for FormF6Record model."""
def setUp(self):
self.record = FormF6RecordFactory.create()
def test_record_creation(self):
"""Test record creation."""
self.assertIsNotNone(self.record.id)
self.assertIsNotNone(self.record.organization)
self.assertIsNotNone(self.record.row_code)
def test_record_str_representation(self):
"""Test string representation."""
expected = f"Ф-6: {self.record.organization} - {self.record.row_code}"
self.assertEqual(str(self.record), expected)
def test_organization_relationship(self):
"""Test organization FK relationship."""
self.assertIsNotNone(self.record.organization.inn)
def test_string_fields_max_length(self):
"""Test string fields max length."""
self.assertEqual(self.record._meta.get_field("row_code").max_length, 10)
self.assertEqual(self.record._meta.get_field("category").max_length, 200)
def test_integer_fields(self):
"""Test integer fields."""
self.assertIsInstance(self.record.total_equipment, int)
self.assertIsInstance(self.record.cnc_total, int)
def test_decimal_fields_precision(self):
"""Test decimal fields precision."""
field = self.record._meta.get_field("physical_wear_percent")
self.assertEqual(field.max_digits, 5)
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,80 @@
"""Tests for FormF6 services."""
from apps.form_6.services import FormF6Parser, FormF6Service
from django.test import TestCase
from tests.apps.organization.factories import OrganizationFactory
from .factories import FormF6RecordFactory
class FormF6ServiceTest(TestCase):
"""Tests for FormF6Service."""
def test_get_by_organization(self):
"""Test getting records by organization."""
org = OrganizationFactory.create()
FormF6RecordFactory.create(organization=org)
FormF6RecordFactory.create(organization=org)
FormF6RecordFactory.create()
results = FormF6Service.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-f6"
FormF6RecordFactory.create(load_batch=batch_id)
FormF6RecordFactory.create(load_batch=batch_id)
results = FormF6Service.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-f6"
FormF6RecordFactory.create(load_batch=batch_id)
FormF6RecordFactory.create(load_batch=batch_id)
other = FormF6RecordFactory.create(load_batch="keep-batch")
count = FormF6Service.delete_by_load_batch(batch_id)
self.assertEqual(count, 2)
from apps.form_6.models import FormF6Record
self.assertTrue(FormF6Record.objects.filter(pk=other.pk).exists())
class FormF6ParserTest(TestCase):
"""Tests for FormF6Parser."""
def test_get_column_mappings_returns_mappings(self):
"""Test get_column_mappings returns correct mappings."""
parser = FormF6Parser()
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("row_code", field_names)
self.assertIn("total_equipment", field_names)
def test_create_record_creates_organization(self):
"""Test create_record creates organization if not exists."""
parser = FormF6Parser()
parser.load_batch = "test-batch"
row_data = {
"inn": "6234567890",
"name": "Тестовая организация Ф-6",
"row_code": "001",
"category": "Металлорежущее",
"total_equipment": 100,
}
record = parser.create_record(row_data)
self.assertIsNotNone(record)
self.assertEqual(record.organization.inn, "6234567890")