pfwb/tests: add test on the command archive2
This commit is contained in:
parent
4089057600
commit
d17040d901
|
@ -36,6 +36,19 @@ class stderr_output(object):
|
|||
return ret
|
||||
return f
|
||||
|
||||
class stdout_output(object):
|
||||
def __init__(self, output):
|
||||
self.output = output
|
||||
|
||||
def __call__(self, func):
|
||||
@wraps(func)
|
||||
def f(testcase, *args, **kwargs):
|
||||
with captured_output() as (out, err):
|
||||
ret = func(testcase, *args, **kwargs)
|
||||
testcase.assertEqual(self.output, out.getvalue())
|
||||
return ret
|
||||
return f
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.core import management
|
||||
|
@ -296,3 +309,60 @@ class PushDocumentTestCase(TestCase):
|
|||
self.assertEquals(json_content['sender'],
|
||||
u'{0} {1} ({2})'.format(FROM_FIRST_NAME,
|
||||
FROM_LAST_NAME, FROM_USERNAME))
|
||||
|
||||
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
|
||||
@override_settings(DOCBOW_PFWB_GED_DIRECTORY=None)
|
||||
class ArchiveTestCase(TestCase):
|
||||
def setUp(self):
|
||||
import datetime
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
self.archive_dir = tempfile.mkdtemp()
|
||||
FROM_USERNAME = 'from_user'
|
||||
FROM_FIRST_NAME = 'from_first_name'
|
||||
FROM_LAST_NAME = 'from_last_name'
|
||||
self.from_user = User.objects.create(username=FROM_USERNAME,
|
||||
first_name=FROM_FIRST_NAME, last_name=FROM_LAST_NAME)
|
||||
self.to_user = User.objects.create(username='to_user')
|
||||
self.filetype = FileType.objects.create(name='filetype')
|
||||
self.plone_filetype = PloneFileType.objects.create(filetype=self.filetype,
|
||||
plone_portal_type='plone-portal-type')
|
||||
DESCRIPTION = 'description'
|
||||
self.document = Document.objects.create(sender=self.from_user,
|
||||
filetype=self.filetype,
|
||||
comment=DESCRIPTION,
|
||||
date=datetime.date.today()-datetime.timedelta(days=366))
|
||||
self.attached_file = AttachedFile(name='attached-file',
|
||||
document=self.document, kind=None)
|
||||
CONTENT = 'content'
|
||||
self.attached_file.content.save('attached-file',
|
||||
ContentFile(CONTENT))
|
||||
|
||||
def tearDown(self):
|
||||
import shutil
|
||||
|
||||
shutil.rmtree(self.archive_dir)
|
||||
|
||||
def test_archive(self):
|
||||
import os.path
|
||||
import glob
|
||||
import datetime
|
||||
|
||||
with captured_output() as (out, err):
|
||||
management.call_command('archive2', self.archive_dir, 100)
|
||||
l = glob.glob(os.path.join(self.archive_dir, '*'))
|
||||
self.assertEquals(len(l), 1)
|
||||
self.assertTrue(l[0].split('T')[0],
|
||||
datetime.datetime.today().isoformat())
|
||||
archive_dir = os.path.join(self.archive_dir, l[0])
|
||||
self.assertTrue(os.path.exists(os.path.join(archive_dir, 'doc')))
|
||||
self.assertTrue(os.path.exists(os.path.join(archive_dir, 'doc',
|
||||
str(self.document.id))))
|
||||
self.assertTrue(os.path.exists(os.path.join(archive_dir, 'doc',
|
||||
str(self.document.id), 'document.json')))
|
||||
self.assertTrue(os.path.exists(os.path.join(archive_dir, 'doc',
|
||||
str(self.document.id), 'attached_file_%s.json' %
|
||||
self.attached_file.id)))
|
||||
self.assertTrue(os.path.exists(os.path.join(archive_dir,
|
||||
'journal.txt')))
|
||||
|
||||
|
|
Loading…
Reference in New Issue