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/organization/__init__.py
Normal file
1
tests/apps/organization/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for organization app."""
|
||||
25
tests/apps/organization/factories.py
Normal file
25
tests/apps/organization/factories.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""Factories for organization app."""
|
||||
|
||||
import factory
|
||||
from apps.organization.models import Organization
|
||||
from faker import Faker
|
||||
|
||||
fake = Faker("ru_RU")
|
||||
|
||||
|
||||
class OrganizationFactory(factory.django.DjangoModelFactory):
|
||||
"""Factory for Organization model."""
|
||||
|
||||
class Meta:
|
||||
model = Organization
|
||||
|
||||
name = factory.LazyAttribute(lambda _: fake.company())
|
||||
inn = factory.LazyAttribute(lambda _: fake.numerify("##########"))
|
||||
ogrn = factory.LazyAttribute(lambda _: fake.numerify("#############"))
|
||||
kpp = factory.LazyAttribute(lambda _: fake.numerify("#########"))
|
||||
okpo = factory.LazyAttribute(lambda _: fake.numerify("########"))
|
||||
|
||||
@classmethod
|
||||
def create_organization(cls, **kwargs):
|
||||
"""Create organization with defaults."""
|
||||
return cls.create(**kwargs)
|
||||
52
tests/apps/organization/test_models.py
Normal file
52
tests/apps/organization/test_models.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Tests for Organization model."""
|
||||
|
||||
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)
|
||||
52
tests/apps/organization/test_services.py
Normal file
52
tests/apps/organization/test_services.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Tests for Organization services."""
|
||||
|
||||
from apps.organization.services import OrganizationService
|
||||
from django.test import TestCase
|
||||
|
||||
from .factories import OrganizationFactory
|
||||
|
||||
|
||||
class OrganizationServiceTest(TestCase):
|
||||
"""Tests for OrganizationService."""
|
||||
|
||||
def test_get_or_create_by_inn_creates_new(self):
|
||||
"""Test get_or_create_by_inn creates new organization."""
|
||||
org, created = OrganizationService.get_or_create_by_inn(
|
||||
inn="1234567890",
|
||||
defaults={"name": "Test Org", "ogrn": "1234567890123"},
|
||||
)
|
||||
self.assertTrue(created)
|
||||
self.assertEqual(org.inn, "1234567890")
|
||||
self.assertEqual(org.name, "Test Org")
|
||||
|
||||
def test_get_or_create_by_inn_returns_existing(self):
|
||||
"""Test get_or_create_by_inn returns existing organization."""
|
||||
existing = OrganizationFactory.create(inn="9876543210")
|
||||
|
||||
org, created = OrganizationService.get_or_create_by_inn(
|
||||
inn="9876543210",
|
||||
defaults={"name": "Different Name"},
|
||||
)
|
||||
self.assertFalse(created)
|
||||
self.assertEqual(org.pk, existing.pk)
|
||||
self.assertEqual(org.name, existing.name)
|
||||
|
||||
def test_get_by_inn_found(self):
|
||||
"""Test get_by_inn returns organization."""
|
||||
existing = OrganizationFactory.create(inn="5555555555")
|
||||
result = OrganizationService.get_by_inn("5555555555")
|
||||
self.assertEqual(result.pk, existing.pk)
|
||||
|
||||
def test_get_by_inn_not_found(self):
|
||||
"""Test get_by_inn returns None when not found."""
|
||||
result = OrganizationService.get_by_inn("0000000000")
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_search_by_name(self):
|
||||
"""Test search_by_name functionality."""
|
||||
OrganizationFactory.create(name="ООО Ромашка")
|
||||
OrganizationFactory.create(name="ООО Василек")
|
||||
OrganizationFactory.create(name="АО Ромашка-Плюс")
|
||||
|
||||
results = OrganizationService.search_by_name("Ромашка")
|
||||
self.assertEqual(results.count(), 2)
|
||||
Reference in New Issue
Block a user