fix(api): align contracts with frontend md
Some checks failed
CI/CD Pipeline / Code Quality Checks (pull_request) Failing after 3m20s
CI/CD Pipeline / Run Tests (pull_request) Successful in 13m45s
CI/CD Pipeline / Run API Inventory E2E Tests (pull_request) Successful in 22s
CI/CD Pipeline / Telegram Notify Success (pull_request) Has been skipped

This commit is contained in:
2026-03-23 13:12:10 +01:00
parent d030c705ac
commit 4ca6b75393
12 changed files with 215 additions and 215 deletions

View File

@@ -36,25 +36,22 @@ class ExchangeCopyRequestSerializerTest(SimpleTestCase):
class ExchangePeriodicTaskUpsertSerializerTest(SimpleTestCase):
def test_interval_schedule_requires_fields(self):
serializer = ExchangePeriodicTaskUpsertSerializer(
data={"name": "copy-job", "schedule_type": "interval"}
)
serializer = ExchangePeriodicTaskUpsertSerializer(data={"schedule_type": "interval"})
self.assertFalse(serializer.is_valid())
self.assertIn("interval_every", serializer.errors)
self.assertIn("interval_period", serializer.errors)
def test_crontab_schedule_requires_fields(self):
serializer = ExchangePeriodicTaskUpsertSerializer(
data={"name": "copy-job", "schedule_type": "crontab"}
)
def test_daily_schedule_requires_fields(self):
serializer = ExchangePeriodicTaskUpsertSerializer(data={"schedule_type": "daily"})
self.assertFalse(serializer.is_valid())
self.assertIn("crontab_minute", serializer.errors)
self.assertIn("crontab_hour", serializer.errors)
def test_update_mode_to_all_clears_old_single_table(self):
def test_partial_update_preserves_existing_payload(self):
instance = SimpleNamespace(
name="copy-job",
interval_id=1,
interval=SimpleNamespace(every=5, period="minutes"),
crontab_id=None,
@@ -62,7 +59,7 @@ class ExchangePeriodicTaskUpsertSerializerTest(SimpleTestCase):
)
serializer = ExchangePeriodicTaskUpsertSerializer(
instance,
data={"mode": "all"},
data={},
partial=True,
)
@@ -70,36 +67,30 @@ class ExchangePeriodicTaskUpsertSerializerTest(SimpleTestCase):
self.assertEqual(
serializer.validated_data["payload"],
{
"mode": "all",
"table": None,
"mode": "single",
"table": "old_table",
"tables": None,
"truncate_before_copy": True,
"notify_on_error": False,
},
)
def test_periodic_task_uses_copy_payload_validation(self):
def test_invalid_schedule_type_is_rejected(self):
serializer = ExchangePeriodicTaskUpsertSerializer(
data={
"name": "copy-job",
"schedule_type": "interval",
"interval_every": 1,
"interval_period": "hours",
"mode": "single",
"schedule_type": "crontab",
}
)
self.assertFalse(serializer.is_valid())
self.assertIn("table", serializer.errors)
self.assertIn("schedule_type", serializer.errors)
def test_notify_on_error_is_added_to_payload(self):
serializer = ExchangePeriodicTaskUpsertSerializer(
data={
"name": "copy-job",
"schedule_type": "interval",
"interval_every": 1,
"interval_period": "hours",
"mode": "all",
"notify_on_error": True,
}
)

View File

@@ -196,13 +196,9 @@ class ExchangeViewsTest(APITestCase):
def test_create_periodic_interval_task_success(self):
payload = {
"name": "exchange-copy-hourly",
"description": "Hourly sync",
"enabled": True,
"schedule_type": "interval",
"interval_every": 1,
"interval_period": "hours",
"mode": "all",
"notify_on_error": True,
}
@@ -219,11 +215,6 @@ class ExchangeViewsTest(APITestCase):
"schedule_type",
"interval_every",
"interval_period",
"crontab_minute",
"crontab_hour",
"crontab_day_of_week",
"crontab_day_of_month",
"crontab_month_of_year",
"notify_on_error",
},
)
@@ -292,15 +283,9 @@ class ExchangeViewsTest(APITestCase):
kwargs={"task_id": task.id},
)
payload = {
"schedule_type": "crontab",
"crontab_minute": "0",
"crontab_hour": "4",
"crontab_day_of_week": "*",
"crontab_day_of_month": "*",
"crontab_month_of_year": "*",
"mode": "single",
"table": "parsers_proxy",
"enabled": False,
"schedule_type": "daily",
"crontab_minute": 0,
"crontab_hour": 4,
"notify_on_error": True,
}
@@ -312,9 +297,9 @@ class ExchangeViewsTest(APITestCase):
self.assertIsNone(task.interval)
self.assertIsNotNone(task.crontab)
self.assertEqual(str(task.crontab.timezone), settings.TIME_ZONE)
self.assertFalse(task.enabled)
self.assertEqual(response.data["schedule_type"], "crontab")
self.assertEqual(response.data["crontab_hour"], "4")
self.assertTrue(task.enabled)
self.assertEqual(response.data["schedule_type"], "daily")
self.assertEqual(response.data["crontab_hour"], 4)
self.assertTrue(response.data["notify_on_error"])
self.assertFalse(IntervalSchedule.objects.filter(id=interval.id).exists())

View File

@@ -209,16 +209,20 @@ class SourcesApiE2ETest(APITestCase):
self.assertEqual(minprom_response.data["status"], "accepted")
self.assertEqual(procurements_response.data["status"], "accepted")
minprom_tasks = minprom_response.data["tasks"]
self.assertEqual(
[item["task_id"] for item in minprom_tasks],
["task-industrial", "task-products", "task-manufactures"],
)
self.assertEqual(set(minprom_response.data.keys()), {"task_id", "status"})
self.assertEqual(minprom_response.data["task_id"], "task-industrial")
self.assertEqual(
set(procurements_response.data.keys()),
{"task_id", "status"},
)
self.assertEqual(procurements_response.data["task_id"], "task-procurements")
self.assertEqual(
BackgroundJob.objects.filter(
task_id__in=["task-industrial", "task-products", "task-manufactures"],
user_id=self.admin.id,
).count(),
3,
)
self.assertTrue(
BackgroundJob.objects.filter(
task_id="task-procurements",

View File

@@ -647,13 +647,9 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
create_periodic = self.client.post(
periodic_tasks_url,
{
"name": "inventory-periodic-task",
"description": "inventory",
"enabled": True,
"schedule_type": "interval",
"interval_every": 1,
"interval_period": "hours",
"mode": "all",
"notify_on_error": True,
},
format="json",
@@ -667,12 +663,9 @@ class ExchangeApiInventoryE2ETest(AuthenticatedApiMixin, APITestCase):
patch_periodic = self.client.patch(
periodic_detail_url,
{
"name": "inventory-periodic-task-updated",
"enabled": False,
"schedule_type": "interval",
"interval_every": 2,
"interval_period": "hours",
"mode": "all",
"schedule_type": "daily",
"crontab_hour": 2,
"crontab_minute": 30,
"notify_on_error": False,
},
format="json",