feat: export state corp package from backup endpoint
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user