From d510d18016cb2cd40276c08e3831f8c11e0bbf94 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:32:34 -0800 Subject: [PATCH] Backend coverage --- src/documents/serialisers.py | 4 ++-- src/documents/tests/test_api_bulk_edit.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index cb0d6d317..9a5600316 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1152,13 +1152,13 @@ class BulkEditSerializer( except Exception as e: logger.exception(f"Error validating custom fields: {e}") raise serializers.ValidationError( - f"{name} must be a list of integers or a dict of key-value pairs, see the log for details", + f"{name} must be a list of integers or a dict of id:value pairs, see the log for details", ) elif not isinstance(custom_fields, list) or not all( isinstance(i, int) for i in ids ): raise serializers.ValidationError( - f"{name} must be a list of integers or a dict of key-value pairs", + f"{name} must be a list of integers or a dict of id:value pairs", ) count = CustomField.objects.filter(id__in=ids).count() if not count == len(ids): diff --git a/src/documents/tests/test_api_bulk_edit.py b/src/documents/tests/test_api_bulk_edit.py index 59002802c..ff0b367d1 100644 --- a/src/documents/tests/test_api_bulk_edit.py +++ b/src/documents/tests/test_api_bulk_edit.py @@ -348,7 +348,23 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) m.assert_not_called() - # Not a list of integers + # Invalid dict + response = self.client.post( + "/api/documents/bulk_edit/", + json.dumps( + { + "documents": [self.doc1.id, self.doc3.id], + "method": "modify_custom_fields", + "parameters": { + "add_custom_fields": {"foo": 99}, + "remove_custom_fields": [self.cf2.id], + }, + }, + ), + content_type="application/json", + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + m.assert_not_called() # Missing remove_custom_fields response = self.client.post(