added sanity checker management command for manual execution #534

This commit is contained in:
jonaswinkler
2021-02-13 16:39:29 +01:00
parent 508260c6a9
commit a0c1887fc3
6 changed files with 101 additions and 3 deletions

View File

@@ -65,6 +65,7 @@ class TestArchiver(DirectoriesMixin, TestCase):
self.assertEqual(doc1.archive_filename, "document.pdf")
self.assertEqual(doc2.archive_filename, "document_01.pdf")
class TestDecryptDocuments(TestCase):
@override_settings(
@@ -154,3 +155,37 @@ class TestCreateClassifier(TestCase):
call_command("document_create_classifier")
m.assert_called_once()
class TestSanityChecker(DirectoriesMixin, TestCase):
def test_no_errors(self):
with self.assertLogs() as capture:
call_command("document_sanity_checker")
self.assertEqual(len(capture.output), 1)
self.assertIn("No issues found.", capture.output[0])
@mock.patch("documents.management.commands.document_sanity_checker.logger.warning")
@mock.patch("documents.management.commands.document_sanity_checker.logger.error")
def test_warnings(self, error, warning):
doc = Document.objects.create(title="test", filename="test.pdf", checksum="d41d8cd98f00b204e9800998ecf8427e")
Path(doc.source_path).touch()
Path(doc.thumbnail_path).touch()
call_command("document_sanity_checker")
error.assert_not_called()
warning.assert_called()
@mock.patch("documents.management.commands.document_sanity_checker.logger.warning")
@mock.patch("documents.management.commands.document_sanity_checker.logger.error")
def test_errors(self, error, warning):
doc = Document.objects.create(title="test", content="test", filename="test.pdf", checksum="abc")
Path(doc.source_path).touch()
Path(doc.thumbnail_path).touch()
call_command("document_sanity_checker")
warning.assert_not_called()
error.assert_called()