Documents now have their own dedicated DocumentPage submodel. The old DocumentPage is now called DocumentVersionPage. This allows mappings between document pages and document version pages, allowing renumbering, appending pages. DocumentPages have a content_object to map them to any other object. For now they only map to DocumentVersionPages. New option added to the version upload form to append the pages of the new version. A new view was added to just append new pages with wraps the new document version upload form and hides the append pages checkbox set to True. Add a new action, reset_pages to reset the pages of the document to those of the latest version. Missing: appending tests, checks for proper content_object in OCR and document parsing. Author: Roberto Rosario <roberto.rosario@mayan-edms.com> Date: Thu Oct 11 12:00:25 2019 -0400
97 lines
3.4 KiB
Python
97 lines
3.4 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from rest_framework import status
|
|
|
|
from mayan.apps.documents.tests.mixins import DocumentTestMixin
|
|
from mayan.apps.rest_api.tests.base import BaseAPITestCase
|
|
|
|
from ..permissions import (
|
|
permission_ocr_document, permission_ocr_content_view,
|
|
)
|
|
|
|
from .literals import TEST_DOCUMENT_CONTENT
|
|
|
|
|
|
class OCRAPIViewTestMixin(object):
|
|
def _request_document_ocr_submit_view(self):
|
|
return self.post(
|
|
viewname='rest_api:document-ocr-submit-view',
|
|
kwargs={'pk': self.test_document.pk}
|
|
)
|
|
|
|
def _request_document_version_ocr_submit_view(self):
|
|
return self.post(
|
|
viewname='rest_api:document-version-ocr-submit-view', kwargs={
|
|
'document_pk': self.test_document.pk,
|
|
'version_pk': self.test_document.latest_version.pk
|
|
}
|
|
)
|
|
|
|
def _request_document_version_page_content_view(self):
|
|
return self.get(
|
|
viewname='rest_api:document-page-ocr-content-view', kwargs={
|
|
'document_pk': self.test_document.pk,
|
|
'version_pk': self.test_document.latest_version.pk,
|
|
'page_pk': self.test_document.latest_version.pages.first().pk,
|
|
}
|
|
)
|
|
|
|
|
|
class OCRAPIViewTestCase(
|
|
OCRAPIViewTestMixin, DocumentTestMixin, BaseAPITestCase
|
|
):
|
|
def test_submit_document_no_access(self):
|
|
response = self._request_document_ocr_submit_view()
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertFalse(
|
|
hasattr(self.test_document.pages.first(), 'ocr_content')
|
|
)
|
|
|
|
def test_submit_document_with_access(self):
|
|
self.grant_access(
|
|
obj=self.test_document, permission=permission_ocr_document
|
|
)
|
|
response = self._request_document_ocr_submit_view()
|
|
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
|
|
|
self.assertTrue(
|
|
hasattr(
|
|
self.test_document.pages.first().content_object, 'ocr_content'
|
|
)
|
|
)
|
|
|
|
def test_submit_document_version_no_access(self):
|
|
response = self._request_document_version_ocr_submit_view()
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
self.assertFalse(
|
|
hasattr(self.test_document.pages.first(), 'ocr_content')
|
|
)
|
|
|
|
def test_submit_document_version_with_access(self):
|
|
self.grant_access(
|
|
permission=permission_ocr_document, obj=self.test_document
|
|
)
|
|
response = self._request_document_version_ocr_submit_view()
|
|
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
|
|
|
self.assertTrue(
|
|
hasattr(self.test_document_version.pages.first(), 'ocr_content')
|
|
)
|
|
|
|
def test_get_document_version_page_content_no_access(self):
|
|
response = self._request_document_version_page_content_view()
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
|
|
|
def test_get_document_version_page_content_with_access(self):
|
|
self.test_document.submit_for_ocr()
|
|
self.grant_access(
|
|
permission=permission_ocr_content_view, obj=self.test_document
|
|
)
|
|
response = self._request_document_version_page_content_view()
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
self.assertTrue(
|
|
TEST_DOCUMENT_CONTENT in response.data['content']
|
|
)
|