mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Rework tests to write to /tmp
Originally the test wrote scratch data inside the repo dir, which meant manual cleanup. Now it writes to `/tmp/paperless-tests-<random-string>` and cleans up after itself.
This commit is contained in:
parent
cebb8b9fa2
commit
c90ed2da1d
@ -1,20 +1,29 @@
|
|||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
from unittest import skipIf, mock
|
import shutil
|
||||||
|
from unittest import mock
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
import pyocr
|
from dateutil import tz
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from ..parsers import RasterisedDocumentParser
|
from ..parsers import RasterisedDocumentParser
|
||||||
import datetime
|
|
||||||
from dateutil import tz
|
|
||||||
|
|
||||||
|
|
||||||
class TestDate(TestCase):
|
class TestDate(TestCase):
|
||||||
|
|
||||||
SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples")
|
SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples")
|
||||||
|
SCRATCH = "/tmp/paperless-tests-{}".format(str(uuid4())[:8])
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
os.makedirs(self.SCRATCH, exist_ok=True)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.SCRATCH)
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_1_pdf(self):
|
def test_get_text_1_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.pdf")
|
||||||
@ -27,7 +36,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_1_png(self):
|
def test_get_text_1_png(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.png")
|
||||||
@ -40,7 +49,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_2_pdf(self):
|
def test_get_text_2_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.pdf")
|
||||||
@ -53,7 +62,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_2_png(self):
|
def test_get_text_2_png(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.png")
|
||||||
@ -66,7 +75,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_3_pdf(self):
|
def test_get_text_3_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.pdf")
|
||||||
@ -79,7 +88,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_3_png(self):
|
def test_get_text_3_png(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.png")
|
||||||
@ -92,7 +101,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_4_pdf(self):
|
def test_get_text_4_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.pdf")
|
||||||
@ -105,7 +114,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_4_png(self):
|
def test_get_text_4_png(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.png")
|
||||||
@ -118,7 +127,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_5_pdf(self):
|
def test_get_text_5_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.pdf")
|
||||||
@ -131,7 +140,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_5_png(self):
|
def test_get_text_5_png(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.png")
|
||||||
@ -144,7 +153,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_6_pdf_us(self):
|
def test_get_text_6_pdf_us(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
|
||||||
@ -158,7 +167,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_6_png_us(self):
|
def test_get_text_6_png_us(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
|
||||||
@ -172,7 +181,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_6_pdf_eu(self):
|
def test_get_text_6_pdf_eu(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
|
||||||
@ -183,7 +192,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_6_png_eu(self):
|
def test_get_text_6_png_eu(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
|
||||||
@ -194,7 +203,7 @@ class TestDate(TestCase):
|
|||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
|
||||||
SAMPLE_FILES
|
SCRATCH
|
||||||
)
|
)
|
||||||
def test_get_text_7_pdf(self):
|
def test_get_text_7_pdf(self):
|
||||||
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_7.pdf")
|
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_7.pdf")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user