diff --git a/src/documents/tests/test_logger.py b/src/documents/tests/test_logger.py index 9b14a3902..51a4fad83 100644 --- a/src/documents/tests/test_logger.py +++ b/src/documents/tests/test_logger.py @@ -25,20 +25,20 @@ class TestPaperlessLog(TestCase): # Debug messages are ignored by default self.logger.debug("This is a debugging message", extra=kw) - self.assertEqual(Log.objects.all().count(), 0) - - self.logger.info("This is an informational message", extra=kw) self.assertEqual(Log.objects.all().count(), 1) - self.logger.warning("This is an warning message", extra=kw) + self.logger.info("This is an informational message", extra=kw) self.assertEqual(Log.objects.all().count(), 2) - self.logger.error("This is an error message", extra=kw) + self.logger.warning("This is an warning message", extra=kw) self.assertEqual(Log.objects.all().count(), 3) - self.logger.critical("This is a critical message", extra=kw) + self.logger.error("This is an error message", extra=kw) self.assertEqual(Log.objects.all().count(), 4) + self.logger.critical("This is a critical message", extra=kw) + self.assertEqual(Log.objects.all().count(), 5) + def test_groups(self): kw1 = {"group": uuid.uuid4()} @@ -48,10 +48,6 @@ class TestPaperlessLog(TestCase): with mock.patch("logging.StreamHandler.emit") as __: - # Debug messages are ignored by default - self.logger.debug("This is a debugging message", extra=kw1) - self.assertEqual(Log.objects.all().count(), 0) - self.logger.info("This is an informational message", extra=kw2) self.assertEqual(Log.objects.all().count(), 1) self.assertEqual(Log.objects.filter(group=kw2["group"]).count(), 1) @@ -67,18 +63,3 @@ class TestPaperlessLog(TestCase): self.logger.critical("This is a critical message", extra=kw1) self.assertEqual(Log.objects.all().count(), 4) self.assertEqual(Log.objects.filter(group=kw1["group"]).count(), 2) - - def test_groupped_query(self): - - kw = {"group": uuid.uuid4()} - with mock.patch("logging.StreamHandler.emit") as __: - self.logger.info("Message 0", extra=kw) - self.logger.info("Message 1", extra=kw) - self.logger.info("Message 2", extra=kw) - self.logger.info("Message 3", extra=kw) - - self.assertEqual(Log.objects.all().by_group().count(), 1) - self.assertEqual( - Log.objects.all().by_group()[0]["messages"], - "Message 0\nMessage 1\nMessage 2\nMessage 3" - ) diff --git a/src/paperless_tesseract/tests/test_date.py b/src/paperless_tesseract/tests/test_date.py index eb14f3b61..51317362f 100644 --- a/src/paperless_tesseract/tests/test_date.py +++ b/src/paperless_tesseract/tests/test_date.py @@ -5,7 +5,7 @@ from unittest import mock from uuid import uuid4 from dateutil import tz -from django.test import TestCase +from django.test import TestCase, override_settings from ..parsers import RasterisedDocumentParser from django.conf import settings @@ -16,36 +16,34 @@ class TestDate(TestCase): SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples") SCRATCH = "/tmp/paperless-tests-{}".format(str(uuid4())[:8]) - MOCK_SCRATCH = "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH" # NOQA: E501 - def setUp(self): os.makedirs(self.SCRATCH, exist_ok=True) def tearDown(self): shutil.rmtree(self.SCRATCH) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_1(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) document._text = "lorem ipsum 130218 lorem ipsum" self.assertEqual(document.get_date(), None) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_2(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) document._text = "lorem ipsum 2018 lorem ipsum" self.assertEqual(document.get_date(), None) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_3(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) document._text = "lorem ipsum 20180213 lorem ipsum" self.assertEqual(document.get_date(), None) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_4(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -59,7 +57,7 @@ class TestDate(TestCase): ) ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_5(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -76,7 +74,7 @@ class TestDate(TestCase): ) ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_6(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -93,7 +91,7 @@ class TestDate(TestCase): ) self.assertEqual(document.get_date(), None) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_7(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -111,7 +109,7 @@ class TestDate(TestCase): ) ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_8(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -135,7 +133,7 @@ class TestDate(TestCase): ) ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_date_format_9(self): input_file = os.path.join(self.SAMPLE_FILES, "") document = RasterisedDocumentParser(input_file, None) @@ -157,7 +155,7 @@ class TestDate(TestCase): "paperless_tesseract.parsers.RasterisedDocumentParser.get_text", return_value="01-07-0590 00:00:00" ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_crazy_date_past(self, *args): document = RasterisedDocumentParser("/dev/null", None) document.get_text() @@ -167,7 +165,7 @@ class TestDate(TestCase): "paperless_tesseract.parsers.RasterisedDocumentParser.get_text", return_value="01-07-2350 00:00:00" ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_crazy_date_future(self, *args): document = RasterisedDocumentParser("/dev/null", None) document.get_text() @@ -177,7 +175,7 @@ class TestDate(TestCase): "paperless_tesseract.parsers.RasterisedDocumentParser.get_text", return_value="20 408000l 2475" ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(SCRATCH_DIR=SCRATCH) def test_crazy_date_with_spaces(self, *args): document = RasterisedDocumentParser("/dev/null", None) document.get_text() @@ -187,13 +185,8 @@ class TestDate(TestCase): "paperless_tesseract.parsers.RasterisedDocumentParser.get_text", return_value="No date in here" ) - @mock.patch( - "paperless_tesseract.parsers.RasterisedDocumentParser." - "FILENAME_DATE_ORDER", - new_callable=mock.PropertyMock, - return_value="YMD" - ) - @mock.patch(MOCK_SCRATCH, SCRATCH) + @override_settings(FILENAME_DATE_ORDER="YMD") + @override_settings(SCRATCH_DIR=SCRATCH) def test_filename_date_parse_invalid(self, *args): document = RasterisedDocumentParser("/tmp/20 408000l 2475 - test.pdf", None) document.get_text() diff --git a/src/paperless_tesseract/tests/test_ocr.py b/src/paperless_tesseract/tests/test_ocr.py index 68ab64707..e0d5726ba 100644 --- a/src/paperless_tesseract/tests/test_ocr.py +++ b/src/paperless_tesseract/tests/test_ocr.py @@ -62,10 +62,6 @@ class TestOCR(TestCase): ) @skipIf(not TESSERACT_INSTALLED, "Tesseract not installed. Skipping") - @mock.patch( - "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", - SAMPLE_FILES - ) @mock.patch("paperless_tesseract.parsers.pyocr", FakePyOcr) def test_image_to_string_with_text_free_page(self): """ @@ -77,4 +73,4 @@ class TestOCR(TestCase): text-free pages are now handled correctly so long as we work around this weird exception. """ - image_to_string(["no-text.png", "en"]) + image_to_string([os.path.join(self.SAMPLE_FILES, "no-text.png"), "en"])