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.exceptions import WorkflowError
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.motion.models import Motion, State, Workflow
|
2014-10-11 14:34:49 +02:00
|
|
|
from openslides.users.models import User
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.test import TestCase
|
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-06-01 12:36:42 +02:00
|
|
|
# Use the simple workflow
|
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):
|
2013-06-01 12:36:42 +02:00
|
|
|
motion = self.motion
|
2013-02-01 19:19:18 +01:00
|
|
|
self.assertEqual(motion.versions.count(), 1)
|
|
|
|
|
2013-06-01 12:36:42 +02:00
|
|
|
# new data, but no new version
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.title = 'new title'
|
|
|
|
motion.save()
|
2013-06-01 12:36:42 +02:00
|
|
|
self.assertEqual(motion.versions.count(), 1)
|
2013-02-01 19:19:18 +01:00
|
|
|
|
2013-06-01 12:36:42 +02:00
|
|
|
# new data and new version
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.text = 'new text'
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.save(use_version=motion.get_new_version())
|
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
|
|
|
self.assertEqual(motion.title, 'new title')
|
|
|
|
self.assertEqual(motion.text, 'new text')
|
2013-02-06 23:56:21 +01:00
|
|
|
|
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')
|
|
|
|
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.text = 'text'
|
|
|
|
self.assertEqual(motion._text, 'text')
|
|
|
|
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.reason = 'reason'
|
|
|
|
self.assertEqual(motion._reason, 'reason')
|
|
|
|
|
|
|
|
def test_version(self):
|
2013-06-01 12:36:42 +02:00
|
|
|
motion = self.motion
|
2013-05-09 23:51:58 +02:00
|
|
|
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.title = 'v2'
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.save(use_version=motion.get_new_version())
|
2013-02-01 19:19:18 +01:00
|
|
|
motion.title = 'v3'
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.save(use_version=motion.get_new_version())
|
2013-02-01 19:19:18 +01:00
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
self._title
|
|
|
|
self.assertEqual(motion.title, 'v3')
|
|
|
|
|
|
|
|
def test_absolute_url(self):
|
|
|
|
motion_id = self.motion.id
|
|
|
|
|
|
|
|
self.assertEqual(self.motion.get_absolute_url('detail'), '/motion/%d/' % motion_id)
|
2014-01-11 17:37:13 +01:00
|
|
|
self.assertEqual(self.motion.get_absolute_url('update'), '/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()
|
2013-04-03 00:40:56 +02:00
|
|
|
|
2013-04-19 14:12:49 +02:00
|
|
|
def test_two_empty_identifiers(self):
|
2013-09-25 10:01:01 +02:00
|
|
|
Motion.objects.create(title='foo', text='bar', identifier='')
|
|
|
|
Motion.objects.create(title='foo2', text='bar2', identifier='')
|
2013-04-19 14:12:49 +02:00
|
|
|
|
2013-04-19 16:02:16 +02:00
|
|
|
def test_do_not_create_new_version_when_permit_old_version(self):
|
|
|
|
motion = Motion()
|
|
|
|
motion.title = 'foo'
|
|
|
|
motion.text = 'bar'
|
|
|
|
motion.save()
|
2013-06-01 12:36:42 +02:00
|
|
|
first_version = motion.get_last_version()
|
2013-04-19 16:02:16 +02:00
|
|
|
|
|
|
|
motion = Motion.objects.get(pk=motion.pk)
|
|
|
|
motion.title = 'New Title'
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.save(use_version=motion.get_new_version())
|
|
|
|
new_version = motion.get_last_version()
|
2013-04-19 16:02:16 +02:00
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
|
|
|
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.active_version = new_version
|
2013-04-19 16:02:16 +02:00
|
|
|
motion.save()
|
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
|
|
|
|
2013-06-01 12:36:42 +02:00
|
|
|
motion.active_version = first_version
|
|
|
|
motion.save(use_version=False)
|
2013-04-19 16:02:16 +02:00
|
|
|
self.assertEqual(motion.versions.count(), 2)
|
|
|
|
|
2013-07-18 09:15:16 +02:00
|
|
|
def test_unicode_with_no_active_version(self):
|
2014-05-19 20:58:09 +02:00
|
|
|
motion = Motion.objects.create(
|
|
|
|
title='test_title_Koowoh1ISheemeey1air',
|
|
|
|
text='test_text_zieFohph0doChi1Uiyoh',
|
|
|
|
identifier='test_identifier_VohT1hu9uhiSh6ooVBFS')
|
2013-07-18 09:15:16 +02:00
|
|
|
motion.active_version = None
|
|
|
|
motion.save(update_fields=['active_version'])
|
2014-05-19 20:58:09 +02:00
|
|
|
# motion.__unicode__() raised an AttributeError
|
|
|
|
self.assertEqual(str(motion), 'test_identifier_VohT1hu9uhiSh6ooVBFS | test_title_Koowoh1ISheemeey1air')
|
2013-07-18 09:15:16 +02:00
|
|
|
|
2013-04-03 00:40:56 +02:00
|
|
|
|
|
|
|
class ConfigTest(TestCase):
|
|
|
|
def test_stop_submitting(self):
|
|
|
|
self.assertFalse(config['motion_stop_submitting'])
|