mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	bug fixes, test case fixes
This commit is contained in:
		| @@ -37,7 +37,7 @@ class Consumer(LoggingMixin): | |||||||
|     def _send_progress(self, current_progress, max_progress, status, |     def _send_progress(self, current_progress, max_progress, status, | ||||||
|                        message, document_id=None): |                        message, document_id=None): | ||||||
|         payload = { |         payload = { | ||||||
|             'filename': os.path.basename(self.filename), |             'filename': os.path.basename(self.filename) if self.filename else None,  # NOQA: E501 | ||||||
|             'task_id': self.task_id, |             'task_id': self.task_id, | ||||||
|             'current_progress': current_progress, |             'current_progress': current_progress, | ||||||
|             'max_progress': max_progress, |             'max_progress': max_progress, | ||||||
| @@ -70,7 +70,7 @@ class Consumer(LoggingMixin): | |||||||
|         if not os.path.isfile(self.path): |         if not os.path.isfile(self.path): | ||||||
|             self._fail( |             self._fail( | ||||||
|                 _("File not found"), |                 _("File not found"), | ||||||
|                 f"Cannot consume {self.path}: It is not a file." |                 f"Cannot consume {self.path}: File not found." | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|     def pre_check_duplicate(self): |     def pre_check_duplicate(self): | ||||||
| @@ -80,7 +80,7 @@ class Consumer(LoggingMixin): | |||||||
|             if settings.CONSUMER_DELETE_DUPLICATES: |             if settings.CONSUMER_DELETE_DUPLICATES: | ||||||
|                 os.unlink(self.path) |                 os.unlink(self.path) | ||||||
|             self._fail( |             self._fail( | ||||||
|                 _("Document is a duplicate"), |                 _("Document already exists"), | ||||||
|                 f"Not consuming {self.filename}: It is a duplicate." |                 f"Not consuming {self.filename}: It is a duplicate." | ||||||
|             ) |             ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -261,7 +261,7 @@ class DocumentParser(LoggingMixin): | |||||||
|     `paperless_tesseract.parsers` for inspiration. |     `paperless_tesseract.parsers` for inspiration. | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     def __init__(self, logging_group, progress_callback): |     def __init__(self, logging_group, progress_callback=None): | ||||||
|         super().__init__() |         super().__init__() | ||||||
|         self.logging_group = logging_group |         self.logging_group = logging_group | ||||||
|         os.makedirs(settings.SCRATCH_DIR, exist_ok=True) |         os.makedirs(settings.SCRATCH_DIR, exist_ok=True) | ||||||
|   | |||||||
| @@ -170,7 +170,7 @@ class DummyParser(DocumentParser): | |||||||
|         raise NotImplementedError() |         raise NotImplementedError() | ||||||
|  |  | ||||||
|     def __init__(self, logging_group, scratch_dir, archive_path): |     def __init__(self, logging_group, scratch_dir, archive_path): | ||||||
|         super(DummyParser, self).__init__(logging_group) |         super(DummyParser, self).__init__(logging_group, None) | ||||||
|         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) |         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) | ||||||
|         self.archive_path = archive_path |         self.archive_path = archive_path | ||||||
|  |  | ||||||
| @@ -212,10 +212,10 @@ def fake_magic_from_file(file, mime=False): | |||||||
| @mock.patch("documents.consumer.magic.from_file", fake_magic_from_file) | @mock.patch("documents.consumer.magic.from_file", fake_magic_from_file) | ||||||
| class TestConsumer(DirectoriesMixin, TestCase): | class TestConsumer(DirectoriesMixin, TestCase): | ||||||
|  |  | ||||||
|     def make_dummy_parser(self, logging_group): |     def make_dummy_parser(self, logging_group, progress_callback=None): | ||||||
|         return DummyParser(logging_group, self.dirs.scratch_dir, self.get_test_archive_file()) |         return DummyParser(logging_group, self.dirs.scratch_dir, self.get_test_archive_file()) | ||||||
|  |  | ||||||
|     def make_faulty_parser(self, logging_group): |     def make_faulty_parser(self, logging_group, progress_callback=None): | ||||||
|         return FaultyParser(logging_group, self.dirs.scratch_dir) |         return FaultyParser(logging_group, self.dirs.scratch_dir) | ||||||
|  |  | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
| @@ -312,7 +312,7 @@ class TestConsumer(DirectoriesMixin, TestCase): | |||||||
|         try: |         try: | ||||||
|             self.consumer.try_consume_file("non-existing-file") |             self.consumer.try_consume_file("non-existing-file") | ||||||
|         except ConsumerError as e: |         except ConsumerError as e: | ||||||
|             self.assertTrue(str(e).endswith('It is not a file')) |             self.assertTrue(str(e).endswith('File not found.')) | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         self.fail("Should throw exception") |         self.fail("Should throw exception") | ||||||
| @@ -350,7 +350,7 @@ class TestConsumer(DirectoriesMixin, TestCase): | |||||||
|         try: |         try: | ||||||
|             self.consumer.try_consume_file(self.get_test_file()) |             self.consumer.try_consume_file(self.get_test_file()) | ||||||
|         except ConsumerError as e: |         except ConsumerError as e: | ||||||
|             self.assertEqual("Unsupported mime type application/pdf of file sample.pdf", str(e)) |             self.assertEqual(str(e), "sample.pdf: Unsupported mime type application/pdf") | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         self.fail("Should throw exception") |         self.fail("Should throw exception") | ||||||
| @@ -366,7 +366,7 @@ class TestConsumer(DirectoriesMixin, TestCase): | |||||||
|         try: |         try: | ||||||
|             self.consumer.try_consume_file(self.get_test_file()) |             self.consumer.try_consume_file(self.get_test_file()) | ||||||
|         except ConsumerError as e: |         except ConsumerError as e: | ||||||
|             self.assertEqual(str(e), "Does not compute.") |             self.assertEqual(str(e), "sample.pdf: Error while consuming document sample.pdf: Does not compute.") | ||||||
|             return |             return | ||||||
|  |  | ||||||
|         self.fail("Should throw exception.") |         self.fail("Should throw exception.") | ||||||
| @@ -378,7 +378,7 @@ class TestConsumer(DirectoriesMixin, TestCase): | |||||||
|         try: |         try: | ||||||
|             self.consumer.try_consume_file(filename) |             self.consumer.try_consume_file(filename) | ||||||
|         except ConsumerError as e: |         except ConsumerError as e: | ||||||
|             self.assertEqual(str(e), "NO.") |             self.assertEqual(str(e), "sample.pdf: The following error occured while consuming sample.pdf: NO.") | ||||||
|         else: |         else: | ||||||
|             self.fail("Should raise exception") |             self.fail("Should raise exception") | ||||||
|  |  | ||||||
| @@ -482,6 +482,7 @@ class PreConsumeTestCase(TestCase): | |||||||
|     @override_settings(PRE_CONSUME_SCRIPT="does-not-exist") |     @override_settings(PRE_CONSUME_SCRIPT="does-not-exist") | ||||||
|     def test_pre_consume_script_not_found(self, m): |     def test_pre_consume_script_not_found(self, m): | ||||||
|         c = Consumer() |         c = Consumer() | ||||||
|  |         c.filename = "somefile.pdf" | ||||||
|         c.path = "path-to-file" |         c.path = "path-to-file" | ||||||
|         self.assertRaises(ConsumerError, c.run_pre_consume_script) |         self.assertRaises(ConsumerError, c.run_pre_consume_script) | ||||||
|  |  | ||||||
| @@ -523,8 +524,9 @@ class PostConsumeTestCase(TestCase): | |||||||
|     @override_settings(POST_CONSUME_SCRIPT="does-not-exist") |     @override_settings(POST_CONSUME_SCRIPT="does-not-exist") | ||||||
|     def test_post_consume_script_not_found(self): |     def test_post_consume_script_not_found(self): | ||||||
|         doc = Document.objects.create(title="Test", mime_type="application/pdf") |         doc = Document.objects.create(title="Test", mime_type="application/pdf") | ||||||
|  |         c = Consumer() | ||||||
|         self.assertRaises(ConsumerError, Consumer().run_post_consume_script, doc) |         c.filename = "somefile.pdf" | ||||||
|  |         self.assertRaises(ConsumerError, c.run_post_consume_script, doc) | ||||||
|  |  | ||||||
|     @mock.patch("documents.consumer.Popen") |     @mock.patch("documents.consumer.Popen") | ||||||
|     def test_post_consume_script_simple(self, m): |     def test_post_consume_script_simple(self, m): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler