diff --git a/src/documents/sanity_checker.py b/src/documents/sanity_checker.py index 61e927c82..2d30a59d7 100644 --- a/src/documents/sanity_checker.py +++ b/src/documents/sanity_checker.py @@ -87,20 +87,18 @@ def check_sanity(): f"Stored: {doc.checksum}, actual: {checksum}." )) + # Check sanity of the archive file. if doc.archive_checksum and not doc.archive_filename: messages.append(SanityError( f"Document {doc.pk} has an archive file checksum, but no " f"archive filename." )) - - if not doc.archive_checksum and doc.archive_filename: + elif not doc.archive_checksum and doc.archive_filename: messages.append(SanityError( f"Document {doc.pk} has an archive file, but its checksum is " f"missing." )) - - # Check sanity of the archive file. - if doc.has_archive_version: + elif doc.has_archive_version: if not os.path.isfile(doc.archive_path): messages.append(SanityError( f"Archived version of document {doc.pk} does not exist." diff --git a/src/documents/tests/test_sanity_check.py b/src/documents/tests/test_sanity_check.py index d7ab1e07f..fae18aaca 100644 --- a/src/documents/tests/test_sanity_check.py +++ b/src/documents/tests/test_sanity_check.py @@ -86,6 +86,19 @@ class TestSanityCheck(DirectoriesMixin, TestCase): Path(self.dirs.originals_dir, "orphaned").touch() self.assertEqual(len(check_sanity()), 1) - def test_all(self): - Document.objects.create(title="test", checksum="dgfhj", archive_checksum="dfhg", content="", pk=1, filename="0000001.pdf") + def test_error_tostring(self): + Document.objects.create(title="test", checksum="dgfhj", archive_checksum="dfhg", content="", pk=1, filename="0000001.pdf", archive_filename="0000001.pdf") string = str(SanityFailedError(check_sanity())) + self.assertIsNotNone(string) + + def test_archive_filename_no_checksum(self): + doc = self.make_test_data() + doc.archive_checksum = None + doc.save() + self.assertEqual(len(check_sanity()), 2) + + def test_archive_checksum_no_filename(self): + doc = self.make_test_data() + doc.archive_filename = None + doc.save() + self.assertEqual(len(check_sanity()), 2)