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_3/__init__.py
Normal file
1
tests/apps/form_3/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for form_3 app."""
|
||||
34
tests/apps/form_3/factories.py
Normal file
34
tests/apps/form_3/factories.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Factories for form_3 app."""
|
||||
|
||||
import factory
|
||||
from apps.form_3.models import FormF3Record
|
||||
from faker import Faker
|
||||
|
||||
from tests.apps.organization.factories import OrganizationFactory
|
||||
|
||||
fake = Faker("ru_RU")
|
||||
|
||||
|
||||
class FormF3RecordFactory(factory.django.DjangoModelFactory):
|
||||
"""Factory for FormF3Record model."""
|
||||
|
||||
class Meta:
|
||||
model = FormF3Record
|
||||
|
||||
organization = factory.SubFactory(OrganizationFactory)
|
||||
load_batch = factory.LazyAttribute(lambda _: fake.uuid4())
|
||||
|
||||
# Кадры
|
||||
avg_employees = factory.LazyAttribute(lambda _: fake.random_int(min=50, max=5000))
|
||||
production_workers = factory.LazyAttribute(lambda _: fake.random_int(min=20, max=3000))
|
||||
engineering_workers = factory.LazyAttribute(lambda _: fake.random_int(min=10, max=500))
|
||||
administrative_workers = factory.LazyAttribute(lambda _: fake.random_int(min=5, max=300))
|
||||
|
||||
# Оборудование
|
||||
total_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=10, max=1000))
|
||||
domestic_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=5, max=500))
|
||||
imported_equipment = factory.LazyAttribute(lambda _: fake.random_int(min=5, max=500))
|
||||
|
||||
# Износ
|
||||
physical_wear_percent = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))
|
||||
utilization_rate = factory.LazyAttribute(lambda _: fake.pydecimal(min_value=0, max_value=100, left_digits=3, right_digits=2))
|
||||
42
tests/apps/form_3/test_models.py
Normal file
42
tests/apps/form_3/test_models.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Tests for FormF3 model."""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .factories import FormF3RecordFactory
|
||||
|
||||
|
||||
class FormF3RecordModelTest(TestCase):
|
||||
"""Tests for FormF3Record model."""
|
||||
|
||||
def setUp(self):
|
||||
self.record = FormF3RecordFactory.create()
|
||||
|
||||
def test_record_creation(self):
|
||||
"""Test record creation."""
|
||||
self.assertIsNotNone(self.record.id)
|
||||
self.assertIsNotNone(self.record.organization)
|
||||
self.assertIsNotNone(self.record.avg_employees)
|
||||
|
||||
def test_record_str_representation(self):
|
||||
"""Test string representation."""
|
||||
expected = f"Ф-3: {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_integer_fields(self):
|
||||
"""Test integer fields."""
|
||||
self.assertIsInstance(self.record.avg_employees, int)
|
||||
self.assertIsInstance(self.record.total_equipment, 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)
|
||||
79
tests/apps/form_3/test_services.py
Normal file
79
tests/apps/form_3/test_services.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Tests for FormF3 services."""
|
||||
|
||||
from apps.form_3.services import FormF3Parser, FormF3Service
|
||||
from django.test import TestCase
|
||||
|
||||
from tests.apps.organization.factories import OrganizationFactory
|
||||
|
||||
from .factories import FormF3RecordFactory
|
||||
|
||||
|
||||
class FormF3ServiceTest(TestCase):
|
||||
"""Tests for FormF3Service."""
|
||||
|
||||
def test_get_by_organization(self):
|
||||
"""Test getting records by organization."""
|
||||
org = OrganizationFactory.create()
|
||||
FormF3RecordFactory.create(organization=org)
|
||||
FormF3RecordFactory.create(organization=org)
|
||||
FormF3RecordFactory.create()
|
||||
|
||||
results = FormF3Service.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-f3"
|
||||
FormF3RecordFactory.create(load_batch=batch_id)
|
||||
FormF3RecordFactory.create(load_batch=batch_id)
|
||||
|
||||
results = FormF3Service.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-f3"
|
||||
FormF3RecordFactory.create(load_batch=batch_id)
|
||||
FormF3RecordFactory.create(load_batch=batch_id)
|
||||
other = FormF3RecordFactory.create(load_batch="keep-batch")
|
||||
|
||||
count = FormF3Service.delete_by_load_batch(batch_id)
|
||||
self.assertEqual(count, 2)
|
||||
|
||||
from apps.form_3.models import FormF3Record
|
||||
|
||||
self.assertTrue(FormF3Record.objects.filter(pk=other.pk).exists())
|
||||
|
||||
|
||||
class FormF3ParserTest(TestCase):
|
||||
"""Tests for FormF3Parser."""
|
||||
|
||||
def test_get_column_mappings_returns_mappings(self):
|
||||
"""Test get_column_mappings returns correct mappings."""
|
||||
parser = FormF3Parser()
|
||||
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("avg_employees", field_names)
|
||||
self.assertIn("total_equipment", field_names)
|
||||
|
||||
def test_create_record_creates_organization(self):
|
||||
"""Test create_record creates organization if not exists."""
|
||||
parser = FormF3Parser()
|
||||
parser.load_batch = "test-batch"
|
||||
|
||||
row_data = {
|
||||
"inn": "3234567890",
|
||||
"name": "Тестовая организация Ф-3",
|
||||
"avg_employees": 100,
|
||||
"total_equipment": 50,
|
||||
}
|
||||
|
||||
record = parser.create_record(row_data)
|
||||
|
||||
self.assertIsNotNone(record)
|
||||
self.assertEqual(record.organization.inn, "3234567890")
|
||||
Reference in New Issue
Block a user