Consolidate some document indexing test code into a new mixin.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from .mixins import * # NOQA
|
||||||
|
|||||||
14
mayan/apps/document_indexing/tests/mixins.py
Normal file
14
mayan/apps/document_indexing/tests/mixins.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from ..models import Index
|
||||||
|
|
||||||
|
from .literals import TEST_INDEX_LABEL
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentIndexingTestMixin(object):
|
||||||
|
def _create_index(self):
|
||||||
|
# Create empty index
|
||||||
|
self.index = Index.objects.create(label=TEST_INDEX_LABEL)
|
||||||
|
|
||||||
|
# Add our document type to the new index
|
||||||
|
self.index.document_types.add(self.document_type)
|
||||||
@@ -10,16 +10,14 @@ from metadata.models import MetadataType, DocumentTypeMetadataType
|
|||||||
from ..models import Index, IndexInstanceNode, IndexTemplateNode
|
from ..models import Index, IndexInstanceNode, IndexTemplateNode
|
||||||
|
|
||||||
from .literals import (
|
from .literals import (
|
||||||
TEST_INDEX_LABEL, TEST_INDEX_TEMPLATE_METADATA_EXPRESSION,
|
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION, TEST_METADATA_TYPE_LABEL,
|
||||||
TEST_METADATA_TYPE_LABEL, TEST_METADATA_TYPE_NAME
|
TEST_METADATA_TYPE_NAME
|
||||||
)
|
)
|
||||||
|
from .mixins import DocumentIndexingTestMixin
|
||||||
|
|
||||||
|
|
||||||
@override_settings(OCR_AUTO_OCR=False)
|
@override_settings(OCR_AUTO_OCR=False)
|
||||||
class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase):
|
||||||
def setUp(self):
|
|
||||||
super(IndexTestCase, self).setUp()
|
|
||||||
|
|
||||||
def test_indexing(self):
|
def test_indexing(self):
|
||||||
metadata_type = MetadataType.objects.create(
|
metadata_type = MetadataType.objects.create(
|
||||||
name=TEST_METADATA_TYPE_NAME, label=TEST_METADATA_TYPE_LABEL
|
name=TEST_METADATA_TYPE_NAME, label=TEST_METADATA_TYPE_LABEL
|
||||||
@@ -28,15 +26,11 @@ class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
|||||||
document_type=self.document_type, metadata_type=metadata_type
|
document_type=self.document_type, metadata_type=metadata_type
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create empty index
|
self._create_index()
|
||||||
index = Index.objects.create(label=TEST_INDEX_LABEL)
|
|
||||||
|
|
||||||
# Add our document type to the new index
|
|
||||||
index.document_types.add(self.document_type)
|
|
||||||
|
|
||||||
# Create simple index template
|
# Create simple index template
|
||||||
root = index.template_root
|
root = self.index.template_root
|
||||||
index.node_templates.create(
|
self.index.node_templates.create(
|
||||||
parent=root, expression=TEST_INDEX_TEMPLATE_METADATA_EXPRESSION,
|
parent=root, expression=TEST_INDEX_TEMPLATE_METADATA_EXPRESSION,
|
||||||
link_documents=True
|
link_documents=True
|
||||||
)
|
)
|
||||||
@@ -124,19 +118,11 @@ class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
|||||||
metadata_type=metadata_type, value='0001'
|
metadata_type=metadata_type, value='0001'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create empty index
|
self._create_index()
|
||||||
index = Index.objects.create(label='test')
|
|
||||||
self.assertEqual(list(Index.objects.all()), [index])
|
|
||||||
|
|
||||||
# Add our document type to the new index
|
|
||||||
index.document_types.add(self.document_type)
|
|
||||||
self.assertQuerysetEqual(
|
|
||||||
index.document_types.all(), [repr(self.document_type)]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create simple index template
|
# Create simple index template
|
||||||
root = index.template_root
|
root = self.index.template_root
|
||||||
index.node_templates.create(
|
self.index.node_templates.create(
|
||||||
parent=root, expression='{{ document.metadata_value_of.test }}',
|
parent=root, expression='{{ document.metadata_value_of.test }}',
|
||||||
link_documents=True
|
link_documents=True
|
||||||
)
|
)
|
||||||
@@ -169,20 +155,16 @@ class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
|||||||
file_object=file_object
|
file_object=file_object
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create empty index
|
self._create_index()
|
||||||
index = Index.objects.create(label=TEST_INDEX_LABEL)
|
|
||||||
|
|
||||||
# Add our document type to the new index
|
|
||||||
index.document_types.add(self.document_type)
|
|
||||||
|
|
||||||
# Create simple index template
|
# Create simple index template
|
||||||
root = index.template_root
|
root = self.index.template_root
|
||||||
level_1 = index.node_templates.create(
|
level_1 = self.index.node_templates.create(
|
||||||
parent=root, expression='{{ document.uuid }}',
|
parent=root, expression='{{ document.uuid }}',
|
||||||
link_documents=False
|
link_documents=False
|
||||||
)
|
)
|
||||||
|
|
||||||
index.node_templates.create(
|
self.index.node_templates.create(
|
||||||
parent=level_1, expression='{{ document.label }}',
|
parent=level_1, expression='{{ document.label }}',
|
||||||
link_documents=True
|
link_documents=True
|
||||||
)
|
)
|
||||||
@@ -202,16 +184,15 @@ class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
|||||||
On a two level template if the first level doesn't return a result
|
On a two level template if the first level doesn't return a result
|
||||||
the indexing should stop. GitLab issue #391.
|
the indexing should stop. GitLab issue #391.
|
||||||
"""
|
"""
|
||||||
index = Index.objects.create(label=TEST_INDEX_LABEL)
|
self._create_index()
|
||||||
index.document_types.add(self.document_type)
|
|
||||||
|
|
||||||
level_1 = index.node_templates.create(
|
level_1 = self.index.node_templates.create(
|
||||||
parent=index.template_root,
|
parent=self.index.template_root,
|
||||||
expression='',
|
expression='',
|
||||||
link_documents=True
|
link_documents=True
|
||||||
)
|
)
|
||||||
|
|
||||||
index.node_templates.create(
|
self.index.node_templates.create(
|
||||||
parent=level_1, expression='{{ document.label }}',
|
parent=level_1, expression='{{ document.label }}',
|
||||||
link_documents=True
|
link_documents=True
|
||||||
)
|
)
|
||||||
@@ -219,16 +200,15 @@ class IndexTestCase(DocumentTestMixin, BaseTestCase):
|
|||||||
Index.objects.rebuild()
|
Index.objects.rebuild()
|
||||||
|
|
||||||
def test_date_based_index(self):
|
def test_date_based_index(self):
|
||||||
index = Index.objects.create(label=TEST_INDEX_LABEL)
|
self._create_index()
|
||||||
index.document_types.add(self.document_type)
|
|
||||||
|
|
||||||
level_year = index.node_templates.create(
|
level_year = self.index.node_templates.create(
|
||||||
parent=index.template_root,
|
parent=self.index.template_root,
|
||||||
expression='{{ document.date_added|date:"Y" }}',
|
expression='{{ document.date_added|date:"Y" }}',
|
||||||
link_documents=False
|
link_documents=False
|
||||||
)
|
)
|
||||||
|
|
||||||
index.node_templates.create(
|
self.index.node_templates.create(
|
||||||
parent=level_year,
|
parent=level_year,
|
||||||
expression='{{ document.date_added|date:"m" }}',
|
expression='{{ document.date_added|date:"m" }}',
|
||||||
link_documents=True
|
link_documents=True
|
||||||
|
|||||||
Reference in New Issue
Block a user