mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-04 00:31:12 -06:00
Fix: change async handling of select custom field updates (#11490)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
from datetime import date
|
||||
from unittest import mock
|
||||
from unittest.mock import ANY
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
@@ -276,6 +277,52 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
|
||||
doc.refresh_from_db()
|
||||
self.assertEqual(doc.custom_fields.first().value, None)
|
||||
|
||||
@mock.patch("documents.signals.handlers.process_cf_select_update.delay")
|
||||
def test_custom_field_update_offloaded_once(self, mock_delay):
|
||||
"""
|
||||
GIVEN:
|
||||
- A select custom field attached to multiple documents
|
||||
WHEN:
|
||||
- The select options are updated
|
||||
THEN:
|
||||
- The async update task is enqueued once
|
||||
"""
|
||||
cf_select = CustomField.objects.create(
|
||||
name="Select Field",
|
||||
data_type=CustomField.FieldDataType.SELECT,
|
||||
extra_data={
|
||||
"select_options": [
|
||||
{"label": "Option 1", "id": "abc-123"},
|
||||
{"label": "Option 2", "id": "def-456"},
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
documents = [
|
||||
Document.objects.create(
|
||||
title="WOW",
|
||||
content="the content",
|
||||
checksum=f"{i}",
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
for i in range(3)
|
||||
]
|
||||
for document in documents:
|
||||
CustomFieldInstance.objects.create(
|
||||
document=document,
|
||||
field=cf_select,
|
||||
value_select="def-456",
|
||||
)
|
||||
|
||||
cf_select.extra_data = {
|
||||
"select_options": [
|
||||
{"label": "Option 1", "id": "abc-123"},
|
||||
],
|
||||
}
|
||||
cf_select.save()
|
||||
|
||||
mock_delay.assert_called_once_with(cf_select)
|
||||
|
||||
def test_custom_field_select_old_version(self):
|
||||
"""
|
||||
GIVEN:
|
||||
|
||||
Reference in New Issue
Block a user