Files
mayan-edms/mayan/apps/document_states/tests/test_views.py
Roberto Rosario 572d7b68d7 Backport fix from development branch.
Fix worklow state and transition deletion views. GH issue #237.

Conflicts:
	mayan/apps/document_states/apps.py
	mayan/apps/document_states/views.py
2015-10-14 14:53:44 -04:00

195 lines
6.7 KiB
Python

from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.core.files import File
from django.core.urlresolvers import reverse
from django.test.client import Client
from django.test import TestCase
from django.utils.timezone import now
from common.literals import TIME_DELTA_UNIT_DAYS
from documents.models import DocumentType
from documents.tests.literals import (
TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL,
TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH
)
from ..models import Workflow, WorkflowState, WorkflowTransition
from .literals import (
TEST_WORKFLOW_LABEL, TEST_WORKFLOW_INITIAL_STATE_LABEL,
TEST_WORKFLOW_INITIAL_STATE_COMPLETION, TEST_WORKFLOW_STATE_LABEL,
TEST_WORKFLOW_STATE_COMPLETION, TEST_WORKFLOW_TRANSITION_LABEL
)
class DocumentStateViewTestCase(TestCase):
def setUp(self):
self.admin_user = User.objects.create_superuser(
username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL,
password=TEST_ADMIN_PASSWORD
)
self.client = Client()
# Login the admin user
logged_in = self.client.login(
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
)
self.assertTrue(logged_in)
self.assertTrue(self.admin_user.is_authenticated())
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(file_object)
)
def tearDown(self):
self.document_type.delete()
self.admin_user.delete()
Workflow.objects.all().delete()
def test_creating_workflow(self):
response = self.client.post(
reverse(
'document_states:setup_workflow_create'
), data={
'label': TEST_WORKFLOW_LABEL,
}, follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(Workflow.objects.count(), 1)
self.assertEquals(Workflow.objects.all()[0].label, TEST_WORKFLOW_LABEL)
def test_delete_workflow(self):
workflow = Workflow.objects.create(label=TEST_WORKFLOW_LABEL)
self.assertEquals(Workflow.objects.count(), 1)
self.assertEquals(Workflow.objects.all()[0].label, TEST_WORKFLOW_LABEL)
response = self.client.post(
reverse(
'document_states:setup_workflow_delete', args=(workflow.pk,)
), follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(Workflow.objects.count(), 0)
def test_create_workflow_state(self):
workflow = Workflow.objects.create(label=TEST_WORKFLOW_LABEL)
response = self.client.post(
reverse(
'document_states:setup_workflow_state_create',
args=(workflow.pk,)
), data={
'label': TEST_WORKFLOW_STATE_LABEL,
'completion': TEST_WORKFLOW_STATE_COMPLETION,
}, follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(WorkflowState.objects.count(), 1)
self.assertEquals(
WorkflowState.objects.all()[0].label, TEST_WORKFLOW_STATE_LABEL
)
self.assertEquals(
WorkflowState.objects.all()[0].completion,
TEST_WORKFLOW_STATE_COMPLETION
)
def test_delete_workflow_state(self):
workflow = Workflow.objects.create(label=TEST_WORKFLOW_LABEL)
workflow_state = WorkflowState.objects.create(
workflow=workflow, label=TEST_WORKFLOW_STATE_LABEL,
completion=TEST_WORKFLOW_STATE_COMPLETION
)
response = self.client.post(
reverse(
'document_states:setup_workflow_state_delete',
args=(workflow_state.pk,)
), follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(WorkflowState.objects.count(), 0)
self.assertEquals(Workflow.objects.count(), 1)
def test_create_workflow_transition(self):
workflow = Workflow.objects.create(label=TEST_WORKFLOW_LABEL)
workflow_initial_state = WorkflowState.objects.create(
workflow=workflow, label=TEST_WORKFLOW_INITIAL_STATE_LABEL,
completion=TEST_WORKFLOW_INITIAL_STATE_COMPLETION, initial=True
)
workflow_state = WorkflowState.objects.create(
workflow=workflow, label=TEST_WORKFLOW_STATE_LABEL,
completion=TEST_WORKFLOW_STATE_COMPLETION
)
response = self.client.post(
reverse(
'document_states:setup_workflow_transition_create',
args=(workflow.pk,)
), data={
'label': TEST_WORKFLOW_TRANSITION_LABEL,
'origin_state': workflow_initial_state.pk,
'destination_state': workflow_state.pk,
}, follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(WorkflowTransition.objects.count(), 1)
self.assertEquals(
WorkflowTransition.objects.all()[0].label,
TEST_WORKFLOW_TRANSITION_LABEL
)
self.assertEquals(
WorkflowTransition.objects.all()[0].origin_state,
workflow_initial_state
)
self.assertEquals(
WorkflowTransition.objects.all()[0].destination_state,
workflow_state
)
def test_delete_workflow_transition(self):
workflow = Workflow.objects.create(label=TEST_WORKFLOW_LABEL)
workflow_initial_state = WorkflowState.objects.create(
workflow=workflow, label=TEST_WORKFLOW_INITIAL_STATE_LABEL,
completion=TEST_WORKFLOW_INITIAL_STATE_COMPLETION, initial=True
)
workflow_state = WorkflowState.objects.create(
workflow=workflow, label=TEST_WORKFLOW_STATE_LABEL,
completion=TEST_WORKFLOW_STATE_COMPLETION
)
workflow_transition = WorkflowTransition.objects.create(
workflow=workflow, label=TEST_WORKFLOW_TRANSITION_LABEL,
origin_state=workflow_initial_state,
destination_state=workflow_state
)
self.assertEquals(WorkflowTransition.objects.count(), 1)
response = self.client.post(
reverse(
'document_states:setup_workflow_transition_delete',
args=(workflow_transition.pk,)
), follow=True
)
self.assertEquals(response.status_code, 200)
self.assertEquals(WorkflowState.objects.count(), 2)
self.assertEquals(Workflow.objects.count(), 1)
self.assertEquals(WorkflowTransition.objects.count(), 0)