feat: export state corp package from backup endpoint
Some checks failed
CI/CD Pipeline / Quality Gate (push) Successful in 33s
CI/CD Pipeline / Build and Push Images (push) Successful in 10s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Failing after 9s

This commit is contained in:
2026-05-12 15:12:56 +02:00
parent 15360a3c8e
commit 75c1d4cf1a
11 changed files with 925 additions and 301 deletions

View File

@@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patch
from apps.core.models import BackgroundJob, JobStatus
from apps.parsers.models import GenericParserRecord, ParserLoadLog
from apps.parsers.source_cards import (
SOURCE_CARD_DEFINITIONS,
SourceCardDefinition,
SourceCardService,
SourceItemDefinition,
@@ -18,6 +19,36 @@ from rest_framework.exceptions import ValidationError
class SourceCardServiceUnitTest(SimpleTestCase):
def test_list_cards_exposes_all_frontend_category_slugs_in_menu_order(self):
self.assertEqual(
[card.slug for card in SOURCE_CARD_DEFINITIONS],
[
"financial-indicators",
"public-procurements",
"manufacturers-and-products",
"planned-inspections",
"bankruptcy-procedures",
"defense-unreliable-suppliers",
"arbitration-cases",
"information-security-registries",
"labor-vacancies",
],
)
self.assertEqual(
[card.title for card in SOURCE_CARD_DEFINITIONS],
[
"Финансово-экономические показатели",
"Государственные закупки по 44-ФЗ и 223-ФЗ",
"Производители и продукция России",
"Плановые проверки Генпрокуратуры России",
"Сведения о процедурах банкротства",
"Недобросовестные поставщики ГОЗ",
"Арбитражные дела",
"Реестры по информационной безопасности",
"Вакансии Работа России",
],
)
def test_get_definition_raises_for_unknown_slug(self):
with self.assertRaises(Http404):
SourceCardService.get_definition("missing-card")
@@ -156,6 +187,40 @@ class SourceCardServiceUnitTest(SimpleTestCase):
},
)
@patch(
"apps.parsers.source_cards.SourceCardService._enqueue_task",
side_effect=[
{
"task_id": "task-unfair",
"task_name": "apps.parsers.tasks.parse_unfair_suppliers",
},
{
"task_id": "task-goz",
"task_name": "apps.parsers.tasks.parse_fas_goz_evasion",
},
],
)
def test_refresh_card_for_defense_unreliable_suppliers_enqueues_sources(
self, enqueue_mock
):
result = SourceCardService.refresh_card(
slug="defense-unreliable-suppliers",
requested_by_id=10,
)
self.assertEqual(result["source_card"], "defense-unreliable-suppliers")
self.assertEqual(
[item["task_id"] for item in result["tasks"]],
["task-unfair", "task-goz"],
)
self.assertEqual(
[call.kwargs["meta"]["source"] for call in enqueue_mock.call_args_list],
[
ParserLoadLog.Source.UNFAIR_SUPPLIERS,
ParserLoadLog.Source.FAS_GOZ,
],
)
def test_launch_refresh_raises_for_unsupported_card(self):
definition = SourceCardDefinition(
slug="custom-source",
@@ -297,6 +362,42 @@ class SourceCardServiceUnitTest(SimpleTestCase):
@override_settings(PARSER_STALE_LOAD_MAX_AGE_MINUTES=90)
class SourceCardServiceDatabaseTest(TestCase):
def test_defense_unreliable_suppliers_counts_unique_generic_organizations(self):
GenericParserRecord.objects.create(
source=ParserLoadLog.Source.UNFAIR_SUPPLIERS,
load_batch=1,
external_id="unfair-1",
inn="7701234567",
title="Недобросовестный поставщик",
payload={"number": "unfair-1"},
)
GenericParserRecord.objects.create(
source=ParserLoadLog.Source.FAS_GOZ,
load_batch=1,
external_id="goz-1",
inn="7701234567",
title="Уклонение от ГОЗ",
payload={"number": "goz-1"},
)
ParserLoadLog.objects.create(
source=ParserLoadLog.Source.UNFAIR_SUPPLIERS,
batch_id=1,
records_count=1,
status=ParserLoadLog.Status.SUCCESS,
)
ParserLoadLog.objects.create(
source=ParserLoadLog.Source.FAS_GOZ,
batch_id=1,
records_count=1,
status=ParserLoadLog.Status.SUCCESS,
)
card = SourceCardService.get_card("defense-unreliable-suppliers")
self.assertEqual(card["status"], "success")
self.assertEqual(card["records_count"], 2)
self.assertEqual(card["organizations_count"], 1)
def test_public_procurements_counts_generic_eis_sources(self):
GenericParserRecord.objects.create(
source=ParserLoadLog.Source.PROCUREMENTS_44FZ,

View File

@@ -249,7 +249,9 @@ class GenericSourceFetchTestCase(TestCase):
)
RegistryMembershipPeriodFactory(organization=organization, ended_at=None)
RegistryMembershipPeriodFactory(
organization=inactive, ended_at=date(2026, 5, 7)
organization=inactive,
started_at=date(2026, 5, 1),
ended_at=date(2026, 5, 7),
)
captured_inns = []
@@ -317,7 +319,9 @@ class GenericSourceFetchTestCase(TestCase):
)
RegistryMembershipPeriodFactory(organization=organization, ended_at=None)
RegistryMembershipPeriodFactory(
organization=inactive, ended_at=date(2026, 5, 7)
organization=inactive,
started_at=date(2026, 5, 1),
ended_at=date(2026, 5, 7),
)
class _CheckoClient:
@@ -448,7 +452,9 @@ class GenericSourceFetchTestCase(TestCase):
)
RegistryMembershipPeriodFactory(organization=organization, ended_at=None)
RegistryMembershipPeriodFactory(
organization=inactive, ended_at=date(2026, 5, 7)
organization=inactive,
started_at=date(2026, 5, 1),
ended_at=date(2026, 5, 7),
)
class _CheckoClient:
@@ -523,7 +529,9 @@ class GenericSourceFetchTestCase(TestCase):
)
RegistryMembershipPeriodFactory(organization=organization, ended_at=None)
RegistryMembershipPeriodFactory(
organization=inactive, ended_at=date(2026, 5, 7)
organization=inactive,
started_at=date(2026, 5, 1),
ended_at=date(2026, 5, 7),
)
class _CheckoClient:
@@ -2021,7 +2029,9 @@ class ParseVacanciesTaskTestCase(TestCase):
RegistryMembershipPeriodFactory(organization=active_first, ended_at=None)
RegistryMembershipPeriodFactory(organization=active_second, ended_at=None)
RegistryMembershipPeriodFactory(
organization=inactive, ended_at=date(2026, 5, 7)
organization=inactive,
started_at=date(2026, 5, 1),
ended_at=date(2026, 5, 7),
)
RegistryMembershipPeriodFactory(organization=active_first, ended_at=None)
captured_fetches = []