From fc82121604fbec5aad1c7e04b27e49557523f922 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Thu, 7 Jan 2021 15:20:00 +0100 Subject: [PATCH] update tests, remove dead code --- src/documents/serialisers.py | 7 ------- src/documents/tests/test_api.py | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 66f5f883f..70a44d3fd 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -382,13 +382,6 @@ class PostDocumentSerializer(serializers.Serializer): return document.name, document_data - def validate_title(self, title): - if title: - return title - else: - # do not return empty strings. - return None - def validate_correspondent(self, correspondent): if correspondent: return correspondent.id diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index dbe8f881c..5f81b83b6 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -114,8 +114,6 @@ class TestDocumentApi(DirectoriesMixin, APITestCase): results = response.data['results'] self.assertEqual(len(results[0]), 0) - - def test_document_actions(self): _, filename = tempfile.mkstemp(dir=self.dirs.originals_dir) @@ -455,6 +453,23 @@ class TestDocumentApi(DirectoriesMixin, APITestCase): self.assertIsNone(kwargs['override_document_type_id']) self.assertIsNone(kwargs['override_tag_ids']) + @mock.patch("documents.views.async_task") + def test_upload_empty_metadata(self, m): + + with open(os.path.join(os.path.dirname(__file__), "samples", "simple.pdf"), "rb") as f: + response = self.client.post("/api/documents/post_document/", {"document": f, "title": "", "correspondent": "", "document_type": ""}) + + self.assertEqual(response.status_code, 200) + + m.assert_called_once() + + args, kwargs = m.call_args + self.assertEqual(kwargs['override_filename'], "simple.pdf") + self.assertIsNone(kwargs['override_title']) + self.assertIsNone(kwargs['override_correspondent_id']) + self.assertIsNone(kwargs['override_document_type_id']) + self.assertIsNone(kwargs['override_tag_ids']) + @mock.patch("documents.views.async_task") def test_upload_invalid_form(self, m):