Files
state-corp-backend/tests/apps/organization/test_services.py
Aleksandr Meshchriakov d1b0cd7945
All checks were successful
CI/CD Pipeline / Run Tests (push) Successful in 6m12s
CI/CD Pipeline / Code Quality Checks (push) Successful in 6m19s
CI/CD Pipeline / Build Docker Images (push) Successful in 2m21s
CI/CD Pipeline / Push to Gitea Registry (push) Successful in 1s
CI/CD Pipeline / Deploy to Server (push) Successful in 1s
feat: import mostovik exchange sections
2026-05-27 23:13:40 +02:00

54 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Tests for Organization services."""
from apps.organization.models import Organization
from apps.organization.services import OrganizationNotFoundError, OrganizationService
from django.test import TestCase
from .factories import OrganizationFactory
class OrganizationServiceTest(TestCase):
"""Tests for OrganizationService."""
def test_get_or_create_by_inn_rejects_missing_organization(self):
"""OrganizationService must not create organizations outside exchange import."""
with self.assertRaises(OrganizationNotFoundError):
OrganizationService.get_or_create_by_inn(
inn="1234567890",
defaults={"name": "Test Org", "ogrn": "1234567890123"},
)
self.assertEqual(Organization.objects.count(), 0)
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)