Coverage
This commit is contained in:
parent
f463841dd5
commit
5cb2aa9c4e
@ -1880,17 +1880,10 @@ class TrashSerializer(SerializerWithPerms):
|
||||
write_only=True,
|
||||
)
|
||||
|
||||
def _validate_document_id_list(self, documents, name="documents"):
|
||||
if not isinstance(documents, list):
|
||||
raise serializers.ValidationError(f"{name} must be a list")
|
||||
if not all(isinstance(i, int) for i in documents):
|
||||
raise serializers.ValidationError(f"{name} must be a list of integers")
|
||||
def validate_documents(self, documents):
|
||||
count = Document.deleted_objects.filter(id__in=documents).count()
|
||||
if not count == len(documents):
|
||||
raise serializers.ValidationError(
|
||||
f"Some documents in {name} have not yet been deleted.",
|
||||
"Some documents in the list have not yet been deleted.",
|
||||
)
|
||||
|
||||
def validate_documents(self, documents):
|
||||
self._validate_document_id_list(documents)
|
||||
return documents
|
||||
|
@ -126,3 +126,30 @@ class TestTrashAPI(APITestCase):
|
||||
)
|
||||
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
|
||||
self.assertEqual(Document.global_objects.count(), 1)
|
||||
|
||||
def test_api_trash_invalid_params(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Existing documents
|
||||
WHEN:
|
||||
- API request to trash with invalid params
|
||||
THEN:
|
||||
- 400 Bad Request
|
||||
"""
|
||||
|
||||
document = Document.objects.create(
|
||||
title="Title",
|
||||
content="content",
|
||||
checksum="checksum",
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
|
||||
self.client.force_login(user=self.user)
|
||||
|
||||
# document isn't in trash
|
||||
resp = self.client.post(
|
||||
"/api/trash/",
|
||||
{"action": "restore", "documents": [document.pk]},
|
||||
)
|
||||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn("have not yet been deleted", resp.data["documents"][0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user