2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import config
|
2015-03-26 05:36:10 +01:00
|
|
|
from openslides.motions.exceptions import WorkflowError
|
|
|
|
from openslides.motions.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):
|
2019-01-06 16:22:33 +01:00
|
|
|
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_supporter(self):
|
|
|
|
self.assertFalse(self.motion.is_supporter(self.test_user))
|
2015-04-30 19:13:28 +02:00
|
|
|
self.motion.supporters.add(self.test_user)
|
2013-02-01 19:19:18 +01:00
|
|
|
self.assertTrue(self.motion.is_supporter(self.test_user))
|
2015-04-30 19:13:28 +02:00
|
|
|
self.motion.supporters.remove(self.test_user)
|
2013-02-01 19:19:18 +01:00
|
|
|
self.assertFalse(self.motion.is_supporter(self.test_user))
|
|
|
|
|
|
|
|
def test_state(self):
|
|
|
|
self.motion.reset_state()
|
2019-01-06 16:22:33 +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)
|
2019-01-06 16:22:33 +01:00
|
|
|
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)
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(self.motion.state.name, "permitted")
|
2013-02-01 19:19:18 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
def test_new_states_or_workflows(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow_1 = Workflow.objects.create(name="W1")
|
|
|
|
state_1 = State.objects.create(name="S1", workflow=workflow_1)
|
2013-02-06 23:56:21 +01:00
|
|
|
workflow_1.first_state = state_1
|
|
|
|
workflow_1.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
workflow_2 = Workflow.objects.create(name="W2")
|
|
|
|
state_2 = State.objects.create(name="S2", workflow=workflow_2)
|
2013-02-06 23:56:21 +01:00
|
|
|
workflow_2.first_state = state_2
|
|
|
|
workflow_2.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
state_3 = State.objects.create(name="S3", workflow=workflow_1)
|
2013-02-06 23:56:21 +01:00
|
|
|
|
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):
|
2019-01-06 16:22:33 +01:00
|
|
|
Motion.objects.create(title="foo", text="bar", identifier="")
|
|
|
|
Motion.objects.create(title="foo2", text="bar2", identifier="")
|
2013-07-18 09:15:16 +02:00
|
|
|
|
2014-12-25 10:58:52 +01:00
|
|
|
def test_is_amendment(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
config["motions_amendments_enabled"] = True
|
|
|
|
amendment = Motion.objects.create(title="amendment", parent=self.motion)
|
2014-12-25 10:58:52 +01:00
|
|
|
|
|
|
|
self.assertTrue(amendment.is_amendment())
|
|
|
|
self.assertFalse(self.motion.is_amendment())
|
|
|
|
|
|
|
|
def test_set_identifier_allready_set(self):
|
|
|
|
"""
|
|
|
|
If the motion already has a identifier, the method does nothing.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
motion = Motion(identifier="My test identifier")
|
2014-12-25 10:58:52 +01:00
|
|
|
|
|
|
|
motion.set_identifier()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(motion.identifier, "My test identifier")
|
2014-12-25 10:58:52 +01:00
|
|
|
|
|
|
|
def test_set_identifier_manually(self):
|
|
|
|
"""
|
|
|
|
If the config is set to manually, the method does nothing.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
config["motions_identifier"] = "manually"
|
2014-12-25 10:58:52 +01:00
|
|
|
motion = Motion()
|
|
|
|
|
|
|
|
motion.set_identifier()
|
|
|
|
|
|
|
|
# If the identifier should be set manually, the method does nothing
|
|
|
|
self.assertIsNone(motion.identifier)
|
|
|
|
|
|
|
|
def test_set_identifier_amendment(self):
|
|
|
|
"""
|
|
|
|
If the motion is an amendment, the identifier is the identifier from the
|
|
|
|
parent + a suffix.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
config["motions_amendments_enabled"] = True
|
|
|
|
self.motion.identifier = "Parent identifier"
|
2014-12-25 10:58:52 +01:00
|
|
|
self.motion.save()
|
|
|
|
motion = Motion(parent=self.motion)
|
|
|
|
|
|
|
|
motion.set_identifier()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(motion.identifier, "Parent identifier - 1")
|
2014-12-25 10:58:52 +01:00
|
|
|
|
|
|
|
def test_set_identifier_second_amendment(self):
|
|
|
|
"""
|
|
|
|
If a motion has already an amendment, the second motion gets another
|
|
|
|
identifier.
|
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
config["motions_amendments_enabled"] = True
|
|
|
|
self.motion.identifier = "Parent identifier"
|
2014-12-25 10:58:52 +01:00
|
|
|
self.motion.save()
|
2019-01-06 16:22:33 +01:00
|
|
|
Motion.objects.create(title="Amendment1", parent=self.motion)
|
2014-12-25 10:58:52 +01:00
|
|
|
motion = Motion(parent=self.motion)
|
|
|
|
|
|
|
|
motion.set_identifier()
|
|
|
|
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertEqual(motion.identifier, "Parent identifier - 2")
|
2014-12-25 10:58:52 +01:00
|
|
|
|
2013-04-03 00:40:56 +02:00
|
|
|
|
|
|
|
class ConfigTest(TestCase):
|
|
|
|
def test_stop_submitting(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
self.assertFalse(config["motions_stop_submitting"])
|