Files
state-corp-backend/tests/apps/organization/test_models.py
Aleksandr Meshchriakov 345b1d0cc8
Some checks failed
CI/CD Pipeline / Run Tests (push) Failing after 45s
CI/CD Pipeline / Code Quality Checks (push) Failing after 48s
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
Add initial implementations for forms and organization apps with serializers, factories, and admin configurations
2026-03-28 18:23:06 +01:00

93 lines
3.3 KiB
Python

"""Tests for Organization model."""
from datetime import date
from apps.registers.models import Register, RegisterUpload, RegistryMembershipPeriod
from django.test import TestCase
from .factories import OrganizationFactory
class OrganizationModelTest(TestCase):
"""Tests for Organization model."""
def setUp(self):
self.org = OrganizationFactory.create()
def test_organization_creation(self):
"""Test organization creation."""
self.assertIsNotNone(self.org.id)
self.assertTrue(self.org.name)
self.assertTrue(self.org.inn)
def test_organization_str_representation(self):
"""Test string representation."""
expected = f"{self.org.name} (ИНН: {self.org.inn})"
self.assertEqual(str(self.org), expected)
def test_inn_unique(self):
"""Test INN field is unique."""
self.assertTrue(self.org._meta.get_field("inn").unique)
def test_inn_max_length(self):
"""Test INN max length."""
self.assertEqual(self.org._meta.get_field("inn").max_length, 12)
def test_ogrn_max_length(self):
"""Test OGRN max length."""
self.assertEqual(self.org._meta.get_field("ogrn").max_length, 15)
def test_kpp_max_length(self):
"""Test KPP max length."""
self.assertEqual(self.org._meta.get_field("kpp").max_length, 9)
def test_name_max_length(self):
"""Test name max length."""
self.assertEqual(self.org._meta.get_field("name").max_length, 500)
def test_timestamps_auto_created(self):
"""Test timestamps are auto-created."""
self.assertIsNotNone(self.org.created_at)
self.assertIsNotNone(self.org.updated_at)
def test_ogrn_index_exists(self):
"""Test OGRN has db_index."""
self.assertTrue(self.org._meta.get_field("ogrn").db_index)
def test_active_registry_names_include_only_current_memberships(self):
"""Test only active registry memberships are shown on organization."""
active_register = Register.objects.create(name="Активный реестр")
inactive_register = Register.objects.create(name="Неактуальный реестр")
active_upload = RegisterUpload.objects.create(
registry=active_register,
actual_date=date(2026, 3, 1),
file_name="active.xlsx",
file_hash="active-hash",
rows_count=1,
)
inactive_upload = RegisterUpload.objects.create(
registry=inactive_register,
actual_date=date(2026, 2, 1),
file_name="inactive.xlsx",
file_hash="inactive-hash",
rows_count=1,
)
RegistryMembershipPeriod.objects.create(
registry=active_register,
organization=self.org,
started_at=date(2026, 3, 1),
started_by_upload=active_upload,
)
RegistryMembershipPeriod.objects.create(
registry=inactive_register,
organization=self.org,
started_at=date(2026, 2, 1),
ended_at=date(2026, 3, 1),
started_by_upload=inactive_upload,
ended_by_upload=inactive_upload,
)
self.assertEqual(self.org.get_active_registry_names(), ["Активный реестр"])
self.assertEqual(self.org.active_registry_names_display(), "Активный реестр")