Complete multiple check in/out support
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import datetime
|
||||
from django.utils.timezone import now
|
||||
|
||||
from mayan.apps.common.literals import TIME_DELTA_UNIT_DAYS
|
||||
from mayan.apps.common.tests.utils import as_id_list
|
||||
|
||||
from ..models import DocumentCheckout
|
||||
|
||||
@@ -12,7 +13,10 @@ from ..models import DocumentCheckout
|
||||
class DocumentCheckoutTestMixin(object):
|
||||
_test_document_check_out_seconds = 0.1
|
||||
|
||||
def _check_out_test_document(self, user=None):
|
||||
def _check_out_test_document(self, document=None, user=None):
|
||||
if not document:
|
||||
document = self.test_document
|
||||
|
||||
if not user:
|
||||
user = self._test_case_user
|
||||
|
||||
@@ -21,7 +25,7 @@ class DocumentCheckoutTestMixin(object):
|
||||
)
|
||||
|
||||
self.test_check_out = DocumentCheckout.objects.check_out_document(
|
||||
block_new_version=True, document=self.test_document,
|
||||
block_new_version=True, document=document,
|
||||
expiration_datetime=self._check_out_expiration_datetime,
|
||||
user=user
|
||||
)
|
||||
@@ -42,6 +46,13 @@ class DocumentCheckoutViewTestMixin(object):
|
||||
}
|
||||
)
|
||||
|
||||
def _request_test_document_multiple_check_in_post_view(self):
|
||||
return self.post(
|
||||
viewname='checkouts:check_in_document_multiple', data={
|
||||
'id_list': as_id_list(items=self.test_documents)
|
||||
}
|
||||
)
|
||||
|
||||
def _request_test_document_check_out_view(self):
|
||||
return self.post(
|
||||
viewname='checkouts:check_out_document', kwargs={
|
||||
@@ -53,6 +64,16 @@ class DocumentCheckoutViewTestMixin(object):
|
||||
}
|
||||
)
|
||||
|
||||
def _request_test_document_multiple_check_out_post_view(self):
|
||||
return self.post(
|
||||
viewname='checkouts:check_out_document_multiple', data={
|
||||
'block_new_version': True,
|
||||
'expiration_datetime_0': TIME_DELTA_UNIT_DAYS,
|
||||
'expiration_datetime_1': 2,
|
||||
'id_list': as_id_list(items=self.test_documents)
|
||||
}
|
||||
)
|
||||
|
||||
def _request_test_document_check_out_detail_view(self):
|
||||
return self.get(
|
||||
viewname='checkouts:check_out_info', kwargs={
|
||||
|
||||
@@ -7,8 +7,7 @@ from mayan.apps.documents.tests import GenericDocumentTestCase, DocumentTestMixi
|
||||
from mayan.apps.documents.tests.literals import TEST_SMALL_DOCUMENT_PATH
|
||||
|
||||
from ..exceptions import (
|
||||
DocumentAlreadyCheckedOut, DocumentNotCheckedOut,
|
||||
NewDocumentVersionNotAllowed
|
||||
DocumentAlreadyCheckedOut, NewDocumentVersionNotAllowed
|
||||
)
|
||||
from ..models import DocumentCheckout, NewVersionBlock
|
||||
|
||||
@@ -49,10 +48,6 @@ class DocumentCheckoutTestCase(DocumentCheckoutTestMixin, GenericDocumentTestCas
|
||||
block_new_version=True
|
||||
)
|
||||
|
||||
def test_checkin_without_checkout(self):
|
||||
with self.assertRaises(DocumentNotCheckedOut):
|
||||
self.test_document.check_in()
|
||||
|
||||
def test_auto_check_in(self):
|
||||
self._check_out_test_document()
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from mayan.apps.common.literals import TIME_DELTA_UNIT_DAYS
|
||||
from mayan.apps.documents.permissions import permission_document_view
|
||||
from mayan.apps.documents.tests import GenericDocumentViewTestCase
|
||||
from mayan.apps.sources.links import link_document_version_upload
|
||||
@@ -23,8 +22,8 @@ class DocumentCheckoutViewTestCase(
|
||||
self._check_out_test_document()
|
||||
|
||||
response = self._request_test_document_check_in_get_view()
|
||||
self.assertContains(
|
||||
response=response, text=self.test_document.label, status_code=200
|
||||
self.assertNotContains(
|
||||
response=response, text=self.test_document.label, status_code=404
|
||||
)
|
||||
|
||||
self.assertTrue(self.test_document.is_checked_out())
|
||||
@@ -68,6 +67,86 @@ class DocumentCheckoutViewTestCase(
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_multiple_check_in_post_view_no_permission(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self._check_out_test_document(document=self.test_documents[0])
|
||||
self._check_out_test_document(document=self.test_documents[1])
|
||||
|
||||
response = self._request_test_document_multiple_check_in_post_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
self.assertTrue(self.test_documents[0].is_checked_out())
|
||||
self.assertTrue(self.test_documents[1].is_checked_out())
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_multiple_check_in_post_view_with_document_0_access(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self._check_out_test_document(document=self.test_documents[0])
|
||||
self._check_out_test_document(document=self.test_documents[1])
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0], permission=permission_document_check_in
|
||||
)
|
||||
|
||||
response = self._request_test_document_multiple_check_in_post_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertFalse(self.test_documents[0].is_checked_out())
|
||||
self.assertTrue(self.test_documents[1].is_checked_out())
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_multiple_check_in_post_view_with_access(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self._check_out_test_document(document=self.test_documents[0])
|
||||
self._check_out_test_document(document=self.test_documents[1])
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0], permission=permission_document_check_in
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[1], permission=permission_document_check_in
|
||||
)
|
||||
|
||||
response = self._request_test_document_multiple_check_in_post_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertFalse(self.test_documents[0].is_checked_out())
|
||||
self.assertFalse(self.test_documents[1].is_checked_out())
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_check_out_view_no_permission(self):
|
||||
response = self._request_test_document_check_out_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
@@ -88,6 +167,102 @@ class DocumentCheckoutViewTestCase(
|
||||
|
||||
self.assertTrue(self.test_document.is_checked_out())
|
||||
|
||||
def test_document_multiple_check_out_post_view_no_permission(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[1],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
|
||||
response = self._request_test_document_multiple_check_out_post_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
self.assertFalse(self.test_documents[0].is_checked_out())
|
||||
self.assertFalse(self.test_documents[1].is_checked_out())
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_multiple_check_out_post_view_with_document_0_access(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0], permission=permission_document_check_out
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[1],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
|
||||
response = self._request_test_document_multiple_check_out_post_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertTrue(self.test_documents[0].is_checked_out())
|
||||
self.assertFalse(self.test_documents[1].is_checked_out())
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_multiple_check_out_post_view_with_access(self):
|
||||
# Upload second document
|
||||
self.upload_document()
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0], permission=permission_document_check_out
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[1], permission=permission_document_check_out
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[0],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_documents[1],
|
||||
permission=permission_document_check_out_detail_view
|
||||
)
|
||||
|
||||
response = self._request_test_document_multiple_check_out_post_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertTrue(self.test_documents[0].is_checked_out())
|
||||
self.assertTrue(self.test_documents[1].is_checked_out())
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[0]
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
DocumentCheckout.objects.is_checked_out(
|
||||
document=self.test_documents[1]
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_check_out_detail_view_no_permission(self):
|
||||
self._check_out_test_document()
|
||||
|
||||
@@ -177,45 +352,39 @@ class DocumentCheckoutViewTestCase(
|
||||
|
||||
self.assertEqual(resolved_link, None)
|
||||
|
||||
def test_document_forcefull_check_in_view_no_permission(self):
|
||||
def test_document_check_in_forcefull_view_no_permission(self):
|
||||
# Gitlab issue #237
|
||||
# Forcefully checking in a document by a user without adequate
|
||||
# permissions throws out an error
|
||||
|
||||
self._create_test_case_superuser()
|
||||
self._check_out_test_document(user=self._test_case_superuser)
|
||||
self._create_test_user()
|
||||
self._check_out_test_document(user=self.test_user)
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_check_in
|
||||
)
|
||||
|
||||
response = self.post(
|
||||
viewname='checkouts:check_in_document', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
self.assertContains(
|
||||
response=response, text='Insufficient permissions', status_code=403
|
||||
)
|
||||
|
||||
self.assertTrue(self.test_document.is_checked_out())
|
||||
|
||||
def test_document_forcefull_check_in_view_with_permission(self):
|
||||
self._create_test_case_superuser()
|
||||
self._check_out_test_document(user=self._test_case_superuser)
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_check_in
|
||||
)
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_check_in_override
|
||||
)
|
||||
|
||||
response = self.post(
|
||||
viewname='checkouts:check_in_document', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(self.test_document.is_checked_out())
|
||||
|
||||
def test_document_check_in_forcefull_view_with_access(self):
|
||||
self._create_test_user()
|
||||
self._check_out_test_document(user=self.test_user)
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_check_in_override
|
||||
)
|
||||
|
||||
response = self.post(
|
||||
viewname='checkouts:check_in_document', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertFalse(self.test_document.is_checked_out())
|
||||
|
||||
Reference in New Issue
Block a user