From 12953eb0223cae0131f6f4e218534d8595a40f00 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 12 Nov 2024 23:51:44 -0800 Subject: [PATCH] A couple more test fixes --- src/documents/tests/test_api_documents.py | 7 +++++-- .../tests/test_api_filter_by_custom_fields.py | 4 ++-- src/documents/tests/test_file_handling.py | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/documents/tests/test_api_documents.py b/src/documents/tests/test_api_documents.py index 08d86d24e..8307d6c4c 100644 --- a/src/documents/tests/test_api_documents.py +++ b/src/documents/tests/test_api_documents.py @@ -657,13 +657,16 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): name="Test Custom Field Select", data_type=CustomField.FieldDataType.SELECT, extra_data={ - "select_options": ["Option 1", "Choice 2"], + "select_options": [ + {"label": "Option 1", "id": "abc123"}, + {"label": "Choice 2", "id": "def456"}, + ], }, ) CustomFieldInstance.objects.create( document=doc1, field=custom_field_select, - value_select=1, + value_select="def456", ) r = self.client.get("/api/documents/?custom_fields__icontains=choice") diff --git a/src/documents/tests/test_api_filter_by_custom_fields.py b/src/documents/tests/test_api_filter_by_custom_fields.py index d0d95d0c9..c7e9092ed 100644 --- a/src/documents/tests/test_api_filter_by_custom_fields.py +++ b/src/documents/tests/test_api_filter_by_custom_fields.py @@ -528,9 +528,9 @@ class TestCustomFieldsSearch(DirectoriesMixin, APITestCase): def test_invalid_value(self): self._assert_validation_error( - json.dumps(["select_field", "exact", "not an option"]), + json.dumps(["select_field", "exact", []]), ["custom_field_query", "2"], - "integer", + "string", ) def test_invalid_logical_operator(self): diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py index 688069db0..2ec388501 100644 --- a/src/documents/tests/test_file_handling.py +++ b/src/documents/tests/test_file_handling.py @@ -544,7 +544,11 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase): name="test", data_type=CustomField.FieldDataType.SELECT, extra_data={ - "select_options": ["apple", "banana", "cherry"], + "select_options": [ + {"label": "apple", "id": "abc123"}, + {"label": "banana", "id": "def456"}, + {"label": "cherry", "id": "ghi789"}, + ], }, ) doc = Document.objects.create( @@ -555,14 +559,22 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase): archive_checksum="B", mime_type="application/pdf", ) - CustomFieldInstance.objects.create(field=cf, document=doc, value_select=0) + CustomFieldInstance.objects.create( + field=cf, + document=doc, + value_select="abc123", + ) self.assertEqual(generate_filename(doc), "document_apple.pdf") # handler should not have been called self.assertEqual(m.call_count, 0) cf.extra_data = { - "select_options": ["aubergine", "banana", "cherry"], + "select_options": [ + {"label": "aubergine", "id": "abc123"}, + {"label": "banana", "id": "def456"}, + {"label": "cherry", "id": "ghi789"}, + ], } cf.save() self.assertEqual(generate_filename(doc), "document_aubergine.pdf")