mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	fixed most of the test cases
This commit is contained in:
		| @@ -1,66 +1,10 @@ | |||||||
| import re | import re | ||||||
|  |  | ||||||
| from django.test import TestCase | from django.test import TestCase | ||||||
| from unittest import mock |  | ||||||
| from tempfile import TemporaryDirectory |  | ||||||
|  |  | ||||||
| from ..consumer import Consumer |  | ||||||
| from ..models import FileInfo, Tag | from ..models import FileInfo, Tag | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestConsumer(TestCase): |  | ||||||
|  |  | ||||||
|     class DummyParser(object): |  | ||||||
|         pass |  | ||||||
|  |  | ||||||
|     def test__get_parser_class_1_parser(self): |  | ||||||
|         self.assertEqual( |  | ||||||
|             self._get_consumer()._get_parser_class("doc.pdf"), |  | ||||||
|             self.DummyParser |  | ||||||
|         ) |  | ||||||
|  |  | ||||||
|     @mock.patch("documents.consumer.os.makedirs") |  | ||||||
|     @mock.patch("documents.consumer.os.path.exists", return_value=True) |  | ||||||
|     @mock.patch("documents.consumer.document_consumer_declaration.send") |  | ||||||
|     def test__get_parser_class_n_parsers(self, m, *args): |  | ||||||
|  |  | ||||||
|         class DummyParser1(object): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         class DummyParser2(object): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         m.return_value = ( |  | ||||||
|             (None, lambda _: {"weight": 0, "parser": DummyParser1}), |  | ||||||
|             (None, lambda _: {"weight": 1, "parser": DummyParser2}), |  | ||||||
|         ) |  | ||||||
|         with TemporaryDirectory() as tmpdir: |  | ||||||
|             self.assertEqual( |  | ||||||
|                 Consumer(consume=tmpdir)._get_parser_class("doc.pdf"), |  | ||||||
|                 DummyParser2 |  | ||||||
|             ) |  | ||||||
|  |  | ||||||
|     @mock.patch("documents.consumer.os.makedirs") |  | ||||||
|     @mock.patch("documents.consumer.os.path.exists", return_value=True) |  | ||||||
|     @mock.patch("documents.consumer.document_consumer_declaration.send") |  | ||||||
|     def test__get_parser_class_0_parsers(self, m, *args): |  | ||||||
|         m.return_value = ((None, lambda _: None),) |  | ||||||
|         with TemporaryDirectory() as tmpdir: |  | ||||||
|             self.assertIsNone( |  | ||||||
|                 Consumer(consume=tmpdir)._get_parser_class("doc.pdf") |  | ||||||
|             ) |  | ||||||
|  |  | ||||||
|     @mock.patch("documents.consumer.os.makedirs") |  | ||||||
|     @mock.patch("documents.consumer.os.path.exists", return_value=True) |  | ||||||
|     @mock.patch("documents.consumer.document_consumer_declaration.send") |  | ||||||
|     def _get_consumer(self, m, *args): |  | ||||||
|         m.return_value = ( |  | ||||||
|             (None, lambda _: {"weight": 0, "parser": self.DummyParser}), |  | ||||||
|         ) |  | ||||||
|         with TemporaryDirectory() as tmpdir: |  | ||||||
|             return Consumer(consume=tmpdir) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestAttributes(TestCase): | class TestAttributes(TestCase): | ||||||
|  |  | ||||||
|     TAGS = ("tag1", "tag2", "tag3") |     TAGS = ("tag1", "tag2", "tag3") | ||||||
|   | |||||||
							
								
								
									
										50
									
								
								src/documents/tests/test_parsers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/documents/tests/test_parsers.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | from tempfile import TemporaryDirectory | ||||||
|  | from unittest import mock | ||||||
|  |  | ||||||
|  | from django.test import TestCase | ||||||
|  |  | ||||||
|  | from documents.parsers import get_parser_class | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class TestParserDiscovery(TestCase): | ||||||
|  |  | ||||||
|  |     @mock.patch("documents.parsers.document_consumer_declaration.send") | ||||||
|  |     def test__get_parser_class_1_parser(self, m, *args): | ||||||
|  |         class DummyParser(object): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         m.return_value = ( | ||||||
|  |             (None, lambda _: {"weight": 0, "parser": DummyParser}), | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         self.assertEqual( | ||||||
|  |             get_parser_class("doc.pdf"), | ||||||
|  |             DummyParser | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |     @mock.patch("documents.parsers.document_consumer_declaration.send") | ||||||
|  |     def test__get_parser_class_n_parsers(self, m, *args): | ||||||
|  |  | ||||||
|  |         class DummyParser1(object): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         class DummyParser2(object): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         m.return_value = ( | ||||||
|  |             (None, lambda _: {"weight": 0, "parser": DummyParser1}), | ||||||
|  |             (None, lambda _: {"weight": 1, "parser": DummyParser2}), | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         self.assertEqual( | ||||||
|  |             get_parser_class("doc.pdf"), | ||||||
|  |             DummyParser2 | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |     @mock.patch("documents.parsers.document_consumer_declaration.send") | ||||||
|  |     def test__get_parser_class_0_parsers(self, m, *args): | ||||||
|  |         m.return_value = ((None, lambda _: None),) | ||||||
|  |         with TemporaryDirectory() as tmpdir: | ||||||
|  |             self.assertIsNone( | ||||||
|  |                 get_parser_class("doc.pdf") | ||||||
|  |             ) | ||||||
		Reference in New Issue
	
	Block a user
	 Jonas Winkler
					Jonas Winkler