mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-14 10:36:58 +01:00
Chore: Initial conversion to pytest fixtures (#7110)
This commit is contained in:
parent
1b9cf5121b
commit
3cf73a77ac
17 changed files with 1051 additions and 753 deletions
|
|
@ -1,37 +1,26 @@
|
|||
from pathlib import Path
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
from documents.tests.utils import FileSystemAssertsMixin
|
||||
from paperless_text.parsers import TextDocumentParser
|
||||
|
||||
|
||||
class TestTextParser(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
SAMPLE_DIR = Path(__file__).resolve().parent / "samples"
|
||||
|
||||
def test_thumbnail(self):
|
||||
parser = TextDocumentParser(None)
|
||||
|
||||
class TestTextParser:
|
||||
def test_thumbnail(self, text_parser: TextDocumentParser, sample_txt_file: Path):
|
||||
# just make sure that it does not crash
|
||||
f = parser.get_thumbnail(
|
||||
self.SAMPLE_DIR / "test.txt",
|
||||
"text/plain",
|
||||
)
|
||||
self.assertIsFile(f)
|
||||
f = text_parser.get_thumbnail(sample_txt_file, "text/plain")
|
||||
assert f.exists()
|
||||
assert f.is_file()
|
||||
|
||||
def test_parse(self):
|
||||
parser = TextDocumentParser(None)
|
||||
def test_parse(self, text_parser: TextDocumentParser, sample_txt_file: Path):
|
||||
text_parser.parse(sample_txt_file, "text/plain")
|
||||
|
||||
parser.parse(
|
||||
self.SAMPLE_DIR / "test.txt",
|
||||
"text/plain",
|
||||
)
|
||||
assert text_parser.get_text() == "This is a test file.\n"
|
||||
assert text_parser.get_archive_path() is None
|
||||
|
||||
self.assertEqual(parser.get_text(), "This is a test file.\n")
|
||||
self.assertIsNone(parser.get_archive_path())
|
||||
|
||||
def test_parse_invalid_bytes(self):
|
||||
def test_parse_invalid_bytes(
|
||||
self,
|
||||
text_parser: TextDocumentParser,
|
||||
malformed_txt_file: Path,
|
||||
):
|
||||
"""
|
||||
GIVEN:
|
||||
- Text file which contains invalid UTF bytes
|
||||
|
|
@ -41,12 +30,8 @@ class TestTextParser(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||
- Parsing continues
|
||||
- Invalid bytes are removed
|
||||
"""
|
||||
parser = TextDocumentParser(None)
|
||||
|
||||
parser.parse(
|
||||
self.SAMPLE_DIR / "decode_error.txt",
|
||||
"text/plain",
|
||||
)
|
||||
text_parser.parse(malformed_txt_file, "text/plain")
|
||||
|
||||
self.assertEqual(parser.get_text(), "Pantothens<EFBFBD>ure\n")
|
||||
self.assertIsNone(parser.get_archive_path())
|
||||
assert text_parser.get_text() == "Pantothens<EFBFBD>ure\n"
|
||||
assert text_parser.get_archive_path() is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue