Add organizations v2 API and registry enrichment
This commit is contained in:
143
tests/apps/organizations/test_populate_command.py
Normal file
143
tests/apps/organizations/test_populate_command.py
Normal file
@@ -0,0 +1,143 @@
|
||||
"""Tests for populate_organizations command."""
|
||||
|
||||
from apps.parsers.models import GenericParserRecord, ProcurementRecord
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from organizations.models import Organization
|
||||
from registers.models import Organization as RegisterOrganization
|
||||
|
||||
|
||||
class PopulateOrganizationsCommandTest(TestCase):
|
||||
"""Checks idempotent organization population from existing DB records."""
|
||||
|
||||
def test_command_populates_from_registers_and_parser_records(self):
|
||||
RegisterOrganization.objects.create(
|
||||
pn_name='Общество с ограниченной ответственностью "Ромашка"',
|
||||
mn_inn=7707083893,
|
||||
mn_ogrn=1027700132195,
|
||||
in_kpp=770701001,
|
||||
mn_okpo="12345678",
|
||||
)
|
||||
ProcurementRecord.objects.create(
|
||||
load_batch=1,
|
||||
purchase_number="001",
|
||||
purchase_name="Поставка",
|
||||
customer_inn="7707083893",
|
||||
customer_kpp="770701001",
|
||||
customer_ogrn="1027700132195",
|
||||
customer_name='OOO "Ромашка"',
|
||||
)
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="arbitration",
|
||||
external_id="name-only-1",
|
||||
organisation_name='ООО "Ромашка"',
|
||||
)
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="name-only-2",
|
||||
organisation_name="ИП Иванов Иван Иванович",
|
||||
inn="500100732259",
|
||||
ogrn="304500116000157",
|
||||
)
|
||||
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
|
||||
self.assertEqual(Organization.objects.count(), 2)
|
||||
|
||||
legal_entity = Organization.objects.get(inn="7707083893")
|
||||
self.assertEqual(legal_entity.name, 'Общество с ограниченной ответственностью "Ромашка"')
|
||||
self.assertEqual(legal_entity.kpp, "770701001")
|
||||
self.assertEqual(legal_entity.ogrn, "1027700132195")
|
||||
self.assertEqual(legal_entity.ogrip, "")
|
||||
|
||||
entrepreneur = Organization.objects.get(inn="500100732259")
|
||||
self.assertEqual(entrepreneur.name, "ИП Иванов Иван Иванович")
|
||||
self.assertEqual(entrepreneur.kpp, "")
|
||||
self.assertEqual(entrepreneur.ogrn, "")
|
||||
self.assertEqual(entrepreneur.ogrip, "304500116000157")
|
||||
|
||||
def test_command_merges_name_only_ooo_variants(self):
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="arbitration",
|
||||
external_id="name-only-1",
|
||||
organisation_name='OOO "Ромашка"',
|
||||
)
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="name-only-2",
|
||||
organisation_name="Общество с ограниченной ответственностью Ромашка",
|
||||
)
|
||||
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
|
||||
self.assertEqual(Organization.objects.count(), 1)
|
||||
self.assertEqual(Organization.objects.get().name, "Общество с ограниченной ответственностью Ромашка")
|
||||
|
||||
def test_command_populates_kpp_from_generic_payload_company(self):
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="generic-with-kpp",
|
||||
organisation_name='ООО "Источник"',
|
||||
inn="7707083893",
|
||||
ogrn="1027700132195",
|
||||
payload={"company": {"kpp": "770701001"}},
|
||||
)
|
||||
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
|
||||
organization = Organization.objects.get(inn="7707083893")
|
||||
self.assertEqual(organization.kpp, "770701001")
|
||||
|
||||
def test_command_keeps_same_inn_different_kpp_as_distinct_branches(self):
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="branch-1",
|
||||
organisation_name='ООО "Источник"',
|
||||
inn="7707083893",
|
||||
ogrn="1027700132195",
|
||||
payload={"company": {"kpp": "770701001"}},
|
||||
)
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="branch-2",
|
||||
organisation_name='ООО "Источник"',
|
||||
inn="7707083893",
|
||||
ogrn="1027700132195",
|
||||
payload={"company": {"kpp": "780101001"}},
|
||||
)
|
||||
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
|
||||
self.assertEqual(
|
||||
set(Organization.objects.filter(inn="7707083893").values_list("kpp", flat=True)),
|
||||
{"770701001", "780101001"},
|
||||
)
|
||||
|
||||
def test_command_updates_existing_blank_kpp_organization_from_branch_candidate(self):
|
||||
Organization.objects.create(
|
||||
name='ООО "Источник"',
|
||||
inn="7707083893",
|
||||
ogrn="1027700132195",
|
||||
)
|
||||
GenericParserRecord.objects.create(
|
||||
load_batch=1,
|
||||
source="trudvsem",
|
||||
external_id="branch-with-kpp",
|
||||
organisation_name='ООО "Источник"',
|
||||
inn="7707083893",
|
||||
ogrn="1027700132195",
|
||||
payload={"company": {"kpp": "770701001"}},
|
||||
)
|
||||
|
||||
call_command("populate_organizations", silent=True, verbosity=0)
|
||||
|
||||
self.assertEqual(Organization.objects.filter(inn="7707083893").count(), 1)
|
||||
self.assertEqual(Organization.objects.get(inn="7707083893").kpp, "770701001")
|
||||
Reference in New Issue
Block a user