Move new version creation blocking from the documents app to the checkouts app.

Closes GitLab #294.
This commit is contained in:
Roberto Rosario
2016-12-22 01:45:43 -04:00
parent 71af09c1fc
commit 1e194e04fa
16 changed files with 181 additions and 99 deletions

View File

@@ -7,7 +7,7 @@ from django.contrib.auth import get_user_model
from django.test import TestCase, override_settings
from django.utils.timezone import now
from documents.exceptions import NewDocumentVersionNotAllowed
from common.tests import BaseTestCase
from documents.models import DocumentType
from documents.tests.literals import (
TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
@@ -16,8 +16,11 @@ from user_management.tests.literals import (
TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD
)
from ..exceptions import DocumentAlreadyCheckedOut, DocumentNotCheckedOut
from ..models import DocumentCheckout
from ..exceptions import (
DocumentAlreadyCheckedOut, DocumentNotCheckedOut,
NewDocumentVersionNotAllowed
)
from ..models import DocumentCheckout, NewVersionBlock
@override_settings(OCR_AUTO_OCR=False)
@@ -116,3 +119,58 @@ class DocumentCheckoutTestCase(TestCase):
DocumentCheckout.objects.check_in_expired_check_outs()
self.assertFalse(self.document.is_checked_out())
def test_blocking_new_versions(self):
NewVersionBlock.objects.block(document=self.document)
with self.assertRaises(NewDocumentVersionNotAllowed):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=file_object)
@override_settings(OCR_AUTO_OCR=False)
class NewVersionBlockTestCase(BaseTestCase):
def setUp(self):
super(NewVersionBlockTestCase, self).setUp()
self.document_type = DocumentType.objects.create(
label=TEST_DOCUMENT_TYPE
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=file_object
)
def tearDown(self):
self.document.delete()
self.document_type.delete()
super(NewVersionBlockTestCase, self).tearDown()
def test_blocking(self):
NewVersionBlock.objects.block(document=self.document)
self.assertEqual(NewVersionBlock.objects.count(), 1)
self.assertEqual(
NewVersionBlock.objects.first().document, self.document
)
def test_unblocking(self):
NewVersionBlock.objects.create(document=self.document)
NewVersionBlock.objects.unblock(document=self.document)
self.assertEqual(NewVersionBlock.objects.count(), 0)
def test_is_blocked(self):
NewVersionBlock.objects.create(document=self.document)
self.assertTrue(
NewVersionBlock.objects.is_blocked(document=self.document)
)
NewVersionBlock.objects.all().delete()
self.assertFalse(
NewVersionBlock.objects.is_blocked(document=self.document)
)