mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Added some tests for the importer
This commit is contained in:
parent
070463b85a
commit
ba7878b9aa
@ -20,13 +20,6 @@ class Command(Renderable, BaseCommand):
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("source")
|
||||
parser.add_argument(
|
||||
'--ignore-absent',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help="If the manifest refers to a document that doesn't exist, "
|
||||
"ignore it and attempt to import what it can"
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
BaseCommand.__init__(self, *args, **kwargs)
|
||||
@ -80,18 +73,14 @@ class Command(Renderable, BaseCommand):
|
||||
if "__exported_file_name__" not in record:
|
||||
raise CommandError(
|
||||
'The manifest file contains a record which does not '
|
||||
'refer to an actual document file. If you want to import '
|
||||
'the rest anyway (skipping such references) call the '
|
||||
'importer with --ignore-absent'
|
||||
'refer to an actual document file.'
|
||||
)
|
||||
|
||||
doc_file = record["__exported_file_name__"]
|
||||
if not os.path.exists(os.path.join(self.source, doc_file)):
|
||||
raise CommandError(
|
||||
'The manifest file refers to "{}" which does not '
|
||||
'appear to be in the source directory. If you want to '
|
||||
'import the rest anyway (skipping such references) call '
|
||||
'the importer with --ignore-absent'.format(doc_file)
|
||||
'appear to be in the source directory.'.format(doc_file)
|
||||
)
|
||||
|
||||
def _import_files_from_manifest(self):
|
||||
|
36
src/documents/tests/test_importer.py
Normal file
36
src/documents/tests/test_importer.py
Normal file
@ -0,0 +1,36 @@
|
||||
from django.core.management.base import CommandError
|
||||
from django.test import TestCase
|
||||
|
||||
from ..management.commands.document_importer import Command
|
||||
|
||||
|
||||
class TestImporter(TestCase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
TestCase.__init__(self, *args, **kwargs)
|
||||
|
||||
def test_check_manifest_exists(self):
|
||||
cmd = Command()
|
||||
self.assertRaises(
|
||||
CommandError, cmd._check_manifest_exists, "/tmp/manifest.json")
|
||||
|
||||
def test_check_manifest(self):
|
||||
|
||||
cmd = Command()
|
||||
cmd.source = "/tmp"
|
||||
|
||||
cmd.manifest = [{"model": "documents.document"}]
|
||||
with self.assertRaises(CommandError) as cm:
|
||||
cmd._check_manifest()
|
||||
self.assertTrue(
|
||||
'The manifest file contains a record' in str(cm.exception))
|
||||
|
||||
cmd.manifest = [{
|
||||
"model": "documents.document",
|
||||
"__exported_file_name__": "noexist.pdf"
|
||||
}]
|
||||
# self.assertRaises(CommandError, cmd._check_manifest)
|
||||
with self.assertRaises(CommandError) as cm:
|
||||
cmd._check_manifest()
|
||||
self.assertTrue(
|
||||
'The manifest file refers to "noexist.pdf"' in str(cm.exception))
|
Loading…
x
Reference in New Issue
Block a user