Add organizations v2 API and registry enrichment
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 26s
CI/CD Pipeline / Build and Push Images (push) Successful in 6s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Successful in 1s

This commit is contained in:
2026-05-06 19:04:46 +02:00
parent f54aa4cb0b
commit 0f17ff6773
62 changed files with 10311 additions and 430 deletions

View File

@@ -1,5 +1,7 @@
"""Тесты для BulkOperationsMixin и QueryOptimizerMixin."""
from unittest.mock import patch
from apps.core.models import BackgroundJob
from apps.core.services import (
BulkOperationsMixin,
@@ -230,3 +232,36 @@ class BulkOperationsIntegrationTest(TestCase):
job = BackgroundJob.objects.get(task_id="upsert-existing")
self.assertEqual(job.task_name, "new.task")
self.assertEqual(job.progress, 100)
def test_bulk_update_or_create_does_not_use_per_row_update_or_create(self):
"""Upsert должен идти через bulk операции, а не update_or_create в цикле."""
class TestService(BulkOperationsMixin):
model = BackgroundJob
BackgroundJob.objects.create(
task_id="upsert-bulk-existing",
task_name="old.task",
progress=0,
)
items = [
{
"task_id": "upsert-bulk-existing",
"task_name": "new.task",
"progress": 100,
},
{"task_id": "upsert-bulk-new", "task_name": "new.task", "progress": 50},
]
with patch(
"django.db.models.query.QuerySet.update_or_create",
side_effect=AssertionError("per-row update_or_create must not be used"),
):
created, updated = TestService.bulk_update_or_create(
items=items,
unique_fields=["task_id"],
update_fields=["task_name", "progress"],
)
self.assertEqual(created, 1)
self.assertEqual(updated, 1)