mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	sanity checker testing
This commit is contained in:
		| @@ -87,20 +87,18 @@ def check_sanity(): | |||||||
|                         f"Stored: {doc.checksum}, actual: {checksum}." |                         f"Stored: {doc.checksum}, actual: {checksum}." | ||||||
|                     )) |                     )) | ||||||
|  |  | ||||||
|  |         # Check sanity of the archive file. | ||||||
|         if doc.archive_checksum and not doc.archive_filename: |         if doc.archive_checksum and not doc.archive_filename: | ||||||
|             messages.append(SanityError( |             messages.append(SanityError( | ||||||
|                 f"Document {doc.pk} has an archive file checksum, but no " |                 f"Document {doc.pk} has an archive file checksum, but no " | ||||||
|                 f"archive filename." |                 f"archive filename." | ||||||
|             )) |             )) | ||||||
|  |         elif not doc.archive_checksum and doc.archive_filename: | ||||||
|         if not doc.archive_checksum and doc.archive_filename: |  | ||||||
|             messages.append(SanityError( |             messages.append(SanityError( | ||||||
|                 f"Document {doc.pk} has an archive file, but its checksum is " |                 f"Document {doc.pk} has an archive file, but its checksum is " | ||||||
|                 f"missing." |                 f"missing." | ||||||
|             )) |             )) | ||||||
|  |         elif doc.has_archive_version: | ||||||
|         # Check sanity of the archive file. |  | ||||||
|         if doc.has_archive_version: |  | ||||||
|             if not os.path.isfile(doc.archive_path): |             if not os.path.isfile(doc.archive_path): | ||||||
|                 messages.append(SanityError( |                 messages.append(SanityError( | ||||||
|                     f"Archived version of document {doc.pk} does not exist." |                     f"Archived version of document {doc.pk} does not exist." | ||||||
|   | |||||||
| @@ -86,6 +86,19 @@ class TestSanityCheck(DirectoriesMixin, TestCase): | |||||||
|         Path(self.dirs.originals_dir, "orphaned").touch() |         Path(self.dirs.originals_dir, "orphaned").touch() | ||||||
|         self.assertEqual(len(check_sanity()), 1) |         self.assertEqual(len(check_sanity()), 1) | ||||||
|  |  | ||||||
|     def test_all(self): |     def test_error_tostring(self): | ||||||
|         Document.objects.create(title="test", checksum="dgfhj", archive_checksum="dfhg", content="", pk=1, filename="0000001.pdf") |         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())) |         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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler