feat: expose FSSP source APIs and exports
This commit is contained in:
@@ -132,3 +132,23 @@ def test_iterator_does_not_read_next_row_until_requested():
|
||||
assert next(iterator).inn == "7707083893"
|
||||
with pytest.raises(SnapshotValidationError):
|
||||
next(iterator)
|
||||
|
||||
|
||||
def test_real_ended_iso_date_and_publisher_reason_labels():
|
||||
row = next(
|
||||
records(
|
||||
fixture_text(
|
||||
"ended.csv",
|
||||
**{
|
||||
"Date, complete IP reason": "2025-10-25, ст. 46 п. 1 п.п. 4",
|
||||
},
|
||||
),
|
||||
dataset=ENDED,
|
||||
)
|
||||
)
|
||||
assert row.payload["terminated_on"] == "2025-10-25"
|
||||
assert row.payload["termination_article"] == "46"
|
||||
assert row.payload["termination_part"] is None
|
||||
assert row.payload["termination_point"] is None
|
||||
assert "unparsed_termination" in row.payload["parse_warnings"]
|
||||
assert row.payload["termination_raw"] == "2025-10-25, ст. 46 п. 1 п.п. 4"
|
||||
|
||||
73
tests/apps/parsers/test_fssp_refresh.py
Normal file
73
tests/apps/parsers/test_fssp_refresh.py
Normal file
@@ -0,0 +1,73 @@
|
||||
"""Two entrypoints, one FSSP task, no caller-supplied download location."""
|
||||
|
||||
from importlib import import_module
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from apps.core.models import BackgroundJob
|
||||
from apps.parsers.source_cards import SourceCardService
|
||||
from core.celery import app as celery_app
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from tests.apps.user.factories import UserFactory
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_refresh_and_run_share_one_job_and_reject_second_run():
|
||||
import_module("apps.parsers.tasks")
|
||||
assert "parsers.fssp_enforcement_proceedings.refresh" in celery_app.tasks
|
||||
task = celery_app.tasks["parsers.fssp_enforcement_proceedings.refresh"]
|
||||
client = APIClient()
|
||||
client.force_authenticate(UserFactory.create_user(is_staff=True))
|
||||
with patch.object(task, "apply_async"):
|
||||
first = client.post(
|
||||
"/api/v1/sources/fssp-enforcement-proceedings/refresh/", {}, format="json"
|
||||
)
|
||||
assert first.status_code == 202, first.data
|
||||
second = client.post(
|
||||
"/api/v1/parsers/run/fssp_enforcement_proceedings/", {}, format="json"
|
||||
)
|
||||
assert second.status_code == 409, second.data
|
||||
assert BackgroundJob.objects.count() == 1
|
||||
assert SourceCardService.get_parser_sources_by_card_slug(
|
||||
"fssp-enforcement-proceedings"
|
||||
) == ["fssp_enforcement_proceedings"]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_refresh_permissions_and_no_download_location():
|
||||
client = APIClient()
|
||||
client.force_authenticate(UserFactory.create_user())
|
||||
urls = (
|
||||
"/api/v1/sources/fssp-enforcement-proceedings/refresh/",
|
||||
"/api/v1/parsers/run/fssp_enforcement_proceedings/",
|
||||
)
|
||||
for url in urls:
|
||||
assert client.post(url, {}, format="json").status_code == 403
|
||||
client.force_authenticate(UserFactory.create_user(is_staff=True))
|
||||
for url in urls:
|
||||
response = client.post(
|
||||
url, {"params": {"file_url": "https://foreign.invalid"}}, format="json"
|
||||
)
|
||||
assert response.status_code == 400, response.data
|
||||
assert BackgroundJob.objects.count() == 0
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_fssp_unknown_total_progress_does_not_report_completion():
|
||||
from apps.core.models import JobStatus
|
||||
from apps.parsers.tasks_registry_snapshots import _update_snapshot_progress
|
||||
|
||||
job = BackgroundJob.objects.create(
|
||||
task_id="fssp-progress",
|
||||
task_name="parsers.fssp_enforcement_proceedings.refresh",
|
||||
status=JobStatus.STARTED,
|
||||
meta={"source": "fssp_enforcement_proceedings"},
|
||||
)
|
||||
_update_snapshot_progress(job, 10000, 0, 12, 3)
|
||||
job.refresh_from_db()
|
||||
assert job.progress == 5
|
||||
assert job.meta["raw_records_count"] == 10000
|
||||
assert job.meta["matched_records_count"] == 12
|
||||
assert job.meta["quarantined_records_count"] == 3
|
||||
assert "организаций" not in job.progress_message
|
||||
@@ -79,6 +79,15 @@ class FsspSnapshotTests(TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_invalid_canonical_requisites_are_quarantined(self):
|
||||
self.org.ogrn = "bad"
|
||||
self.org.okpo = "1234567890"
|
||||
self.org.save()
|
||||
artifact, result = self.run_import()
|
||||
assert result.published == 0
|
||||
assert result.quarantined == 2
|
||||
assert artifact.metadata["reasons"]["invalid_canonical_requisites"] == 2
|
||||
|
||||
def test_two_inputs_manifest_and_stable_uid(self):
|
||||
artifact, result = self.run_import()
|
||||
assert result.parsed == 2
|
||||
|
||||
@@ -34,6 +34,7 @@ def _parallel(actions):
|
||||
("sme-support-recipients-registry", "fns_sme_support_recipients"),
|
||||
("budget-process-registry", "budget_ubpandnubp"),
|
||||
("sro-membership-check", "sro_membership_check"),
|
||||
("fssp-enforcement-proceedings", "fssp_enforcement_proceedings"),
|
||||
],
|
||||
)
|
||||
def test_two_simultaneous_refreshes_dispatch_exactly_one_task(slug, source):
|
||||
|
||||
@@ -24,6 +24,12 @@ from rest_framework.test import APIClient
|
||||
from tests.apps.user.factories import UserFactory
|
||||
|
||||
SOURCES = (
|
||||
(
|
||||
"fssp-enforcement-proceedings",
|
||||
"fssp_enforcement_proceedings",
|
||||
"enforcement_proceedings",
|
||||
"enforcement_proceeding",
|
||||
),
|
||||
(
|
||||
"budget-process-registry",
|
||||
"budget_ubpandnubp",
|
||||
|
||||
@@ -97,6 +97,7 @@ class SourceCardServiceUnitTest(TestCase):
|
||||
"sro-membership-check",
|
||||
"integrated-structure-documents",
|
||||
"fedresurs-company-profile",
|
||||
"fssp-enforcement-proceedings",
|
||||
],
|
||||
)
|
||||
self.assertEqual(
|
||||
@@ -119,6 +120,7 @@ class SourceCardServiceUnitTest(TestCase):
|
||||
"Проверка членства в СРО",
|
||||
"Документы интегрированных структур",
|
||||
"Федресурс: сведения о юридических лицах",
|
||||
"ФССП: Банк данных исполнительных производств",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user