Add periodic exchange task management API
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Successful in 3m16s
CI/CD Pipeline / Run Tests (push) Successful in 3m26s
CI/CD Pipeline / Telegram Notify Success (push) Failing after 1m29s
CI/CD Pipeline / Run Tests (pull_request) Successful in 1m44s
CI/CD Pipeline / Code Quality Checks (pull_request) Successful in 20m19s
CI/CD Pipeline / Telegram Notify Success (pull_request) Failing after 1m34s

This commit is contained in:
2026-03-19 17:03:47 +01:00
parent 941c268d32
commit 3de66cc25c
8 changed files with 867 additions and 24 deletions

View File

@@ -2,11 +2,51 @@ from __future__ import annotations
from unittest.mock import MagicMock, patch
from apps.exchange.tasks import copy_parsers_data_async
from apps.exchange.services import ExchangeServiceError
from apps.exchange.tasks import copy_parsers_data_async, dispatch_periodic_exchange_copy
from django.test import SimpleTestCase
class ExchangeTasksTest(SimpleTestCase):
def test_dispatch_periodic_exchange_copy_enqueues_copy_with_active_connection(self):
active_connection = MagicMock(id=15)
with patch(
"apps.exchange.tasks.ExchangeConnectionService.get_active_connection",
return_value=active_connection,
) as get_connection_mock, patch(
"apps.exchange.tasks.copy_parsers_data_async.delay",
return_value=MagicMock(id="task-15"),
) as delay_mock:
result = dispatch_periodic_exchange_copy.run(
payload={"mode": "all", "truncate_before_copy": True}
)
self.assertEqual(
result,
{
"status": "queued",
"task_id": "task-15",
"connection_id": 15,
},
)
get_connection_mock.assert_called_once_with()
delay_mock.assert_called_once_with(
connection_id=15,
payload={"mode": "all", "truncate_before_copy": True},
requested_by_id=None,
)
def test_dispatch_periodic_exchange_copy_fails_without_active_connection(self):
with patch(
"apps.exchange.tasks.ExchangeConnectionService.get_active_connection",
side_effect=ExchangeServiceError("Активное подключение не найдено"),
), self.assertRaisesMessage(
ExchangeServiceError,
"Активное подключение не найдено",
):
dispatch_periodic_exchange_copy.run(payload={"mode": "all"})
def test_copy_parsers_data_async_completes_with_existing_job(self):
background_job = MagicMock()
connection = MagicMock()