fix parser schedule run issues
All checks were successful
CI/CD Pipeline / Manual Action Help (push) Has been skipped
CI/CD Pipeline / Start Dev Containers in Dokploy (push) Has been skipped
CI/CD Pipeline / Drop and Recreate Dev Database (push) Has been skipped
CI/CD Pipeline / Quality Gate (push) Successful in 1m53s
CI/CD Pipeline / Build and Push Images (push) Successful in 2m42s
CI/CD Pipeline / Internal Notify (push) Successful in 1s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Successful in 1s
All checks were successful
CI/CD Pipeline / Manual Action Help (push) Has been skipped
CI/CD Pipeline / Start Dev Containers in Dokploy (push) Has been skipped
CI/CD Pipeline / Drop and Recreate Dev Database (push) Has been skipped
CI/CD Pipeline / Quality Gate (push) Successful in 1m53s
CI/CD Pipeline / Build and Push Images (push) Successful in 2m42s
CI/CD Pipeline / Internal Notify (push) Successful in 1s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Successful in 1s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Tests for parsers models."""
|
||||
|
||||
from apps.parsers.models import (
|
||||
GenericParserRecord,
|
||||
IndustrialCertificateRecord,
|
||||
IndustrialProductRecord,
|
||||
ManufacturerRecord,
|
||||
@@ -97,6 +98,15 @@ class ParserLoadLogModelTest(TestCase):
|
||||
self.assertIsNotNone(log.updated_at)
|
||||
|
||||
|
||||
class GenericParserRecordModelTest(TestCase):
|
||||
"""Tests for generic parser records."""
|
||||
|
||||
def test_record_date_allows_source_specific_long_values(self):
|
||||
field = GenericParserRecord._meta.get_field("record_date")
|
||||
|
||||
self.assertEqual(field.max_length, 255)
|
||||
|
||||
|
||||
class IndustrialCertificateRecordModelTest(TestCase):
|
||||
"""Tests for IndustrialCertificateRecord model."""
|
||||
|
||||
|
||||
@@ -896,6 +896,34 @@ class ParseInspectionsTaskTestCase(TestCase):
|
||||
self.assertEqual(result["status"], "success")
|
||||
self.assertEqual(result["total_saved"], 0)
|
||||
|
||||
def test_sync_inspections_honors_limited_params(self):
|
||||
xml_content, rows = build_proverki_xml(count=1)
|
||||
archive = build_zip([("inspections.xml", xml_content)])
|
||||
|
||||
with TestHTTPServer() as server:
|
||||
server.add_bytes(
|
||||
_portal_path(2026, 4),
|
||||
archive,
|
||||
content_type="application/zip",
|
||||
)
|
||||
result = sync_inspections(
|
||||
proxies=[],
|
||||
client_adapter=server.adapter,
|
||||
use_playwright=False,
|
||||
max_months_per_law=1,
|
||||
start_year=2026,
|
||||
start_month=4,
|
||||
include_fz294=True,
|
||||
include_fz248=False,
|
||||
current_year=2026,
|
||||
current_month=5,
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "success")
|
||||
self.assertEqual(len(result["results"]["fz294"]), 1)
|
||||
self.assertEqual(result["results"]["fz248"], [])
|
||||
self.assertGreaterEqual(result["total_saved"], len(rows))
|
||||
|
||||
def test_sync_inspections_resumes_from_last_loaded(self):
|
||||
last_year = 2024
|
||||
last_month = 12
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import io
|
||||
import os
|
||||
import tempfile
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from apps.parsers.models import FinancialReport, FinancialReportLine, ProcurementRecord
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
@@ -341,3 +342,28 @@ class ParsersViewSetTest(APITestCase):
|
||||
|
||||
self.assertEqual(updated.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(updated.data["planned_inspections"], "weekly")
|
||||
|
||||
def test_run_sync_inspections_accepts_limited_sync_params(self):
|
||||
self.client.force_authenticate(self.user)
|
||||
url = reverse("api_v1:parsers:run-parser", args=["sync_inspections"])
|
||||
payload = {
|
||||
"max_months_per_law": 1,
|
||||
"start_year": 2026,
|
||||
"start_month": 4,
|
||||
"include_fz294": True,
|
||||
"include_fz248": False,
|
||||
"current_year": 2026,
|
||||
"current_month": 4,
|
||||
}
|
||||
|
||||
with patch(
|
||||
"apps.parsers.views.tasks.sync_inspections.apply_async",
|
||||
return_value=Mock(id="task-123"),
|
||||
) as apply_async_mock:
|
||||
response = self.client.post(url, payload, format="json")
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||
task_kwargs = apply_async_mock.call_args.kwargs["kwargs"]
|
||||
for key, value in payload.items():
|
||||
self.assertEqual(task_kwargs[key], value)
|
||||
self.assertEqual(task_kwargs["requested_by_id"], self.user.id)
|
||||
|
||||
Reference in New Issue
Block a user