feat(parsers): sync RU proxies from proxy-tools
Some checks failed
CI/CD Pipeline / Telegram Notify Success (push) Has been cancelled
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Code Quality Checks (push) Has been cancelled

This commit is contained in:
2026-03-23 10:47:34 +01:00
parent b4260d53cb
commit 7d4c54636b
13 changed files with 705 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ import tempfile
import threading
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
from urllib.parse import urlparse
from apps.parsers import tasks as parser_tasks
@@ -39,6 +40,7 @@ from apps.parsers.tasks import (
_move_to_dir,
_process_fns_file_sync,
_remove_lock,
_resolve_proxies,
_try_create_lock,
parse_all_minpromtorg,
parse_all_sources,
@@ -51,6 +53,7 @@ from apps.parsers.tasks import (
scan_fns_directory,
sync_inspections,
sync_procurements,
sync_ru_proxies,
)
from django.test import TestCase, override_settings
from openpyxl import Workbook
@@ -59,6 +62,7 @@ from tests.apps.parsers.factories import (
InspectionRecordFactory,
ParserLoadLogFactory,
ProcurementRecordFactory,
ProxyFactory,
)
from tests.utils import TestHTTPServer
from tests.utils.fixtures import (
@@ -102,6 +106,55 @@ def _portal_path(year: int, month: int) -> str:
return f"/portal/public-open-data/check/{year}/{month}"
class ProxyResolutionTestCase(TestCase):
"""Tests for proxy resolution in parser tasks."""
@override_settings(PARSER_PROXIES=["http://env-proxy:8080"])
def test_resolve_proxies_prefers_runtime_db_proxies(self):
imported_proxy = ProxyFactory(
address="http://10.0.0.2:8000",
source="proxy-tools",
country_code="RU",
is_active=True,
)
ProxyFactory(
address="http://10.0.0.3:8000",
source="manual",
country_code="RU",
is_active=True,
)
result = _resolve_proxies(None)
self.assertEqual(result, [imported_proxy.address])
@override_settings(PARSER_PROXIES=["http://env-proxy:8080"])
def test_resolve_proxies_falls_back_to_settings_when_db_empty(self):
result = _resolve_proxies(None)
self.assertEqual(result, ["http://env-proxy:8080"])
class SyncRuProxiesTaskTestCase(TestCase):
"""Tests for periodic RU proxy sync task."""
@patch("apps.parsers.tasks.ProxyToolsSyncService.sync_ru_proxies")
def test_sync_ru_proxies_returns_service_payload(self, sync_mock):
sync_mock.return_value = {
"status": "success",
"fetched": 3,
"created": 2,
"updated": 1,
"deactivated": 0,
}
result = sync_ru_proxies.run()
self.assertEqual(result["status"], "success")
self.assertEqual(result["fetched"], 3)
sync_mock.assert_called_once_with()
@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,
CELERY_TASK_EAGER_PROPAGATES=True,