2013-02-01 19:19:18 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Tests for openslides.motion.models
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2013-03-12 21:38:22 +01:00
|
|
|
from openslides.utils.test import TestCase
|
2013-02-01 19:19:18 +01:00
|
|
|
from openslides.participant.models import User
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2013-02-17 17:07:44 +01:00
|
|
|
from openslides.motion.models import Motion, Workflow, State
|
|
|
|
from openslides.motion.exceptions import WorkflowError
|
2013-02-01 19:19:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ModelTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.motion = Motion.objects.create(title='v1')
|
|
|
|
self.test_user = User.objects.create(username='blub')
|
2013-02-06 23:56:21 +01:00
|
|
|
self.workflow = Workflow.objects.get(pk=1)
|
2013-02-01 19:19:18 +01:00
|
|
|
|
|
|
|
def test_create_new_version(self):
|
|
|
|
motion = Motion.objects.create(title='m1')
|
|
|
|
self.assertEqual(motion.versions.count(), 1)
|
|
|
|
|
|
|
|
motion.new_version
|
|
|
|
motion.save()
|
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
|
|
|
|
|
|
|
motion.title = 'new title'
|
|
|
|
motion.save()
|
2013-02-06 23:56:21 +01:00
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
2013-02-01 19:19:18 +01:00
|
|
|
|
|
|
|
motion.save()
|
2013-02-06 23:56:21 +01:00
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
2013-02-01 19:19:18 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
motion.state = State.objects.create(name='automatic_versioning', workflow=self.workflow, versioning=True)
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.text = 'new text'
|
|
|
|
motion.save()
|
|
|
|
self.assertEqual(motion.versions.count(), 3)
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
motion.save()
|
|
|
|
self.assertEqual(motion.versions.count(), 3)
|
|
|
|
|
2013-02-01 19:19:18 +01:00
|
|
|
def test_version_data(self):
|
|
|
|
motion = Motion()
|
|
|
|
self.assertEqual(motion.title, '')
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
self._title
|
|
|
|
|
|
|
|
motion.title = 'title'
|
|
|
|
self.assertEqual(motion._title, 'title')
|
|
|
|
|
|
|
|
motion.reason = 'reason'
|
|
|
|
self.assertEqual(motion._reason, 'reason')
|
|
|
|
|
|
|
|
def test_version(self):
|
|
|
|
motion = Motion.objects.create(title='v1')
|
2013-02-06 23:56:21 +01:00
|
|
|
motion.state = State.objects.create(name='automatic_versioning', workflow=self.workflow, versioning=True)
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.title = 'v2'
|
|
|
|
motion.save()
|
|
|
|
v2_version = motion.version
|
|
|
|
motion.title = 'v3'
|
|
|
|
motion.save()
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
self._title
|
|
|
|
self.assertEqual(motion.title, 'v3')
|
|
|
|
|
2013-02-03 13:54:01 +01:00
|
|
|
motion.version = 1
|
2013-02-01 19:19:18 +01:00
|
|
|
self.assertEqual(motion.title, 'v1')
|
|
|
|
|
|
|
|
motion.version = v2_version
|
|
|
|
self.assertEqual(motion.title, 'v2')
|
|
|
|
|
|
|
|
motion.version = None
|
2013-03-12 21:56:13 +01:00
|
|
|
motion.version = None # Test to set a version to None, which is already None
|
2013-02-01 19:19:18 +01:00
|
|
|
self.assertEqual(motion.title, 'v3')
|
|
|
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
motion.version = 'wrong'
|
|
|
|
|
|
|
|
def test_absolute_url(self):
|
|
|
|
motion_id = self.motion.id
|
|
|
|
|
|
|
|
self.assertEqual(self.motion.get_absolute_url('detail'), '/motion/%d/' % motion_id)
|
|
|
|
self.assertEqual(self.motion.get_absolute_url('edit'), '/motion/%d/edit/' % motion_id)
|
2013-02-02 00:51:08 +01:00
|
|
|
self.assertEqual(self.motion.get_absolute_url('delete'), '/motion/%d/del/' % motion_id)
|
2013-02-01 19:19:18 +01:00
|
|
|
|
|
|
|
def test_supporter(self):
|
|
|
|
self.assertFalse(self.motion.is_supporter(self.test_user))
|
|
|
|
self.motion.support(self.test_user)
|
|
|
|
self.assertTrue(self.motion.is_supporter(self.test_user))
|
|
|
|
self.motion.unsupport(self.test_user)
|
|
|
|
self.assertFalse(self.motion.is_supporter(self.test_user))
|
|
|
|
self.motion.unsupport(self.test_user)
|
|
|
|
|
|
|
|
def test_poll(self):
|
2013-02-06 23:56:21 +01:00
|
|
|
self.motion.state = State.objects.get(pk=1)
|
2013-02-01 19:19:18 +01:00
|
|
|
poll = self.motion.create_poll()
|
|
|
|
self.assertEqual(poll.poll_number, 1)
|
|
|
|
|
|
|
|
def test_state(self):
|
|
|
|
self.motion.reset_state()
|
2013-02-06 23:56:21 +01:00
|
|
|
self.assertEqual(self.motion.state.name, 'submitted')
|
2013-02-01 19:19:18 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
self.motion.state = State.objects.get(pk=5)
|
|
|
|
self.assertEqual(self.motion.state.name, 'published')
|
2013-02-01 19:19:18 +01:00
|
|
|
with self.assertRaises(WorkflowError):
|
|
|
|
self.motion.create_poll()
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
self.motion.state = State.objects.get(pk=6)
|
|
|
|
self.assertEqual(self.motion.state.name, 'permitted')
|
2013-03-11 21:32:09 +01:00
|
|
|
self.assertEqual(self.motion.state.get_action_word(), 'Permit')
|
2013-02-01 19:19:18 +01:00
|
|
|
with self.assertRaises(WorkflowError):
|
|
|
|
self.motion.support(self.test_user)
|
|
|
|
with self.assertRaises(WorkflowError):
|
|
|
|
self.motion.unsupport(self.test_user)
|
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
def test_new_states_or_workflows(self):
|
2013-03-11 21:32:09 +01:00
|
|
|
workflow_1 = Workflow.objects.create(name='W1')
|
2013-02-06 23:56:21 +01:00
|
|
|
state_1 = State.objects.create(name='S1', workflow=workflow_1)
|
|
|
|
workflow_1.first_state = state_1
|
|
|
|
workflow_1.save()
|
2013-03-11 21:32:09 +01:00
|
|
|
workflow_2 = Workflow.objects.create(name='W2')
|
2013-02-06 23:56:21 +01:00
|
|
|
state_2 = State.objects.create(name='S2', workflow=workflow_2)
|
|
|
|
workflow_2.first_state = state_2
|
|
|
|
workflow_2.save()
|
|
|
|
state_3 = State.objects.create(name='S3', workflow=workflow_1)
|
|
|
|
|
2013-02-01 19:19:18 +01:00
|
|
|
with self.assertRaises(WorkflowError):
|
2013-02-06 23:56:21 +01:00
|
|
|
workflow_2.first_state = state_3
|
|
|
|
workflow_2.save()
|
2013-02-01 19:19:18 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
with self.assertRaises(WorkflowError):
|
|
|
|
state_1.next_states.add(state_2)
|
|
|
|
state_1.save()
|