2020-12-15 13:26:01 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
from documents.tests.utils import DirectoriesMixin
|
|
|
|
|
from paperless_text.parsers import TextDocumentParser
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTextParser(DirectoriesMixin, TestCase):
|
|
|
|
|
def test_thumbnail(self):
|
|
|
|
|
|
|
|
|
|
parser = TextDocumentParser(None)
|
|
|
|
|
|
|
|
|
|
# just make sure that it does not crash
|
2022-02-27 15:26:41 +01:00
|
|
|
f = parser.get_thumbnail(
|
2022-03-11 10:55:51 -08:00
|
|
|
os.path.join(os.path.dirname(__file__), "samples", "test.txt"),
|
|
|
|
|
"text/plain",
|
2022-02-27 15:26:41 +01:00
|
|
|
)
|
2020-12-15 13:26:01 +01:00
|
|
|
self.assertTrue(os.path.isfile(f))
|
|
|
|
|
|
|
|
|
|
def test_parse(self):
|
|
|
|
|
|
|
|
|
|
parser = TextDocumentParser(None)
|
|
|
|
|
|
2022-02-27 15:26:41 +01:00
|
|
|
parser.parse(
|
2022-03-11 10:55:51 -08:00
|
|
|
os.path.join(os.path.dirname(__file__), "samples", "test.txt"),
|
|
|
|
|
"text/plain",
|
2022-02-27 15:26:41 +01:00
|
|
|
)
|
2020-12-15 13:26:01 +01:00
|
|
|
|
|
|
|
|
self.assertEqual(parser.get_text(), "This is a test file.\n")
|
|
|
|
|
self.assertIsNone(parser.get_archive_path())
|