fix: implement backend testing amendments and atomic source publication
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m16s
Mostovik Backend CI/CD / Deploy dev (push) Has been cancelled
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been cancelled
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been cancelled
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m16s
Mostovik Backend CI/CD / Deploy dev (push) Has been cancelled
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been cancelled
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been cancelled
This commit is contained in:
386
tests/apps/parsers/test_aggregate_publication.py
Normal file
386
tests/apps/parsers/test_aggregate_publication.py
Normal file
@@ -0,0 +1,386 @@
|
||||
"""A composed refresh exposes all parts together or preserves the old records."""
|
||||
from unittest.mock import patch
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from apps.core.models import BackgroundJob
|
||||
from apps.parsers.aggregate_publication import finish_part
|
||||
from apps.parsers.models import ParserLoadLog, ParserRefreshRun, ParserRefreshStage
|
||||
from apps.parsers.source_cards import SourceCardService
|
||||
from organizations.models import Organization, OrganizationSourceRecord
|
||||
from organizations.source_ingestion import (
|
||||
OrganizationSourceIngestionService,
|
||||
SourceRecordInput,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run(db):
|
||||
organization = Organization.objects.create(
|
||||
name="Factory",
|
||||
inn="7707083810",
|
||||
directory_imported_at="2026-10-09T00:00:00Z",
|
||||
opk_registry_membership=True,
|
||||
)
|
||||
tasks = {"industrial": str(uuid4()), "manufactures": str(uuid4())}
|
||||
run = ParserRefreshRun.objects.create(
|
||||
source_card="manufacturers-and-products", tasks=tasks
|
||||
)
|
||||
jobs = {}
|
||||
logs = {}
|
||||
for source, task_id in tasks.items():
|
||||
jobs[source] = BackgroundJob.objects.create(
|
||||
task_id=task_id,
|
||||
task_name=f"test.{source}",
|
||||
meta={
|
||||
"source": source,
|
||||
"aggregate_refresh_id": str(run.pk),
|
||||
"source_card": run.source_card,
|
||||
"refresh_task_ids": list(tasks.values()),
|
||||
},
|
||||
)
|
||||
jobs[source].mark_started()
|
||||
logs[source] = ParserLoadLog.objects.create(
|
||||
source=source, batch_id=1, status="in_progress"
|
||||
)
|
||||
OrganizationSourceIngestionService.save_records(
|
||||
source=source,
|
||||
load_batch=0,
|
||||
records=[
|
||||
SourceRecordInput(
|
||||
external_id="old",
|
||||
title="Old",
|
||||
organization_name=organization.name,
|
||||
inn=organization.inn,
|
||||
)
|
||||
],
|
||||
)
|
||||
return run, jobs, logs, organization
|
||||
|
||||
|
||||
def stage(run, source, organization):
|
||||
return OrganizationSourceIngestionService.save_records(
|
||||
source=source,
|
||||
load_batch=1,
|
||||
publication_run_id=str(run.pk),
|
||||
records=[
|
||||
SourceRecordInput(
|
||||
external_id="new",
|
||||
title="New",
|
||||
organization_name=organization.name,
|
||||
inn=organization.inn,
|
||||
payload={"issue_date": "09.10.2026"},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def ready(run, source, jobs, logs):
|
||||
return finish_part(
|
||||
jobs[source], logs[source], {"status": "success", "batch_id": 1, "saved": 1}
|
||||
)
|
||||
|
||||
|
||||
def test_all_parts_and_terminal_jobs_are_published_together(run):
|
||||
run, jobs, logs, organization = run
|
||||
stage(run, "industrial", organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
assert not OrganizationSourceRecord.objects.filter(external_id="new").exists()
|
||||
jobs["industrial"].refresh_from_db()
|
||||
assert jobs["industrial"].status == "running"
|
||||
logs["industrial"].refresh_from_db()
|
||||
assert logs["industrial"].status == "in_progress"
|
||||
stage(run, "manufactures", organization)
|
||||
ready(run, "manufactures", jobs, logs)
|
||||
assert OrganizationSourceRecord.objects.filter(external_id="new").count() == 2
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"success"}
|
||||
assert set(ParserLoadLog.objects.values_list("status", flat=True)) == {"success"}
|
||||
run.refresh_from_db()
|
||||
assert run.status == "published"
|
||||
assert not ParserRefreshStage.objects.exists()
|
||||
assert SourceCardService.get_card(run.source_card)["active_tasks"] == []
|
||||
|
||||
|
||||
def test_part_failure_discards_staged_data_and_closes_all_jobs(run):
|
||||
run, jobs, logs, organization = run
|
||||
before = list(
|
||||
OrganizationSourceRecord.objects.values("uid", "title", "payload", "updated_at")
|
||||
)
|
||||
stage(run, "industrial", organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
jobs["manufactures"].fail("HTTPError: secret")
|
||||
assert (
|
||||
list(
|
||||
OrganizationSourceRecord.objects.values(
|
||||
"uid", "title", "payload", "updated_at"
|
||||
)
|
||||
)
|
||||
== before
|
||||
)
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"failed"}
|
||||
assert not ParserRefreshStage.objects.exists()
|
||||
assert SourceCardService.get_card(run.source_card)["active_tasks"] == []
|
||||
with pytest.raises(RuntimeError):
|
||||
stage(run, "manufactures", organization)
|
||||
|
||||
|
||||
def test_publication_failure_rolls_back_every_part(run):
|
||||
run, jobs, logs, organization = run
|
||||
stage(run, "industrial", organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
stage(run, "manufactures", organization)
|
||||
original = OrganizationSourceIngestionService.save_records
|
||||
|
||||
def save(**kwargs):
|
||||
if kwargs["source"] == "manufactures":
|
||||
raise RuntimeError("database publication failure")
|
||||
return original(**kwargs)
|
||||
|
||||
with patch.object(
|
||||
OrganizationSourceIngestionService, "save_records", side_effect=save
|
||||
), pytest.raises(RuntimeError):
|
||||
ready(run, "manufactures", jobs, logs)
|
||||
assert not OrganizationSourceRecord.objects.filter(external_id="new").exists()
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"failed"}
|
||||
|
||||
|
||||
def test_cancellation_closes_siblings_and_late_delivery_cannot_publish(run):
|
||||
from apps.parsers.aggregate_publication import claim_part
|
||||
|
||||
run, jobs, logs, organization = run
|
||||
stage(run, "industrial", organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
jobs["manufactures"].revoke()
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"cancelled"}
|
||||
assert claim_part(jobs["manufactures"].task_id)["status"] == "cancelled"
|
||||
assert not ParserRefreshStage.objects.exists()
|
||||
assert not OrganizationSourceRecord.objects.filter(external_id="new").exists()
|
||||
|
||||
|
||||
def test_duplicate_delivery_and_failure_after_commit_are_noops(run):
|
||||
from apps.parsers.aggregate_publication import claim_part
|
||||
|
||||
run, jobs, logs, organization = run
|
||||
assert claim_part(jobs["industrial"].task_id) is None
|
||||
assert claim_part(jobs["industrial"].task_id)["duplicate_delivery"] is True
|
||||
for source in jobs:
|
||||
stage(run, source, organization)
|
||||
ready(run, source, jobs, logs)
|
||||
jobs["industrial"].fail("late failure")
|
||||
assert jobs["industrial"].status == "success"
|
||||
assert claim_part(jobs["industrial"].task_id)["status"] == "success"
|
||||
assert OrganizationSourceRecord.objects.filter(external_id="new").count() == 2
|
||||
|
||||
|
||||
def test_real_parser_tasks_stage_and_publish_through_the_barrier(run):
|
||||
from types import SimpleNamespace
|
||||
|
||||
from apps.parsers.tasks import parse_industrial_production, parse_manufactures
|
||||
|
||||
run, jobs, logs, organization = run
|
||||
certificate = SimpleNamespace(
|
||||
certificate_number="new",
|
||||
organisation_name=organization.name,
|
||||
inn=organization.inn,
|
||||
ogrn="",
|
||||
issue_date="09.10.2026",
|
||||
expiry_date="09.10.2027",
|
||||
certificate_file_url="",
|
||||
)
|
||||
manufacturer = SimpleNamespace(
|
||||
inn=organization.inn,
|
||||
ogrn="",
|
||||
full_legal_name=organization.name,
|
||||
address="Factory address",
|
||||
)
|
||||
with patch("apps.parsers.tasks.IndustrialProductionClient") as client:
|
||||
client.return_value.__enter__.return_value.fetch_certificates.return_value = [
|
||||
certificate
|
||||
]
|
||||
result = parse_industrial_production.apply(
|
||||
task_id=jobs["industrial"].task_id, kwargs={"proxies": []}, throw=True
|
||||
).result
|
||||
assert result["publication_pending"] is True
|
||||
assert not OrganizationSourceRecord.objects.filter(external_id="new").exists()
|
||||
with patch("apps.parsers.tasks.ManufacturesClient") as client:
|
||||
client.return_value.__enter__.return_value.fetch_manufacturers.return_value = [
|
||||
manufacturer
|
||||
]
|
||||
result = parse_manufactures.apply(
|
||||
task_id=jobs["manufactures"].task_id, kwargs={"proxies": []}, throw=True
|
||||
).result
|
||||
assert result["status"] == "success"
|
||||
assert (
|
||||
OrganizationSourceRecord.objects.filter(
|
||||
source="industrial", external_id="new"
|
||||
).count()
|
||||
== 1
|
||||
)
|
||||
assert (
|
||||
OrganizationSourceRecord.objects.filter(
|
||||
source="manufactures", external_id=organization.inn
|
||||
).count()
|
||||
== 1
|
||||
)
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"success"}
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_concurrent_last_parts_publish_once_on_postgres(run):
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from django.db import close_old_connections, connection
|
||||
|
||||
if connection.vendor != "postgresql":
|
||||
pytest.skip("Requires PostgreSQL row locks and independent connections")
|
||||
run, jobs, logs, organization = run
|
||||
for source in jobs:
|
||||
stage(run, source, organization)
|
||||
|
||||
def finish(source):
|
||||
close_old_connections()
|
||||
try:
|
||||
return finish_part(
|
||||
BackgroundJob.objects.get(pk=jobs[source].pk),
|
||||
ParserLoadLog.objects.get(pk=logs[source].pk),
|
||||
{"status": "success", "saved": 1, "batch_id": 1},
|
||||
)
|
||||
finally:
|
||||
close_old_connections()
|
||||
|
||||
with ThreadPoolExecutor(max_workers=2) as workers:
|
||||
results = list(workers.map(finish, jobs))
|
||||
assert [result["status"] for result in results].count("success") == 1
|
||||
assert OrganizationSourceRecord.objects.filter(external_id="new").count() == 2
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"success"}
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_reader_sees_previous_snapshot_until_commit_on_postgres(run):
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from django.db import close_old_connections, connection
|
||||
|
||||
if connection.vendor != "postgresql":
|
||||
pytest.skip("Requires independent PostgreSQL reader")
|
||||
run, jobs, logs, organization = run
|
||||
for source in jobs:
|
||||
stage(run, source, organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
original = OrganizationSourceIngestionService.save_records
|
||||
|
||||
def read():
|
||||
close_old_connections()
|
||||
try:
|
||||
return OrganizationSourceRecord.objects.filter(
|
||||
external_id="new"
|
||||
).count(), set(BackgroundJob.objects.values_list("status", flat=True))
|
||||
finally:
|
||||
close_old_connections()
|
||||
|
||||
def save(**kwargs):
|
||||
result = original(**kwargs)
|
||||
with ThreadPoolExecutor(max_workers=1) as reader:
|
||||
assert reader.submit(read).result(timeout=15) == (0, {"running"})
|
||||
return result
|
||||
|
||||
with patch.object(
|
||||
OrganizationSourceIngestionService, "save_records", side_effect=save
|
||||
):
|
||||
ready(run, "manufactures", jobs, logs)
|
||||
assert OrganizationSourceRecord.objects.filter(external_id="new").count() == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fail_second", [False, True])
|
||||
def test_defense_refresh_tasks_share_one_publication_boundary(db, fail_second):
|
||||
from types import SimpleNamespace
|
||||
|
||||
from apps.parsers.clients.common import GenericParserItem
|
||||
from apps.parsers.tasks import _run_generic_parser
|
||||
|
||||
organization = Organization.objects.create(
|
||||
name="Supplier",
|
||||
inn="7707083810",
|
||||
directory_imported_at="2026-10-09T00:00:00Z",
|
||||
opk_registry_membership=True,
|
||||
)
|
||||
|
||||
def enqueue(**kwargs):
|
||||
return {"task_id": kwargs["task_id"], "task_name": kwargs["task_name"]}
|
||||
|
||||
with patch.object(SourceCardService, "_enqueue_task", side_effect=enqueue):
|
||||
SourceCardService._launch_refresh(
|
||||
SourceCardService.get_definition("defense-unreliable-suppliers"),
|
||||
requested_by_id=None,
|
||||
params={},
|
||||
)
|
||||
run = ParserRefreshRun.objects.get()
|
||||
for index, source in enumerate(run.tasks):
|
||||
|
||||
def fetch(source=source, index=index):
|
||||
if fail_second and index == 1:
|
||||
raise RuntimeError("upstream failed")
|
||||
return [
|
||||
GenericParserItem(
|
||||
source=source,
|
||||
external_id="new",
|
||||
inn=organization.inn,
|
||||
organisation_name=organization.name,
|
||||
)
|
||||
]
|
||||
|
||||
job = BackgroundJob.objects.get(task_id=run.tasks[source])
|
||||
|
||||
def execute(job=job, source=source, fetch=fetch):
|
||||
return _run_generic_parser(
|
||||
SimpleNamespace(request=SimpleNamespace(id=job.task_id)),
|
||||
source_key=source,
|
||||
source=source,
|
||||
task_name=job.task_name,
|
||||
fetch_records=fetch,
|
||||
)
|
||||
|
||||
if fail_second and index == 1:
|
||||
with pytest.raises(RuntimeError):
|
||||
execute()
|
||||
else:
|
||||
execute()
|
||||
if index == 0:
|
||||
assert not OrganizationSourceRecord.objects.exists()
|
||||
assert OrganizationSourceRecord.objects.count() == (0 if fail_second else 2)
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == (
|
||||
{"failed"} if fail_second else {"success"}
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_cache_callback_failure_preserves_committed_success(run, caplog):
|
||||
run, jobs, logs, organization = run
|
||||
for source in jobs:
|
||||
stage(run, source, organization)
|
||||
ready(run, "industrial", jobs, logs)
|
||||
with patch(
|
||||
"apps.parsers.aggregate_publication.invalidate_source_data_cache",
|
||||
side_effect=RuntimeError("cache unavailable"),
|
||||
), patch(
|
||||
"apps.parsers.tasks_registry_snapshots._refresh_published_exports"
|
||||
) as export:
|
||||
ready(run, "manufactures", jobs, logs)
|
||||
export.assert_called_once()
|
||||
assert set(BackgroundJob.objects.values_list("status", flat=True)) == {"success"}
|
||||
assert set(ParserLoadLog.objects.values_list("status", flat=True)) == {"success"}
|
||||
assert "cache invalidation failed" in caplog.text
|
||||
|
||||
|
||||
def test_second_composed_refresh_is_rejected_without_extra_jobs(db):
|
||||
from apps.core.exceptions import ConflictError
|
||||
|
||||
definition = SourceCardService.get_definition("manufacturers-and-products")
|
||||
with patch.object(SourceCardService, "_enqueue_task", return_value={}):
|
||||
SourceCardService._launch_refresh(definition, requested_by_id=None, params={})
|
||||
with pytest.raises(ConflictError):
|
||||
SourceCardService._launch_refresh(
|
||||
definition, requested_by_id=None, params={}
|
||||
)
|
||||
assert ParserRefreshRun.objects.count() == 1
|
||||
assert BackgroundJob.objects.count() == 3
|
||||
@@ -80,9 +80,9 @@ def test_failed_run_keeps_progress_and_error_after_last_active_job_disappears():
|
||||
job.fail("Ошибка загрузки")
|
||||
card = SourceCardService.get_card("arbitration-cases")
|
||||
assert (card["status"], card["progress"], card["error_message"]) == (
|
||||
"error",
|
||||
"failed",
|
||||
60,
|
||||
"Ошибка загрузки",
|
||||
"Не удалось обновить данные. Повторите попытку позже.",
|
||||
)
|
||||
|
||||
|
||||
@@ -110,13 +110,21 @@ def test_broker_failure_keeps_all_registered_parts_in_final_failed_state():
|
||||
@pytest.mark.django_db
|
||||
def test_completed_new_run_does_not_hide_active_older_run():
|
||||
definition = SourceCardService.get_definition("manufacturers-and-products")
|
||||
specs = [(MagicMock(), name, "industrial") for name in definition.task_names]
|
||||
first = SourceCardService._enqueue_refresh_group(
|
||||
definition, specs, requested_by_id=None, kwargs={}
|
||||
)
|
||||
second = SourceCardService._enqueue_refresh_group(
|
||||
definition, specs, requested_by_id=None, kwargs={}
|
||||
)
|
||||
|
||||
# Historical overlapping runs predate the publication barrier. New refreshes
|
||||
# reject this overlap, but polling must still represent existing older jobs.
|
||||
def legacy_run(prefix):
|
||||
ids = [f"{prefix}-{index}" for index in range(len(definition.task_names))]
|
||||
for task_id, name in zip(ids, definition.task_names, strict=True):
|
||||
BackgroundJob.objects.create(
|
||||
task_id=task_id,
|
||||
task_name=name,
|
||||
meta={"source_card": definition.slug, "refresh_task_ids": ids},
|
||||
)
|
||||
return [{"task_id": task_id} for task_id in ids]
|
||||
|
||||
first = legacy_run("older")
|
||||
second = legacy_run("newer")
|
||||
for item in second:
|
||||
BackgroundJob.objects.get(task_id=item["task_id"]).complete()
|
||||
card = SourceCardService.get_card(definition.slug)
|
||||
|
||||
@@ -234,7 +234,11 @@ def test_registry_job_status_distinguishes_queue_retry_failure_cancel(
|
||||
assert response.status_code == 200
|
||||
assert response.data["status"] == expected
|
||||
assert response.data["progress"] == 47
|
||||
assert response.data["message"] == "fixture progress"
|
||||
assert response.data["message"] == (
|
||||
"Не удалось обновить данные. Повторите попытку позже."
|
||||
if expected in {"failed", "cancelled"}
|
||||
else "fixture progress"
|
||||
)
|
||||
if raw == "success":
|
||||
job.result = {"status": "skipped"}
|
||||
job.save(update_fields=["result"])
|
||||
@@ -267,9 +271,15 @@ def test_typed_refresh_job_dashboard_history_openapi(admin_client):
|
||||
)
|
||||
assert paths[dashboard]["get"]["operationId"] == "api_v1_parsers_dashboard_list"
|
||||
assert paths[dashboard]["get"]["tags"] == ["api"]
|
||||
assert {"pending", "started", "retry", "failure", "revoked"} <= set(
|
||||
definitions["BackgroundJob"]["properties"]["status"]["enum"]
|
||||
)
|
||||
assert {
|
||||
"queued",
|
||||
"running",
|
||||
"retrying",
|
||||
"failed",
|
||||
"cancelled",
|
||||
"success",
|
||||
"skipped",
|
||||
} == set(definitions["BackgroundJob"]["properties"]["status"]["enum"])
|
||||
logs_path = next(path for path in paths if path.endswith("/system/logs/"))
|
||||
parameters = {item["name"]: item for item in paths[logs_path]["get"]["parameters"]}
|
||||
assert parameters["source"]["type"] == "string"
|
||||
|
||||
@@ -428,7 +428,7 @@ class SourceCardServiceUnitTest(TestCase):
|
||||
latest_load=stale_in_progress_load,
|
||||
last_updated_at=None,
|
||||
),
|
||||
"error",
|
||||
"failed",
|
||||
)
|
||||
self.assertEqual(
|
||||
SourceCardService._get_status(
|
||||
@@ -437,7 +437,7 @@ class SourceCardServiceUnitTest(TestCase):
|
||||
latest_load=failed_load,
|
||||
last_updated_at=None,
|
||||
),
|
||||
"error",
|
||||
"failed",
|
||||
)
|
||||
self.assertEqual(
|
||||
SourceCardService._get_status(
|
||||
|
||||
@@ -125,9 +125,10 @@ class SourcesApiE2ETest(APITestCase):
|
||||
self.assertEqual(cards["financial-indicators"]["records_count"], 1)
|
||||
self.assertEqual(cards["planned-inspections"]["status"], "in_progress")
|
||||
self.assertEqual(cards["planned-inspections"]["progress"], 55)
|
||||
self.assertEqual(cards["public-procurements"]["status"], "error")
|
||||
self.assertEqual(cards["public-procurements"]["status"], "failed")
|
||||
self.assertEqual(
|
||||
cards["public-procurements"]["error_message"], "download error"
|
||||
cards["public-procurements"]["error_message"],
|
||||
"Не удалось обновить данные. Повторите попытку позже.",
|
||||
)
|
||||
|
||||
minprom_card = detail_response.data["data"]
|
||||
@@ -142,7 +143,7 @@ class SourcesApiE2ETest(APITestCase):
|
||||
|
||||
statuses = {item["slug"]: item for item in statuses_response.data["data"]}
|
||||
self.assertEqual(statuses["planned-inspections"]["progress"], 55)
|
||||
self.assertEqual(statuses["public-procurements"]["status"], "error")
|
||||
self.assertEqual(statuses["public-procurements"]["status"], "failed")
|
||||
|
||||
def test_products_endpoint_supports_filter_and_search(self):
|
||||
target = IndustrialProductRecordFactory(
|
||||
|
||||
@@ -150,7 +150,7 @@ class SystemLogsCheckupTest(APITestCase):
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_csv_preserves_cyrillic_delimiters_quotes_and_newlines(self):
|
||||
def test_csv_preserves_encoding_and_hides_internal_diagnostics(self):
|
||||
message = 'Ошибка; "детали"\r\nСледующая строка'
|
||||
self.create_log(
|
||||
datetime(2026, 9, 7, 12, 34, tzinfo=UTC),
|
||||
@@ -173,7 +173,11 @@ class SystemLogsCheckupTest(APITestCase):
|
||||
)
|
||||
self.assertEqual(rows[1][1], "07.09.2026 12:34")
|
||||
self.assertEqual(rows[1][3], "Ошибка")
|
||||
self.assertEqual(rows[1][rows[0].index("Ошибка")], message)
|
||||
self.assertEqual(
|
||||
rows[1][rows[0].index("Ошибка")],
|
||||
"Не удалось обновить данные. Повторите попытку позже.",
|
||||
)
|
||||
self.assertNotIn(message, decoded)
|
||||
|
||||
def test_openapi_documents_period_for_list_and_export(self):
|
||||
response = self.client.get(reverse("schema-swagger-ui"), {"format": "openapi"})
|
||||
|
||||
@@ -1894,6 +1894,17 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
"parse_fstec_registers",
|
||||
)
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(
|
||||
patch.object(
|
||||
parser_tasks,
|
||||
"parse_all_minpromtorg",
|
||||
return_value={
|
||||
"industrial": "industrial-id",
|
||||
"industrial_products": "products-id",
|
||||
"manufactures": "manufactures-id",
|
||||
},
|
||||
)
|
||||
)
|
||||
delays = {
|
||||
task_name: stack.enter_context(
|
||||
patch.object(
|
||||
@@ -1939,51 +1950,63 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
original_industrial = parser_tasks.IndustrialProductionClient
|
||||
original_industrial_products = parser_tasks.GispProductsClient
|
||||
original_manufactures = parser_tasks.ManufacturesClient
|
||||
original_industrial_delay = parser_tasks.parse_industrial_production.delay
|
||||
original_industrial_products_delay = (
|
||||
parser_tasks.parse_industrial_products.delay
|
||||
original_industrial_delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async
|
||||
)
|
||||
original_manufactures_delay = parser_tasks.parse_manufactures.delay
|
||||
original_industrial_products_delay = (
|
||||
parser_tasks.parse_industrial_products.apply_async
|
||||
)
|
||||
original_manufactures_delay = parser_tasks.parse_manufactures.apply_async
|
||||
parser_tasks.IndustrialProductionClient = _LocalIndustrialClient
|
||||
parser_tasks.GispProductsClient = _LocalIndustrialProductsClient
|
||||
parser_tasks.ManufacturesClient = _LocalManufacturesClient
|
||||
|
||||
def _industrial_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_industrial_production.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
def _industrial_products_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_industrial_products.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
def _manufactures_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_manufactures.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
parser_tasks.parse_industrial_production.delay = _industrial_eager_delay
|
||||
parser_tasks.parse_industrial_products.delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async = (
|
||||
_industrial_eager_delay
|
||||
)
|
||||
parser_tasks.parse_industrial_products.apply_async = (
|
||||
_industrial_products_eager_delay
|
||||
)
|
||||
parser_tasks.parse_manufactures.delay = _manufactures_eager_delay
|
||||
parser_tasks.parse_manufactures.apply_async = _manufactures_eager_delay
|
||||
try:
|
||||
result = parse_all_minpromtorg(proxies=[])
|
||||
finally:
|
||||
parser_tasks.IndustrialProductionClient = original_industrial
|
||||
parser_tasks.GispProductsClient = original_industrial_products
|
||||
parser_tasks.ManufacturesClient = original_manufactures
|
||||
parser_tasks.parse_industrial_production.delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async = (
|
||||
original_industrial_delay
|
||||
)
|
||||
parser_tasks.parse_industrial_products.delay = (
|
||||
parser_tasks.parse_industrial_products.apply_async = (
|
||||
original_industrial_products_delay
|
||||
)
|
||||
parser_tasks.parse_manufactures.delay = original_manufactures_delay
|
||||
parser_tasks.parse_manufactures.apply_async = (
|
||||
original_manufactures_delay
|
||||
)
|
||||
|
||||
self.assertIn("industrial", result)
|
||||
self.assertIn("industrial_products", result)
|
||||
@@ -2029,11 +2052,13 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
original_industrial = parser_tasks.IndustrialProductionClient
|
||||
original_industrial_products = parser_tasks.GispProductsClient
|
||||
original_manufactures = parser_tasks.ManufacturesClient
|
||||
original_industrial_delay = parser_tasks.parse_industrial_production.delay
|
||||
original_industrial_products_delay = (
|
||||
parser_tasks.parse_industrial_products.delay
|
||||
original_industrial_delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async
|
||||
)
|
||||
original_manufactures_delay = parser_tasks.parse_manufactures.delay
|
||||
original_industrial_products_delay = (
|
||||
parser_tasks.parse_industrial_products.apply_async
|
||||
)
|
||||
original_manufactures_delay = parser_tasks.parse_manufactures.apply_async
|
||||
original_sync_inspections_delay = parser_tasks.sync_inspections.delay
|
||||
parser_tasks.IndustrialProductionClient = _LocalIndustrialClient
|
||||
parser_tasks.GispProductsClient = _LocalIndustrialProductsClient
|
||||
@@ -2041,30 +2066,38 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
|
||||
def _industrial_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_industrial_production.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
def _industrial_products_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_industrial_products.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
def _manufactures_eager_delay(*args, **kwargs):
|
||||
return parser_tasks.parse_manufactures.apply(
|
||||
args=args,
|
||||
kwargs=kwargs,
|
||||
args=kwargs.get("args", args),
|
||||
kwargs=kwargs.get("kwargs", {}),
|
||||
task_id=kwargs.get("task_id"),
|
||||
throw=True,
|
||||
)
|
||||
|
||||
def _inspections_stub_delay(*_args, **_kwargs):
|
||||
return SimpleNamespace(id="inspections-test-task")
|
||||
|
||||
parser_tasks.parse_industrial_production.delay = _industrial_eager_delay
|
||||
parser_tasks.parse_industrial_products.delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async = (
|
||||
_industrial_eager_delay
|
||||
)
|
||||
parser_tasks.parse_industrial_products.apply_async = (
|
||||
_industrial_products_eager_delay
|
||||
)
|
||||
parser_tasks.parse_manufactures.delay = _manufactures_eager_delay
|
||||
parser_tasks.parse_manufactures.apply_async = _manufactures_eager_delay
|
||||
parser_tasks.sync_inspections.delay = _inspections_stub_delay
|
||||
try:
|
||||
result = parse_all_sources(proxies=[], inspections_use_playwright=None)
|
||||
@@ -2072,13 +2105,15 @@ class MinpromtorgTasksTestCase(TestCase):
|
||||
parser_tasks.IndustrialProductionClient = original_industrial
|
||||
parser_tasks.GispProductsClient = original_industrial_products
|
||||
parser_tasks.ManufacturesClient = original_manufactures
|
||||
parser_tasks.parse_industrial_production.delay = (
|
||||
parser_tasks.parse_industrial_production.apply_async = (
|
||||
original_industrial_delay
|
||||
)
|
||||
parser_tasks.parse_industrial_products.delay = (
|
||||
parser_tasks.parse_industrial_products.apply_async = (
|
||||
original_industrial_products_delay
|
||||
)
|
||||
parser_tasks.parse_manufactures.delay = original_manufactures_delay
|
||||
parser_tasks.parse_manufactures.apply_async = (
|
||||
original_manufactures_delay
|
||||
)
|
||||
parser_tasks.sync_inspections.delay = original_sync_inspections_delay
|
||||
|
||||
self.assertIn("industrial", result)
|
||||
|
||||
Reference in New Issue
Block a user