diff --git a/src/paperless_tesseract/tests/test_date.py b/src/paperless_tesseract/tests/test_date.py index 7b1f75f6c..a687cd4f1 100644 --- a/src/paperless_tesseract/tests/test_date.py +++ b/src/paperless_tesseract/tests/test_date.py @@ -12,6 +12,97 @@ from dateutil import tz class TestDate(TestCase): SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples") + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_1(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = "lorem ipsum 130218 lorem ipsum" + self.assertEqual(document.get_date(), + None) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_2(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = "lorem ipsum 2018 lorem ipsum" + self.assertEqual(document.get_date(), + None) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_3(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = "lorem ipsum 20180213 lorem ipsum" + self.assertEqual(document.get_date(), + None) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_4(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = "lorem ipsum 13.02.2018 lorem ipsum" + self.assertEqual(document.get_date(), + datetime.datetime(2018, 2, 13, 0, 0, + tzinfo=tz.tzutc())) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_5(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = ("lorem ipsum 130218, 2018, 20180213 and " + "13.02.2018 lorem ipsum") + self.assertEqual(document.get_date(), + datetime.datetime(2018, 2, 13, 0, 0, + tzinfo=tz.tzutc())) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_6(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = ("lorem ipsum\n" + "Wohnort\n" + "3100\n" + "IBAN\n" + "AT87 4534\n" + "1234\n" + "1234 5678\n" + "BIC\n" + "lorem ipsum") + self.assertEqual(document.get_date(), + None) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_date_format_7(self): + input_file = os.path.join(self.SAMPLE_FILES, "") + document = RasterisedDocumentParser(input_file) + document.TEXT_CACHE = ("lorem ipsum\n" + "März 2019\n" + "lorem ipsum") + self.assertEqual(document.get_date(), + datetime.datetime(2019, 3, 1, 0, 0, + tzinfo=tz.tzutc())) + @mock.patch( "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", SAMPLE_FILES