tests documents updates, creations and publications
This commit is contained in:
parent
51994b4600
commit
c77d5eaa88
|
@ -3,13 +3,13 @@ This module defines the structure and properties of documents.
|
|||
"""
|
||||
|
||||
from django.db import models
|
||||
from closuretree.models import ClosureModel
|
||||
from simple_history.models import HistoricalRecords
|
||||
from django.contrib.auth.models import Group, User
|
||||
|
||||
from closuretree.models import ClosureModel
|
||||
import reversion
|
||||
|
||||
from process.models import Approval
|
||||
from jci.models import Standard
|
||||
from process.exceptions import ActorException
|
||||
|
||||
|
||||
class Audience(ClosureModel):
|
||||
|
@ -121,7 +121,7 @@ class Document(models.Model):
|
|||
|
||||
@property
|
||||
def major(self):
|
||||
latest_version = self.versions.filter(published=True).last()
|
||||
latest_version = self.versions.filter(is_published=True).last()
|
||||
if latest_version:
|
||||
return latest_version.major
|
||||
return 0
|
||||
|
@ -159,10 +159,10 @@ class Version(models.Model):
|
|||
def publish(self):
|
||||
if not self.is_published:
|
||||
if self.validators.count() == 0:
|
||||
raise ValueError('There are no validators for this version. \n'
|
||||
'Please, add at least one of them.')
|
||||
raise ActorException('There are no validators for this version. \n'
|
||||
'Please, add at least one of them.')
|
||||
|
||||
Approval.objects.get_or_create(
|
||||
return Approval.objects.create(
|
||||
document_version=self
|
||||
)
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from process.exceptions import ActorException
|
||||
from django.contrib.auth.models import User, Group
|
||||
from model_mommy import mommy
|
||||
|
||||
|
@ -6,31 +8,58 @@ 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)
|
||||
v1 = self.document.create_new_version()
|
||||
self.document.create_new_version()
|
||||
self.assertEquals(0, self.document.major)
|
||||
|
||||
|
||||
def test_document_major_version_0(self):
|
||||
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()
|
||||
v1.publish()
|
||||
self.assertEquals(1, self.document.major)
|
||||
self.assertEquals(0, v1.revision)
|
||||
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()
|
||||
print(v1)
|
||||
self.assertEquals(1, v1.revision)
|
||||
v1.update()
|
||||
self.assertEquals(2, v1.revision)
|
||||
v1.update()
|
||||
self.assertEquals(3, v1.revision)
|
||||
v1.publish()
|
||||
v1.validators.add(self.validator)
|
||||
approval_process = v1.publish()
|
||||
approval_process.finalize()
|
||||
self.assertEquals(0, v1.revision)
|
|
@ -0,0 +1,5 @@
|
|||
"""Defines all exceptions that can occur within the treatment of a process."""
|
||||
|
||||
|
||||
class ActorException(Exception):
|
||||
pass
|
Loading…
Reference in New Issue