dms/dms/tests.py

66 lines
2.5 KiB
Python

from django.test import TestCase
from process.exceptions import ActorException
from django.contrib.auth.models import User, Group
from model_mommy import mommy
class TestDocument(TestCase):
def setUp(self):
self.document = mommy.make('evolus.Document')
self.validator = mommy.make(User)
self.group = mommy.make(Group)
def test_create_document_version(self):
"""Check that the **first** version of a document is numbered v0.1 (Draft)"""
version = self.document.create_new_version()
self.assertEquals('v0.1 (Draft)', str(version))
def test_document_major_version(self):
"""Check that the major number of a document is 0.
This occurs in two places:
1. Right after the document has been created
2. Right after a new version of this document is created.
"""
self.assertEquals(0, self.document.major)
self.document.create_new_version()
self.assertEquals(0, self.document.major)
def test_publish_document_without_validators_raises_exception(self):
"""Asserts that a document cannot be published if not validators has been set."""
v1 = self.document.create_new_version()
with self.assertRaises(ActorException):
v1.publish()
def test_document_cannot_have_two_working_drafts(self):
self.document.create_new_version()
with self.assertRaises(IndexError):
self.document.create_new_version()
def test_document_major_version_1_0(self):
"""Checks the version associated to a document is set to 1.0 (Published) when it has been validated."""
v1 = self.document.create_new_version()
v1.validators.add(self.validator)
v1.save()
process = v1.publish()
process.finalize()
self.assertEqual('v1.0 (Published)', str(v1))
def test_document_version_update(self):
"""Checks the minor version bump when a document is updated.
The test creates the document then updates it 2 times. We must have v0.1, v0.2, v0.3.
Then, we publish it; the version should bump to v1.0.
"""
v1 = self.document.create_new_version()
self.assertEquals(1, v1.revision)
v1.update()
self.assertEquals(2, v1.revision)
v1.update()
self.assertEquals(3, v1.revision)
v1.validators.add(self.validator)
approval_process = v1.publish()
approval_process.finalize()
self.assertEquals(0, v1.revision)