Tests: Fix failing tests after last refactor
Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from mayan.apps.common import (
|
||||
MayanAppConfig, menu_facet, menu_main, menu_multi_item, menu_object,
|
||||
menu_sidebar
|
||||
)
|
||||
from mayan.apps.common.classes import ModelAttribute
|
||||
from mayan.apps.documents.search import document_page_search, document_search
|
||||
from mayan.apps.navigation import SourceColumn
|
||||
|
||||
@@ -54,9 +55,11 @@ class CabinetsApp(MayanAppConfig):
|
||||
# Add explicit order_by as DocumentCabinet ordering Meta option has no
|
||||
# effect.
|
||||
Document.add_to_class(
|
||||
name='get_document_cabinets', value=method_get_document_cabinets
|
||||
name='get_cabinets', value=method_get_document_cabinets
|
||||
)
|
||||
|
||||
ModelAttribute(model=Document, name='get_cabinets')
|
||||
|
||||
ModelPermission.register(
|
||||
model=Document, permissions=(
|
||||
permission_cabinet_add_document,
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def method_get_document_cabinets(self):
|
||||
DocumentCabinet = apps.get_models(
|
||||
DocumentCabinet = apps.get_model(
|
||||
app_label='cabinets', model_name='DocumentCabinet'
|
||||
)
|
||||
|
||||
return DocumentCabinet.objects.filter(documents=self).order_by(
|
||||
'parent__label', 'label'
|
||||
)
|
||||
|
||||
|
||||
method_get_document_cabinets.help_text = _(
|
||||
'Return a list of cabinets containing the document'
|
||||
)
|
||||
method_get_document_cabinets.short_description = _('get_cabinets()')
|
||||
|
||||
10
mayan/apps/cabinets/tests/mixins.py
Normal file
10
mayan/apps/cabinets/tests/mixins.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ..models import Cabinet
|
||||
|
||||
from .literals import TEST_CABINET_LABEL
|
||||
|
||||
|
||||
class CabinetTestMixin(object):
|
||||
def _create_cabinet(self):
|
||||
self.cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from mayan.apps.documents.permissions import permission_document_view
|
||||
from mayan.apps.documents.tests import GenericDocumentViewTestCase
|
||||
|
||||
from ..models import Cabinet
|
||||
@@ -10,19 +11,17 @@ from ..permissions import (
|
||||
)
|
||||
|
||||
from .literals import TEST_CABINET_EDITED_LABEL, TEST_CABINET_LABEL
|
||||
from .mixins import CabinetTestMixin
|
||||
|
||||
|
||||
class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
class CabinetViewTestCase(CabinetTestMixin, GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(CabinetViewTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def _create_cabinet(self):
|
||||
self.cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL)
|
||||
|
||||
def _request_create_cabinet(self, label):
|
||||
return self.post(
|
||||
'cabinets:cabinet_create', data={
|
||||
viewname='cabinets:cabinet_create', data={
|
||||
'label': TEST_CABINET_LABEL
|
||||
}
|
||||
)
|
||||
@@ -53,7 +52,9 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(Cabinet.objects.first().pk, self.cabinet.pk)
|
||||
|
||||
def _request_delete_cabinet(self):
|
||||
return self.post('cabinets:cabinet_delete', args=(self.cabinet.pk,))
|
||||
return self.post(
|
||||
viewname='cabinets:cabinet_delete', args=(self.cabinet.pk,)
|
||||
)
|
||||
|
||||
def test_cabinet_delete_view_no_permission(self):
|
||||
self._create_cabinet()
|
||||
@@ -73,7 +74,7 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
def _request_edit_cabinet(self):
|
||||
return self.post(
|
||||
'cabinets:cabinet_edit', args=(self.cabinet.pk,), data={
|
||||
viewname='cabinets:cabinet_edit', args=(self.cabinet.pk,), data={
|
||||
'label': TEST_CABINET_EDITED_LABEL
|
||||
}
|
||||
)
|
||||
@@ -97,11 +98,36 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
self.cabinet.refresh_from_db()
|
||||
self.assertEqual(self.cabinet.label, TEST_CABINET_EDITED_LABEL)
|
||||
|
||||
def _request_cabinet_list(self):
|
||||
return self.get(viewname='cabinets:cabinet_list')
|
||||
|
||||
def test_cabinet_list_view_no_permission(self):
|
||||
self._create_cabinet()
|
||||
response = self._request_cabinet_list()
|
||||
self.assertNotContains(
|
||||
response, text=self.cabinet.label, status_code=200
|
||||
)
|
||||
|
||||
def test_cabinet_list_view_with_access(self):
|
||||
self._create_cabinet()
|
||||
self.grant_access(obj=self.cabinet, permission=permission_cabinet_view)
|
||||
response = self._request_cabinet_list()
|
||||
|
||||
self.assertContains(
|
||||
response, text=self.cabinet.label, status_code=200
|
||||
)
|
||||
|
||||
|
||||
class DocumentViewsTestCase(CabinetTestMixin, GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(DocumentViewsTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def _add_document_to_cabinet(self):
|
||||
return self.post(
|
||||
'cabinets:cabinet_add_document', args=(self.document.pk,), data={
|
||||
'cabinets': self.cabinet.pk
|
||||
}
|
||||
viewname='cabinets:cabinet_add_document', args=(
|
||||
self.document.pk,
|
||||
), data={'cabinets': self.cabinet.pk}
|
||||
)
|
||||
|
||||
def test_cabinet_add_document_view_no_permission(self):
|
||||
@@ -140,7 +166,7 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
def _request_add_multiple_documents_to_cabinet(self):
|
||||
return self.post(
|
||||
'cabinets:cabinet_add_multiple_documents', data={
|
||||
viewname='cabinets:cabinet_add_multiple_documents', data={
|
||||
'id_list': (self.document.pk,), 'cabinets': self.cabinet.pk
|
||||
}
|
||||
)
|
||||
@@ -179,8 +205,8 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
def _request_remove_document_from_cabinet(self):
|
||||
return self.post(
|
||||
'cabinets:document_cabinet_remove', args=(self.document.pk,),
|
||||
data={
|
||||
viewname='cabinets:document_cabinet_remove',
|
||||
args=(self.document.pk,), data={
|
||||
'cabinets': (self.cabinet.pk,),
|
||||
}
|
||||
)
|
||||
@@ -217,21 +243,55 @@ class CabinetViewTestCase(GenericDocumentViewTestCase):
|
||||
self.cabinet.refresh_from_db()
|
||||
self.assertEqual(self.cabinet.documents.count(), 0)
|
||||
|
||||
def _request_cabinet_list(self):
|
||||
return self.get('cabinets:cabinet_list')
|
||||
def _request_document_cabinet_list(self):
|
||||
return self.get(
|
||||
viewname='cabinets:document_cabinet_list', args=(self.document.pk,)
|
||||
)
|
||||
|
||||
def test_cabinet_list_view_no_permission(self):
|
||||
def test_document_cabinet_list_view_no_permission(self):
|
||||
self._create_cabinet()
|
||||
response = self._request_cabinet_list()
|
||||
self.cabinet.documents.add(self.document)
|
||||
response = self._request_document_cabinet_list()
|
||||
self.assertNotContains(
|
||||
response, text=self.cabinet.label, status_code=200
|
||||
response=response, text=self.document.label, status_code=403
|
||||
)
|
||||
self.assertNotContains(
|
||||
response=response, text=self.cabinet.label, status_code=403
|
||||
)
|
||||
|
||||
def test_cabinet_list_view_with_access(self):
|
||||
def test_document_cabinet_list_view_with_cabinet_access(self):
|
||||
self._create_cabinet()
|
||||
self.cabinet.documents.add(self.document)
|
||||
self.grant_access(obj=self.cabinet, permission=permission_cabinet_view)
|
||||
response = self._request_cabinet_list()
|
||||
|
||||
self.assertContains(
|
||||
response, text=self.cabinet.label, status_code=200
|
||||
response = self._request_document_cabinet_list()
|
||||
self.assertNotContains(
|
||||
response=response, text=self.document.label, status_code=403
|
||||
)
|
||||
self.assertNotContains(
|
||||
response=response, text=self.cabinet.label, status_code=403
|
||||
)
|
||||
|
||||
def test_document_cabinet_list_view_with_document_access(self):
|
||||
self._create_cabinet()
|
||||
self.cabinet.documents.add(self.document)
|
||||
self.grant_access(obj=self.document, permission=permission_document_view)
|
||||
response = self._request_document_cabinet_list()
|
||||
self.assertContains(
|
||||
response=response, text=self.document.label, status_code=200
|
||||
)
|
||||
self.assertNotContains(
|
||||
response=response, text=self.cabinet.label, status_code=200
|
||||
)
|
||||
|
||||
def test_document_cabinet_list_view_with_full_access(self):
|
||||
self._create_cabinet()
|
||||
self.cabinet.documents.add(self.document)
|
||||
self.grant_access(obj=self.cabinet, permission=permission_cabinet_view)
|
||||
self.grant_access(obj=self.document, permission=permission_document_view)
|
||||
response = self._request_document_cabinet_list()
|
||||
self.assertContains(
|
||||
response=response, text=self.document.label, status_code=200
|
||||
)
|
||||
self.assertContains(
|
||||
response=response, text=self.cabinet.label, status_code=200
|
||||
)
|
||||
|
||||
@@ -220,7 +220,7 @@ class DocumentCabinetListView(CabinetListView):
|
||||
}
|
||||
|
||||
def get_object_list(self):
|
||||
return self.document.document_cabinets().all()
|
||||
return self.document.get_cabinets().all()
|
||||
|
||||
|
||||
class DocumentAddToCabinetView(MultipleObjectFormActionView):
|
||||
|
||||
@@ -43,7 +43,7 @@ def widget_document_cabinets(document, user):
|
||||
)
|
||||
|
||||
cabinets = AccessControlList.objects.filter_by_access(
|
||||
permission_cabinet_view, user, queryset=document.document_cabinets().all()
|
||||
permission_cabinet_view, user, queryset=document.get_cabinets().all()
|
||||
)
|
||||
|
||||
return format_html_join(
|
||||
|
||||
@@ -26,12 +26,14 @@ class DocumentCheckoutDefailForm(DetailForm):
|
||||
extra_fields = (
|
||||
{
|
||||
'label': _('Document status'),
|
||||
'field': lambda instance: STATE_LABELS[instance.checkout_state()]
|
||||
'field': lambda instance: STATE_LABELS[
|
||||
instance.get_checkout_state()
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
if instance.is_checked_out():
|
||||
checkout_info = instance.checkout_info()
|
||||
checkout_info = instance.get_checkout_info()
|
||||
extra_fields += (
|
||||
{
|
||||
'label': _('User'),
|
||||
|
||||
@@ -34,7 +34,7 @@ class DocumentCheckoutManager(models.Manager):
|
||||
raise DocumentNotCheckedOut
|
||||
else:
|
||||
if user:
|
||||
if self.document_checkout_info(document).user != user:
|
||||
if self.get_document_checkout_info(document).user != user:
|
||||
event_document_forceful_check_in.commit(
|
||||
actor=user, target=document
|
||||
)
|
||||
@@ -46,7 +46,7 @@ class DocumentCheckoutManager(models.Manager):
|
||||
document_checkout.delete()
|
||||
|
||||
def check_in_expired_check_outs(self):
|
||||
for document in self.expired_check_outs():
|
||||
for document in self.get_expired_check_outs():
|
||||
document.check_in()
|
||||
|
||||
def checkout_document(self, document, expiration_datetime, user, block_new_version=True):
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -56,7 +56,10 @@ class DocumentCheckout(models.Model):
|
||||
verbose_name_plural = _('Document checkouts')
|
||||
|
||||
def __str__(self):
|
||||
return force_text(self.document)
|
||||
return '{}: {} - {} by {}'.format(
|
||||
self.document, self.checkout_datetime, self.expiration_datetime,
|
||||
self.user
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
if self.expiration_datetime < now():
|
||||
|
||||
@@ -51,7 +51,6 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase):
|
||||
document=self.document, expiration_datetime=expiration_datetime,
|
||||
user=self.user, block_new_version=True
|
||||
)
|
||||
|
||||
self.assertTrue(self.document.is_checked_out())
|
||||
|
||||
self.grant_access(
|
||||
|
||||
@@ -5,6 +5,7 @@ TEST_INDEX_LABEL_EDITED = 'test edited label'
|
||||
TEST_INDEX_SLUG = 'test_slug'
|
||||
TEST_METADATA_TYPE_LABEL = 'test metadata label'
|
||||
TEST_METADATA_TYPE_NAME = 'test_metadata_name'
|
||||
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION = '{{ document.get_metadata("%s").value }}' % TEST_METADATA_TYPE_NAME
|
||||
TEST_METADATA_VALUE = '0001'
|
||||
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION = '{{{{ document.get_metadata("{}").value }}}}'.format(TEST_METADATA_TYPE_NAME)
|
||||
TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION = '{{ document.label }}'
|
||||
TEST_INDEX_TEMPLATE_DOCUMENT_DESCRIPTION_EXPRESSION = '{{ document.description }}'
|
||||
|
||||
@@ -12,13 +12,13 @@ from mayan.apps.documents.tests.literals import (
|
||||
)
|
||||
from mayan.apps.metadata.models import DocumentTypeMetadataType, MetadataType
|
||||
|
||||
from ..models import Index, IndexInstanceNode, IndexTemplateNode
|
||||
from ..models import Index, IndexInstanceNode
|
||||
|
||||
from .literals import (
|
||||
TEST_INDEX_TEMPLATE_DOCUMENT_DESCRIPTION_EXPRESSION,
|
||||
TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION,
|
||||
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION, TEST_METADATA_TYPE_LABEL,
|
||||
TEST_METADATA_TYPE_NAME
|
||||
TEST_METADATA_TYPE_NAME, TEST_METADATA_VALUE
|
||||
)
|
||||
from .mixins import DocumentIndexingTestMixin
|
||||
|
||||
@@ -248,14 +248,16 @@ class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase):
|
||||
|
||||
def test_rebuild_all_indexes(self):
|
||||
# Add metadata type and connect to document type
|
||||
metadata_type = MetadataType.objects.create(name='test', label='test')
|
||||
metadata_type = MetadataType.objects.create(
|
||||
name=TEST_METADATA_TYPE_NAME, label=TEST_METADATA_TYPE_LABEL
|
||||
)
|
||||
DocumentTypeMetadataType.objects.create(
|
||||
document_type=self.document_type, metadata_type=metadata_type
|
||||
)
|
||||
|
||||
# Add document metadata value
|
||||
self.document.metadata.create(
|
||||
metadata_type=metadata_type, value='0001'
|
||||
metadata_type=metadata_type, value=TEST_METADATA_VALUE
|
||||
)
|
||||
|
||||
self._create_index()
|
||||
@@ -263,14 +265,9 @@ class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase):
|
||||
# Create simple index template
|
||||
root = self.index.template_root
|
||||
self.index.node_templates.create(
|
||||
parent=root, expression='{{ document.metadata_value_of.test }}',
|
||||
parent=root, expression=TEST_INDEX_TEMPLATE_METADATA_EXPRESSION,
|
||||
link_documents=True
|
||||
)
|
||||
self.assertEqual(
|
||||
list(
|
||||
IndexTemplateNode.objects.values_list('expression', flat=True)
|
||||
), ['', '{{ document.metadata_value_of.test }}']
|
||||
)
|
||||
|
||||
# There should be no index instances
|
||||
self.assertEqual(list(IndexInstanceNode.objects.all()), [])
|
||||
@@ -279,7 +276,9 @@ class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase):
|
||||
Index.objects.rebuild()
|
||||
|
||||
# Check that document is in instance node
|
||||
instance_node = IndexInstanceNode.objects.get(value='0001')
|
||||
instance_node = IndexInstanceNode.objects.get(
|
||||
value=TEST_METADATA_VALUE
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
instance_node.documents.all(), [repr(self.document)]
|
||||
)
|
||||
|
||||
@@ -17,8 +17,9 @@ class DocumentAutoParsingTestCase(GenericDocumentTestCase):
|
||||
self._create_document_type()
|
||||
self.document = self.upload_document()
|
||||
|
||||
with self.assertRaises(StopIteration):
|
||||
next(self.document.latest_version.content())
|
||||
self.assertTrue(
|
||||
TEST_DOCUMENT_CONTENT not in self.document.get_content()
|
||||
)
|
||||
|
||||
@override_settings(DOCUMENT_PARSING_AUTO_PARSING=True)
|
||||
def test_enabled_auto_parsing(self):
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
TEST_INDEX_LABEL = 'test workflow index'
|
||||
|
||||
TEST_WORKFLOW_LABEL = 'test workflow label'
|
||||
TEST_WORKFLOW_INTERNAL_NAME = 'test_workflow_label'
|
||||
TEST_WORKFLOW_INTERNAL_NAME = 'test_workflow_name'
|
||||
TEST_WORKFLOW_LABEL_EDITED = 'test workflow label edited'
|
||||
TEST_WORKFLOW_INITIAL_STATE_LABEL = 'test initial state'
|
||||
TEST_WORKFLOW_INITIAL_STATE_COMPLETION = 33
|
||||
@@ -15,6 +15,6 @@ TEST_WORKFLOW_TRANSITION_LABEL = 'test transition label'
|
||||
TEST_WORKFLOW_TRANSITION_LABEL_2 = 'test transition label 2'
|
||||
TEST_WORKFLOW_TRANSITION_LABEL_EDITED = 'test transition label edited'
|
||||
|
||||
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION = '{{{{ document.get_workflow.("{}").get_current_state() }}}}'.format(
|
||||
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION = '{{{{ document.get_workflow("{}").get_current_state() }}}}'.format(
|
||||
TEST_WORKFLOW_INTERNAL_NAME
|
||||
)
|
||||
|
||||
@@ -86,16 +86,14 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
document_type=document_type_2
|
||||
)
|
||||
|
||||
self.assertContains(
|
||||
response=response, text='Select a valid choice', status_code=200
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertEqual(
|
||||
Document.objects.get(pk=self.document.pk).document_type,
|
||||
self.document_type
|
||||
)
|
||||
|
||||
def test_document_document_type_change_view_with_permissions(self):
|
||||
def test_document_document_type_change_view_with_access(self):
|
||||
self.assertEqual(
|
||||
self.document.document_type, self.document_type
|
||||
)
|
||||
@@ -144,15 +142,13 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
document_type=document_type_2
|
||||
)
|
||||
|
||||
self.assertContains(
|
||||
response=response, text='Select a valid choice.', status_code=200
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertEqual(
|
||||
Document.objects.first().document_type, self.document_type
|
||||
)
|
||||
|
||||
def test_document_multiple_document_type_change_view_with_permission(self):
|
||||
def test_document_multiple_document_type_change_view_with_access(self):
|
||||
self.assertEqual(
|
||||
Document.objects.first().document_type, self.document_type
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ def method_get_document_file_metadata(self, dotted_name):
|
||||
)
|
||||
|
||||
|
||||
method_get_document_file_metadata.short_description=_(
|
||||
method_get_document_file_metadata.short_description = _(
|
||||
'get_file_metadata(< file metadata dotted path >)'
|
||||
)
|
||||
method_get_document_file_metadata.help_text = _(
|
||||
|
||||
@@ -19,5 +19,9 @@ TEST_METADATA_VALUE = 'test value'
|
||||
TEST_METADATA_VALUE_EDITED = 'test value edited'
|
||||
TEST_METADATA_VALUE_UNICODE = 'español'
|
||||
TEST_METADATA_VALUE_WITH_AMPERSAND = 'first value & second value'
|
||||
TEST_NON_ASCII_LOOKUP = '测试1,测试2,test1,test2'
|
||||
TEST_NON_ASCII_LOOKUP_VALUE = '测试1'
|
||||
TEST_NON_UNICODE_LOOKUP_TEMPLATE = b'test1,test2,test3'
|
||||
TEST_NON_UNICODE_LOOKUP_VALUE = b'test1'
|
||||
TEST_PARSED_VALID_DATE = '2001-01-01'
|
||||
TEST_VALID_DATE = '2001-1-1'
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from mayan.apps.common.tests import BaseTestCase
|
||||
from mayan.apps.documents.models import DocumentType
|
||||
from mayan.apps.documents.tests import DocumentTestMixin, TEST_DOCUMENT_TYPE_2_LABEL
|
||||
from mayan.apps.documents.tests import (
|
||||
DocumentTestMixin, TEST_DOCUMENT_TYPE_2_LABEL
|
||||
)
|
||||
|
||||
from ..models import DocumentMetadata
|
||||
|
||||
from .literals import (
|
||||
TEST_DEFAULT_VALUE, TEST_LOOKUP_TEMPLATE, TEST_INCORRECT_LOOKUP_VALUE,
|
||||
TEST_CORRECT_LOOKUP_VALUE, TEST_DATE_VALIDATOR, TEST_DATE_PARSER,
|
||||
TEST_INVALID_DATE, TEST_VALID_DATE, TEST_PARSED_VALID_DATE
|
||||
TEST_INVALID_DATE, TEST_METADATA_TYPE_NAME, TEST_NON_ASCII_LOOKUP,
|
||||
TEST_NON_ASCII_LOOKUP_VALUE, TEST_NON_UNICODE_LOOKUP_TEMPLATE,
|
||||
TEST_NON_UNICODE_LOOKUP_VALUE, TEST_VALID_DATE, TEST_PARSED_VALID_DATE
|
||||
)
|
||||
from .mixins import MetadataTypeTestMixin
|
||||
|
||||
@@ -30,7 +33,9 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
document_metadata.full_clean()
|
||||
document_metadata.save()
|
||||
|
||||
self.assertEqual(self.document.metadata_value_of.test, None)
|
||||
self.assertEqual(
|
||||
self.document.get_metadata(TEST_METADATA_TYPE_NAME).value, None
|
||||
)
|
||||
|
||||
def test_default(self):
|
||||
self.metadata_type.default = TEST_DEFAULT_VALUE
|
||||
@@ -44,7 +49,8 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
document_metadata.save()
|
||||
|
||||
self.assertEqual(
|
||||
self.document.metadata_value_of.test, TEST_DEFAULT_VALUE
|
||||
self.document.get_metadata(TEST_METADATA_TYPE_NAME).value,
|
||||
TEST_DEFAULT_VALUE
|
||||
)
|
||||
|
||||
def test_lookup_with_incorrect_value(self):
|
||||
@@ -74,7 +80,8 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
document_metadata.save()
|
||||
|
||||
self.assertEqual(
|
||||
self.document.metadata_value_of.test, TEST_CORRECT_LOOKUP_VALUE
|
||||
self.document.get_metadata(TEST_METADATA_TYPE_NAME).value,
|
||||
TEST_CORRECT_LOOKUP_VALUE
|
||||
)
|
||||
|
||||
def test_empty_optional_lookup(self):
|
||||
@@ -110,7 +117,10 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
document_metadata.full_clean()
|
||||
document_metadata.save()
|
||||
|
||||
self.assertEqual(self.document.metadata_value_of.test, TEST_VALID_DATE)
|
||||
self.assertEqual(
|
||||
self.document.get_metadata(TEST_METADATA_TYPE_NAME).value,
|
||||
TEST_VALID_DATE
|
||||
)
|
||||
|
||||
def test_parsing(self):
|
||||
self.metadata_type.parser = TEST_DATE_PARSER
|
||||
@@ -131,7 +141,8 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
document_metadata.save()
|
||||
|
||||
self.assertEqual(
|
||||
self.document.metadata_value_of.test, TEST_PARSED_VALID_DATE
|
||||
self.document.get_metadata(TEST_METADATA_TYPE_NAME).value,
|
||||
TEST_PARSED_VALID_DATE
|
||||
)
|
||||
|
||||
def test_required_metadata(self):
|
||||
@@ -161,15 +172,19 @@ class MetadataTestCase(DocumentTestMixin, MetadataTypeTestMixin, BaseTestCase):
|
||||
|
||||
def test_unicode_lookup(self):
|
||||
# Should NOT return a ValidationError, otherwise test fails
|
||||
self.metadata_type.lookup = '测试1,测试2,test1,test2'
|
||||
self.metadata_type.lookup = TEST_NON_ASCII_LOOKUP
|
||||
self.metadata_type.save()
|
||||
self.metadata_type.validate_value(document_type=None, value='测试1')
|
||||
self.metadata_type.validate_value(
|
||||
document_type=None, value=TEST_NON_ASCII_LOOKUP_VALUE
|
||||
)
|
||||
|
||||
def test_non_unicode_lookup(self):
|
||||
# Should NOT return a ValidationError, otherwise test fails
|
||||
self.metadata_type.lookup = 'test1,test2'
|
||||
self.metadata_type.lookup = TEST_NON_UNICODE_LOOKUP_TEMPLATE
|
||||
self.metadata_type.save()
|
||||
self.metadata_type.validate_value(document_type=None, value='test1')
|
||||
self.metadata_type.validate_value(
|
||||
document_type=None, value=TEST_NON_UNICODE_LOOKUP_VALUE
|
||||
)
|
||||
|
||||
def test_add_new_metadata_type_on_document_type_change(self):
|
||||
"""
|
||||
|
||||
@@ -34,7 +34,7 @@ def method_get_document_ocr_content(self):
|
||||
latest_version = self.latest_version
|
||||
# Don't error out if document has no version
|
||||
if latest_version:
|
||||
latest_version.get_ocr_content()
|
||||
return latest_version.get_ocr_content()
|
||||
|
||||
|
||||
method_get_document_ocr_content.short_description = _(
|
||||
|
||||
@@ -74,7 +74,7 @@ class OCRViewsTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
def test_document_submit_view_no_permission(self):
|
||||
self._request_document_submit_view()
|
||||
self.assertEqual(self.document.ocr_content, '')
|
||||
self.assertEqual(self.document.get_ocr_content(), '')
|
||||
|
||||
def test_document_submit_view_with_access(self):
|
||||
self.grant_access(
|
||||
|
||||
@@ -38,7 +38,7 @@ def widget_document_tags(document, user):
|
||||
result = ['<div class="tag-container">']
|
||||
|
||||
tags = AccessControlList.objects.filter_by_access(
|
||||
permission_tag_view, user, queryset=document.attached_tags().all()
|
||||
permission_tag_view, user, queryset=document.get_tags().all()
|
||||
)
|
||||
|
||||
for tag in tags:
|
||||
|
||||
Reference in New Issue
Block a user