Rename the DeletedDocument proxy model to a TrashedDocument. Rename the deleted_document views to trashed_document. Rename the document and deleted_document URL parameters to trashed_document. Update URL parameters to the '_id' form. Add keyword arguments. Update use of .filter_by_access(). Enclose trashed document restore method in a transaction. Sort arguments. Update app for compliance with MERCs 5 and 6. Add document page view tests. Add favorite document view tests. Movernize tests. Replace use of urlencode with furl. Update views to use ExternalObjectMixin. Refactor the document and version download views. Rename the DocumentDocumentTypeEditView to DocumentChangeTypeView. Move the trashed document views to their own module. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
131 lines
4.4 KiB
Python
131 lines
4.4 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.utils.encoding import force_text
|
|
|
|
from ..permissions import permission_document_view
|
|
|
|
from .base import GenericDocumentViewTestCase
|
|
from .literals import TEST_MULTI_PAGE_TIFF
|
|
|
|
|
|
class DocumentPageViewTestCase(GenericDocumentViewTestCase):
|
|
def _document_page_list_view(self):
|
|
return self.get(
|
|
viewname='documents:document_pages',
|
|
kwargs={'document_id': self.document.pk}
|
|
)
|
|
|
|
def test_document_page_list_view_no_permission(self):
|
|
response = self._document_page_list_view()
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
def test_document_page_list_view_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._document_page_list_view()
|
|
self.assertContains(
|
|
response=response, text=self.document.label, status_code=200
|
|
)
|
|
|
|
def _request_document_page_view(self, document_page):
|
|
return self.get(
|
|
viewname='documents:document_page_view', kwargs={
|
|
'document_page_id': document_page.pk
|
|
}
|
|
)
|
|
|
|
def test_document_page_view_no_permissions(self):
|
|
response = self._request_document_page_view(
|
|
document_page=self.document.pages.first()
|
|
)
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
def test_document_page_view_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._request_document_page_view(
|
|
document_page=self.document.pages.first()
|
|
)
|
|
self.assertContains(
|
|
response=response, text=force_text(self.document.pages.first()),
|
|
status_code=200
|
|
)
|
|
|
|
|
|
class DocumentPageNavigationViewTestCase(GenericDocumentViewTestCase):
|
|
test_document_filename = TEST_MULTI_PAGE_TIFF
|
|
|
|
def _request_document_page_navigation_next_view(self):
|
|
return self.get(
|
|
viewname='documents:document_page_navigation_next',
|
|
kwargs={'document_page_id': self.document.pages.first().pk},
|
|
follow=True
|
|
)
|
|
|
|
def test_document_page_navigation_next_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._request_document_page_navigation_next_view()
|
|
|
|
self.assertContains(
|
|
response=response, status_code=200,
|
|
text=force_text(self.document.pages.last())
|
|
)
|
|
|
|
def _request_document_page_navigation_last_view(self):
|
|
return self.get(
|
|
viewname='documents:document_page_navigation_last',
|
|
kwargs={'document_page_id': self.document.pages.first().pk},
|
|
follow=True
|
|
)
|
|
|
|
def test_document_page_navigation_last_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._request_document_page_navigation_last_view()
|
|
|
|
self.assertContains(
|
|
response=response, status_code=200,
|
|
text=force_text(self.document.pages.last())
|
|
)
|
|
|
|
def _request_document_page_navigation_previous_view(self):
|
|
return self.get(
|
|
viewname='documents:document_page_navigation_previous',
|
|
kwargs={'document_page_id': self.document.pages.last().pk},
|
|
follow=True
|
|
)
|
|
|
|
def test_document_page_navigation_previous_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._request_document_page_navigation_previous_view()
|
|
|
|
self.assertContains(
|
|
response=response, status_code=200,
|
|
text=force_text(self.document.pages.first())
|
|
)
|
|
|
|
def _request_document_page_navigation_first_view(self):
|
|
return self.get(
|
|
viewname='documents:document_page_navigation_first',
|
|
kwargs={'document_page_id': self.document.pages.last().pk},
|
|
follow=True
|
|
)
|
|
|
|
def test_document_page_navigation_first_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_document_view
|
|
)
|
|
response = self._request_document_page_navigation_first_view()
|
|
|
|
self.assertContains(
|
|
response=response, status_code=200,
|
|
text=force_text(self.document.pages.first())
|
|
)
|