mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
fixed most of the tests
This commit is contained in:
@@ -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()
|
||||
|
@@ -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"])
|
||||
|
Reference in New Issue
Block a user