Backport test improvements
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -8,7 +8,8 @@ from ..models import DocumentType
|
||||
|
||||
from .literals import (
|
||||
TEST_DOCUMENT_TYPE_LABEL, TEST_SMALL_DOCUMENT_FILENAME,
|
||||
TEST_DOCUMENT_TYPE_QUICK_LABEL
|
||||
TEST_DOCUMENT_TYPE_QUICK_LABEL, TEST_SMALL_DOCUMENT_PATH,
|
||||
TEST_VERSION_COMMENT
|
||||
)
|
||||
|
||||
__all__ = ('DocumentTestMixin',)
|
||||
@@ -18,26 +19,34 @@ class DocumentTestMixin(object):
|
||||
auto_create_document_type = True
|
||||
auto_upload_document = True
|
||||
test_document_filename = TEST_SMALL_DOCUMENT_FILENAME
|
||||
test_document_path = None
|
||||
|
||||
def _create_document_type(self):
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
self.test_document_type = self.document_type
|
||||
|
||||
def upload_document(self):
|
||||
def upload_document(self, label=None):
|
||||
self._calculate_test_document_path()
|
||||
|
||||
if not label:
|
||||
label = self.test_document_filename
|
||||
|
||||
with open(self.test_document_path, mode='rb') as file_object:
|
||||
document = self.document_type.new_document(
|
||||
file_object=file_object, label=self.test_document_filename
|
||||
file_object=file_object, label=label
|
||||
)
|
||||
|
||||
self.test_document = document
|
||||
return document
|
||||
|
||||
def _calculate_test_document_path(self):
|
||||
self.test_document_path = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'documents', 'tests', 'contrib',
|
||||
'sample_documents', self.test_document_filename
|
||||
)
|
||||
if not self.test_document_path:
|
||||
self.test_document_path = os.path.join(
|
||||
settings.BASE_DIR, 'apps', 'documents', 'tests', 'contrib',
|
||||
'sample_documents', self.test_document_filename
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentTestMixin, self).setUp()
|
||||
@@ -54,8 +63,16 @@ class DocumentTestMixin(object):
|
||||
super(DocumentTestMixin, self).tearDown()
|
||||
|
||||
|
||||
class DocumentVersionTestMixin(object):
|
||||
def _upload_new_version(self):
|
||||
with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object:
|
||||
self.test_document.new_version(
|
||||
comment=TEST_VERSION_COMMENT, file_object=file_object
|
||||
)
|
||||
|
||||
|
||||
class DocumentTypeQuickLabelTestMixin(object):
|
||||
def _create_quick_label(self):
|
||||
self.document_type_filename = self.document_type.filenames.create(
|
||||
def _create_test_quick_label(self):
|
||||
self.test_document_type_filename = self.test_document_type.filenames.create(
|
||||
filename=TEST_DOCUMENT_TYPE_QUICK_LABEL
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user