1from django.core.management.base import CommandError
2from django.test import TestCase
3
4from ..management.commands.document_importer import Command
5
6from documents.settings import EXPORTER_FILE_NAME
7
8
9class TestImporter(TestCase):
10
11    def __init__(self, *args, **kwargs):
12        TestCase.__init__(self, *args, **kwargs)
13
14    def test_check_manifest_exists(self):
15        cmd = Command()
16        self.assertRaises(
17            CommandError, cmd._check_manifest_exists, "/tmp/manifest.json")
18
19    def test_check_manifest(self):
20
21        cmd = Command()
22        cmd.source = "/tmp"
23
24        cmd.manifest = [{"model": "documents.document"}]
25        with self.assertRaises(CommandError) as cm:
26            cmd._check_manifest()
27        self.assertTrue(
28            'The manifest file contains a record' in str(cm.exception))
29
30        cmd.manifest = [{
31            "model": "documents.document",
32            EXPORTER_FILE_NAME: "noexist.pdf"
33        }]
34        # self.assertRaises(CommandError, cmd._check_manifest)
35        with self.assertRaises(CommandError) as cm:
36            cmd._check_manifest()
37        self.assertTrue(
38            'The manifest file refers to "noexist.pdf"' in str(cm.exception))
39