feat: export organizations to state corp v3
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
"""Tests for organizations API v2."""
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
from apps.parsers.models import ParserLoadLog
|
||||
from django.core.cache import cache
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import connection
|
||||
from django.test import override_settings
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
from django.urls import reverse
|
||||
from openpyxl import Workbook
|
||||
from organizations.cache import invalidate_organization_api_cache
|
||||
from organizations.directory_import import DIRECTORY_SHEET, SOURCE_HEADERS
|
||||
from organizations.filters import OrganizationFilter
|
||||
from organizations.models import (
|
||||
FinancialIndicatorsExtension,
|
||||
@@ -19,6 +24,7 @@ from organizations.models import (
|
||||
SecurityRegistryExtension,
|
||||
VacancyExtension,
|
||||
)
|
||||
from registers.models import Organization as LegacyRegisterOrganization
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
|
||||
@@ -33,6 +39,17 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
self.user = UserFactory.create_user()
|
||||
self.client.force_authenticate(self.user)
|
||||
|
||||
@staticmethod
|
||||
def _append_reference_sheet(
|
||||
workbook: Workbook,
|
||||
title: str,
|
||||
values: dict[str, str],
|
||||
) -> None:
|
||||
worksheet = workbook.create_sheet(title=title)
|
||||
worksheet.append(["kod", "value"])
|
||||
for key, value in values.items():
|
||||
worksheet.append([key, value])
|
||||
|
||||
def test_list_is_paginated_and_available_only_under_v2(self):
|
||||
Organization.objects.create(
|
||||
name='ООО "Альфа"',
|
||||
@@ -60,6 +77,73 @@ class OrganizationsApiV2Test(APITestCase):
|
||||
v1_response = self.client.get("/api/v1/organizations/")
|
||||
self.assertEqual(v1_response.status_code, status.HTTP_404_NOT_FOUND)
|
||||
|
||||
def test_admin_import_directory_uploads_xlsx_into_canonical_organizations(self):
|
||||
self.client.force_authenticate(UserFactory.create_superuser())
|
||||
workbook = Workbook()
|
||||
worksheet = workbook.active
|
||||
worksheet.title = DIRECTORY_SHEET
|
||||
worksheet.append(SOURCE_HEADERS)
|
||||
worksheet.append(
|
||||
[
|
||||
{
|
||||
"rn": "10",
|
||||
"_gk": "1",
|
||||
"in_korp": "1",
|
||||
"full_name": 'Акционерное общество "Тест"',
|
||||
"short_name": 'АО "Тест"',
|
||||
"pn_name": 'АО "Тест"',
|
||||
"inn": "7701001001",
|
||||
"ogrn": "1027700100001",
|
||||
"okpo": "00123456",
|
||||
"filial": ".F.",
|
||||
"kpp": "770101001",
|
||||
"registration_date": "01.02.2020",
|
||||
"authorized_capita": 1000,
|
||||
"business_act_cod": "2",
|
||||
"goz_participation": ".T.",
|
||||
"opk_registry_membership": ".F.",
|
||||
"_k": "2",
|
||||
}.get(header, "")
|
||||
for header in SOURCE_HEADERS
|
||||
]
|
||||
)
|
||||
self._append_reference_sheet(workbook, "_gk", {"1": "Роскосмос"})
|
||||
self._append_reference_sheet(workbook, "in_korp", {"1": "Входит в состав"})
|
||||
self._append_reference_sheet(
|
||||
workbook,
|
||||
"business_act_cod",
|
||||
{"2": "Производственная"},
|
||||
)
|
||||
self._append_reference_sheet(
|
||||
workbook,
|
||||
"_k - Госектор",
|
||||
{"2": "Головные исполнители"},
|
||||
)
|
||||
buffer = BytesIO()
|
||||
workbook.save(buffer)
|
||||
upload = SimpleUploadedFile(
|
||||
"directory.xlsx",
|
||||
buffer.getvalue(),
|
||||
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("api_v2:organizations:organizations-import-directory"),
|
||||
{"file": upload},
|
||||
format="multipart",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.data["success"], True)
|
||||
self.assertEqual(response.data["created"], 1)
|
||||
self.assertEqual(LegacyRegisterOrganization.objects.count(), 0)
|
||||
organization = Organization.objects.get(rn=10)
|
||||
self.assertEqual(organization.name, 'Акционерное общество "Тест"')
|
||||
self.assertEqual(organization.inn, "7701001001")
|
||||
self.assertEqual(organization.gk_name, "Роскосмос")
|
||||
self.assertEqual(organization.business_activity, "Производственная")
|
||||
self.assertTrue(organization.goz_participation)
|
||||
|
||||
def test_openapi_documents_v2_organizations_endpoints(self):
|
||||
response = self.client.get(
|
||||
reverse("schema-swagger-ui"),
|
||||
|
||||
Reference in New Issue
Block a user