Add organizations v2 API and registry enrichment
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user