feat: use authoritative organization directory
This commit is contained in:
@@ -22,13 +22,6 @@ from organizations.models import (
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
from tests.apps.registers.factories import (
|
||||
OrganizationFactory as RegistryOrganizationFactory,
|
||||
)
|
||||
from tests.apps.registers.factories import (
|
||||
RegisterFactory,
|
||||
RegistryMembershipPeriodFactory,
|
||||
)
|
||||
from tests.apps.user.factories import UserFactory
|
||||
|
||||
|
||||
@@ -241,9 +234,21 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
def test_source_records_endpoint_returns_requested_source_payload(self):
|
||||
organization = Organization.objects.create(
|
||||
name='ООО "Явные данные"',
|
||||
full_name='Общество с ограниченной ответственностью "Явные данные"',
|
||||
short_name='ООО "Явные данные"',
|
||||
gk_name="ГК Роскосмос",
|
||||
in_korp_name="Внутри корпорации",
|
||||
inn="7712345683",
|
||||
kpp="771201006",
|
||||
ogrn="1027700132201",
|
||||
okpo="12345678",
|
||||
filial=".F.",
|
||||
is_branch=False,
|
||||
legal_address="127000, Москва, ул. Тестовая, д. 1",
|
||||
business_activity="Производство испытательного оборудования",
|
||||
dep="Департамент промышленности",
|
||||
integrated_structure="Интегрированная структура",
|
||||
state_sector_name="Госсектор",
|
||||
)
|
||||
extension = IndustrialProductionExtension.objects.create(
|
||||
organization=organization,
|
||||
@@ -270,6 +275,32 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
response.data["data"][0]["payload"],
|
||||
{"certificate_number": "CERT-SOURCE-RECORDS"},
|
||||
)
|
||||
embedded_organization = response.data["data"][0]["organization"]
|
||||
self.assertEqual(
|
||||
embedded_organization["full_name"],
|
||||
'Общество с ограниченной ответственностью "Явные данные"',
|
||||
)
|
||||
self.assertEqual(embedded_organization["short_name"], 'ООО "Явные данные"')
|
||||
self.assertEqual(embedded_organization["normalized_name"], 'ООО "Явные данные"')
|
||||
self.assertEqual(embedded_organization["okpo"], "12345678")
|
||||
self.assertEqual(
|
||||
embedded_organization["legal_address"],
|
||||
"127000, Москва, ул. Тестовая, д. 1",
|
||||
)
|
||||
self.assertEqual(
|
||||
embedded_organization["business_activity"],
|
||||
"Производство испытательного оборудования",
|
||||
)
|
||||
self.assertEqual(embedded_organization["dep"], "Департамент промышленности")
|
||||
self.assertEqual(
|
||||
embedded_organization["integrated_structure"],
|
||||
"Интегрированная структура",
|
||||
)
|
||||
self.assertEqual(embedded_organization["gk_name"], "ГК Роскосмос")
|
||||
self.assertEqual(embedded_organization["in_korp_name"], "Внутри корпорации")
|
||||
self.assertEqual(embedded_organization["state_sector_name"], "Госсектор")
|
||||
self.assertEqual(embedded_organization["filial"], ".F.")
|
||||
self.assertEqual(embedded_organization["is_branch"], False)
|
||||
|
||||
def test_detail_returns_compact_source_summaries_by_default(self):
|
||||
organization = Organization.objects.create(
|
||||
@@ -483,7 +514,7 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
self.assertEqual(second_response["X-Cache"], "HIT")
|
||||
self.assertEqual(third_response["X-Cache"], "MISS")
|
||||
|
||||
def test_registry_update_invalidates_organization_cache(self):
|
||||
def test_explicit_invalidation_refreshes_organization_cache(self):
|
||||
Organization.objects.create(
|
||||
name='ООО "Реестр сброса"',
|
||||
inn="7744444447",
|
||||
@@ -495,8 +526,7 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
|
||||
first_response = self.client.get(url, params)
|
||||
second_response = self.client.get(url, params)
|
||||
with self.captureOnCommitCallbacks(execute=True):
|
||||
RegisterFactory(name="Реестр для сброса кеша")
|
||||
invalidate_organization_api_cache()
|
||||
third_response = self.client.get(url, params)
|
||||
|
||||
self.assertEqual(first_response["X-Cache"], "MISS")
|
||||
@@ -530,15 +560,9 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
inn="7777777777",
|
||||
kpp="777701001",
|
||||
ogrn="1027700132777",
|
||||
)
|
||||
registry = RegisterFactory(name="Росатом ГОЗ")
|
||||
registry_organization = RegistryOrganizationFactory(
|
||||
mn_inn=int(organization.inn),
|
||||
mn_ogrn=int(organization.ogrn),
|
||||
)
|
||||
RegistryMembershipPeriodFactory(
|
||||
registry=registry,
|
||||
organization=registry_organization,
|
||||
opk_registry_membership=True,
|
||||
ropk_razdel_num="opk-1",
|
||||
ropk_razdel_name="Росатом ГОЗ",
|
||||
)
|
||||
industrial = IndustrialProductionExtension.objects.create(
|
||||
organization=organization,
|
||||
@@ -647,7 +671,7 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
item = response.data["data"][0]
|
||||
self.assertEqual(
|
||||
item["registries"],
|
||||
[{"id": str(registry.id), "name": "Росатом ГОЗ"}],
|
||||
[{"id": "opk-1", "name": "Росатом ГОЗ"}],
|
||||
)
|
||||
self.assertNotIn("data_presence", item)
|
||||
self.assertNotIn("data", item)
|
||||
@@ -681,6 +705,9 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
inn="7788888888",
|
||||
kpp="778801001",
|
||||
ogrn="1027700132888",
|
||||
opk_registry_membership=True,
|
||||
ropk_razdel_num="opk-space",
|
||||
ropk_razdel_name="Роскосмос ОПК",
|
||||
)
|
||||
without_registry = Organization.objects.create(
|
||||
name='ООО "Без реестра"',
|
||||
@@ -688,19 +715,9 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
kpp="779901001",
|
||||
ogrn="1027700132999",
|
||||
)
|
||||
registry = RegisterFactory(name="Роскосмос ОПК")
|
||||
registry_organization = RegistryOrganizationFactory(
|
||||
mn_inn=int(with_registry.inn),
|
||||
mn_ogrn=int(with_registry.ogrn),
|
||||
)
|
||||
RegistryMembershipPeriodFactory(
|
||||
registry=registry,
|
||||
organization=registry_organization,
|
||||
)
|
||||
|
||||
by_registry = self.client.get(
|
||||
reverse("api_v2:organizations:organizations-list"),
|
||||
{"registry": str(registry.id)},
|
||||
{"registry": "opk-space"},
|
||||
)
|
||||
has_registry = self.client.get(
|
||||
reverse("api_v2:organizations:organizations-list"),
|
||||
@@ -730,7 +747,7 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
self.assertTrue(filterset.is_valid(), filterset.errors)
|
||||
sql = str(filterset.qs.query).upper()
|
||||
|
||||
self.assertIn(" IN ", sql)
|
||||
self.assertIn("OPK_REGISTRY_MEMBERSHIP", sql)
|
||||
self.assertNotIn("EXISTS", sql)
|
||||
|
||||
def test_list_defaults_to_has_registry_true(self):
|
||||
@@ -739,6 +756,9 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
inn="7800000101",
|
||||
kpp="780001101",
|
||||
ogrn="1027700133101",
|
||||
opk_registry_membership=True,
|
||||
ropk_razdel_num="default",
|
||||
ropk_razdel_name="Дефолтный реестр",
|
||||
)
|
||||
Organization.objects.create(
|
||||
name='ООО "Скрыто по дефолту"',
|
||||
@@ -746,16 +766,6 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
kpp="780001102",
|
||||
ogrn="1027700133102",
|
||||
)
|
||||
registry = RegisterFactory(name="Дефолтный реестр")
|
||||
registry_organization = RegistryOrganizationFactory(
|
||||
mn_inn=int(with_registry.inn),
|
||||
mn_ogrn=int(with_registry.ogrn),
|
||||
)
|
||||
RegistryMembershipPeriodFactory(
|
||||
registry=registry,
|
||||
organization=registry_organization,
|
||||
)
|
||||
|
||||
default_response = self.client.get(
|
||||
reverse("api_v2:organizations:organizations-list")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user