feat: expose FSSP source APIs and exports
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user