mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
tests
This commit is contained in:
parent
490f59451b
commit
51851ff15a
28
src/documents/tests/test_management_archiver.py
Normal file
28
src/documents/tests/test_management_archiver.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from django.core.management import call_command
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from documents.models import Document
|
||||||
|
from documents.tests.utils import DirectoriesMixin
|
||||||
|
|
||||||
|
sample_file = os.path.join(os.path.dirname(__file__), "samples", "simple.pdf")
|
||||||
|
|
||||||
|
class TestArchiver(DirectoriesMixin, TestCase):
|
||||||
|
|
||||||
|
def make_models(self):
|
||||||
|
self.d1 = Document.objects.create(checksum="A", title="A", content="first document", pk=1, mime_type="application/pdf")
|
||||||
|
#self.d2 = Document.objects.create(checksum="B", title="B", content="second document")
|
||||||
|
#self.d3 = Document.objects.create(checksum="C", title="C", content="unrelated document")
|
||||||
|
|
||||||
|
@mock.patch("documents.management.commands.document_archiver.handle_document")
|
||||||
|
def test_archiver(self, m):
|
||||||
|
|
||||||
|
shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, "0000001.pdf"))
|
||||||
|
self.make_models()
|
||||||
|
|
||||||
|
call_command('document_archiver')
|
||||||
|
|
||||||
|
m.assert_called()
|
@ -17,10 +17,11 @@ def setup_directories():
|
|||||||
dirs.index_dir = os.path.join(dirs.data_dir, "index")
|
dirs.index_dir = os.path.join(dirs.data_dir, "index")
|
||||||
dirs.originals_dir = os.path.join(dirs.media_dir, "documents", "originals")
|
dirs.originals_dir = os.path.join(dirs.media_dir, "documents", "originals")
|
||||||
dirs.thumbnail_dir = os.path.join(dirs.media_dir, "documents", "thumbnails")
|
dirs.thumbnail_dir = os.path.join(dirs.media_dir, "documents", "thumbnails")
|
||||||
|
dirs.archive_dir = os.path.join(dirs.media_dir, "documents", "archive")
|
||||||
|
|
||||||
os.makedirs(dirs.index_dir, exist_ok=True)
|
os.makedirs(dirs.index_dir, exist_ok=True)
|
||||||
os.makedirs(dirs.originals_dir, exist_ok=True)
|
os.makedirs(dirs.originals_dir, exist_ok=True)
|
||||||
os.makedirs(dirs.thumbnail_dir, exist_ok=True)
|
os.makedirs(dirs.archive_dir, exist_ok=True)
|
||||||
|
|
||||||
override_settings(
|
override_settings(
|
||||||
DATA_DIR=dirs.data_dir,
|
DATA_DIR=dirs.data_dir,
|
||||||
@ -28,6 +29,7 @@ def setup_directories():
|
|||||||
MEDIA_ROOT=dirs.media_dir,
|
MEDIA_ROOT=dirs.media_dir,
|
||||||
ORIGINALS_DIR=dirs.originals_dir,
|
ORIGINALS_DIR=dirs.originals_dir,
|
||||||
THUMBNAIL_DIR=dirs.thumbnail_dir,
|
THUMBNAIL_DIR=dirs.thumbnail_dir,
|
||||||
|
ARCHIVE_DIR=dirs.archive_dir,
|
||||||
CONSUMPTION_DIR=dirs.consumption_dir,
|
CONSUMPTION_DIR=dirs.consumption_dir,
|
||||||
INDEX_DIR=dirs.index_dir,
|
INDEX_DIR=dirs.index_dir,
|
||||||
MODEL_FILE=os.path.join(dirs.data_dir, "classification_model.pickle")
|
MODEL_FILE=os.path.join(dirs.data_dir, "classification_model.pickle")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user