Die Versammlung möge beschließen, die Satzung in § 2 Abs. 3 wie folgt zu ändern:
Es wird vor dem Wort "Zweck" das Wort "gemeinnütziger" eingefügt.
''') self.assertEqual(motion2.reason, u'Die Änderung der Satzung ist aufgrund der letzten Erfahrungen eine sinnvolle Maßnahme, weil ...') - self.assertEqual(len(motion2.submitter.all()), 1) - self.assertEqual(motion2.submitter.all()[0].person, special_user) + self.assertEqual(len(motion2.submitters.all()), 1) + self.assertEqual(motion2.submitters.all()[0], special_user) self.assertEqual(motion2.category.name, u"Satzungsanträge") # category is created automatically # check user 'John Doe' diff --git a/tests/old/motions/test_models.py b/tests/old/motions/test_models.py index 50bf3f177..85b5dcb3d 100644 --- a/tests/old/motions/test_models.py +++ b/tests/old/motions/test_models.py @@ -66,11 +66,10 @@ class ModelTest(TestCase): def test_supporter(self): self.assertFalse(self.motion.is_supporter(self.test_user)) - self.motion.support(self.test_user) + self.motion.supporters.add(self.test_user) self.assertTrue(self.motion.is_supporter(self.test_user)) - self.motion.unsupport(self.test_user) + self.motion.supporters.remove(self.test_user) self.assertFalse(self.motion.is_supporter(self.test_user)) - self.motion.unsupport(self.test_user) def test_poll(self): self.motion.state = State.objects.get(pk=1) @@ -89,10 +88,8 @@ class ModelTest(TestCase): self.motion.state = State.objects.get(pk=6) self.assertEqual(self.motion.state.name, 'permitted') self.assertEqual(self.motion.state.get_action_word(), 'Permit') - with self.assertRaises(WorkflowError): - self.motion.support(self.test_user) - with self.assertRaises(WorkflowError): - self.motion.unsupport(self.test_user) + self.assertFalse(self.motion.get_allowed_actions(self.test_user)['support']) + self.assertFalse(self.motion.get_allowed_actions(self.test_user)['unsupport']) def test_new_states_or_workflows(self): workflow_1 = Workflow.objects.create(name='W1') diff --git a/tests/old/motions/test_views.py b/tests/old/motions/test_views.py index d693d5f53..fc3d0cc02 100644 --- a/tests/old/motions/test_views.py +++ b/tests/old/motions/test_views.py @@ -135,7 +135,7 @@ class TestMotionDetailView(MotionViewTestCase): def test_get_without_required_permission_from_state_but_by_submitter(self): self.motion1.state.required_permission_to_see = 'motions.can_manage' self.motion1.state.save() - self.motion1.add_submitter(self.registered) + self.motion1.submitters.add(self.registered) self.check_url('/motions/1/', self.registered_client, 200) @@ -360,7 +360,7 @@ class TestMotionUpdateView(MotionViewTestCase): 'reason': 'motion reason'}) self.assertEqual(response.status_code, 403) motion = Motion.objects.get(pk=1) - motion.add_submitter(self.delegate) + motion.submitters.add(self.delegate) response = self.delegate_client.post(self.url, {'title': 'my title', 'text': 'motion text', 'reason': 'motion reason'}) @@ -468,7 +468,7 @@ class TestMotionUpdateView(MotionViewTestCase): 'text': 'eequei1Tee1aegeNgee0', 'submitter': self.delegate.id}) self.assertEqual(response.status_code, 403) - motion.add_submitter(self.delegate) + motion.submitters.add(self.delegate) # Edit three times, without removal of supporters, with removal and in another state for i in range(3): @@ -480,9 +480,9 @@ class TestMotionUpdateView(MotionViewTestCase): 'text': 'Lohjuu1aebewiu2or3oh'}) self.assertRedirects(response, '/motions/%s/' % motion.id) if i == 0 or i == 2: - self.assertTrue(self.registered in Motion.objects.get(pk=motion.pk).supporters) + self.assertTrue(self.registered in Motion.objects.get(pk=motion.pk).supporters.all()) else: - self.assertFalse(self.registered in Motion.objects.get(pk=motion.pk).supporters) + self.assertFalse(self.registered in Motion.objects.get(pk=motion.pk).supporters.all()) # Preparing the comming (third) run motion = Motion.objects.get(pk=motion.pk) motion.support(self.registered) @@ -577,7 +577,7 @@ class TestMotionDeleteView(MotionViewTestCase): def test_delegate(self): response = self.delegate_client.post('/motions/2/del/', {'yes': 'yes'}) self.assertEqual(response.status_code, 403) - Motion.objects.get(pk=2).add_submitter(self.delegate) + Motion.objects.get(pk=2).submitters.add(self.delegate) response = self.delegate_client.post('/motions/2/del/', {'yes': 'yes'}) self.assertEqual(response.status_code, 403) diff --git a/tests/unit/motions/__init__.py b/tests/unit/motions/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/motions/test_views.py b/tests/unit/motions/test_views.py new file mode 100644 index 000000000..f3cbe49be --- /dev/null +++ b/tests/unit/motions/test_views.py @@ -0,0 +1,81 @@ +from unittest import TestCase +from unittest.mock import MagicMock, patch + +from rest_framework.exceptions import PermissionDenied + +from openslides.motions.views import MotionViewSet + + +class MotionViewSetCreate(TestCase): + """ + Tests create view of MotionViewSet. + """ + def setUp(self): + self.request = MagicMock() + self.view_instance = MotionViewSet() + self.view_instance.request = self.request + self.view_instance.format_kwarg = MagicMock() + self.view_instance.get_serializer = get_serializer_mock = MagicMock() + get_serializer_mock.return_value = self.mock_serializer = MagicMock() + + @patch('openslides.motions.views.config') + def test_simple_create(self, mock_config): + self.request.user.has_perm.return_value = True + self.view_instance.create(self.request) + self.mock_serializer.save.assert_called_with(request_user=self.request.user) + + @patch('openslides.motions.views.config') + def test_user_without_can_create_perm(self, mock_config): + self.request.user.has_perm.return_value = False + with self.assertRaises(PermissionDenied): + self.view_instance.create(self.request) + + +class MotionViewSetUpdate(TestCase): + """ + Tests update view of MotionViewSet. + """ + def setUp(self): + self.request = MagicMock() + self.view_instance = MotionViewSet() + self.view_instance.request = self.request + self.view_instance.kwargs = MagicMock() + self.view_instance.get_object = MagicMock() + self.view_instance.get_serializer = get_serializer_mock = MagicMock() + get_serializer_mock.return_value = self.mock_serializer = MagicMock() + + @patch('openslides.motions.views.config') + def test_simple_update(self, mock_config): + self.request.user.has_perm.return_value = True + self.view_instance.update(self.request) + self.mock_serializer.save.assert_called_with() + + @patch('openslides.motions.views.config') + def test_user_without_perms(self, mock_config): + self.request.user.has_perm.return_value = False + with self.assertRaises(PermissionDenied): + self.view_instance.update(self.request) + + +class MotionViewSetManageVersion(TestCase): + """ + Tests views of MotionViewSet to manage versions. + """ + def setUp(self): + self.request = MagicMock() + self.view_instance = MotionViewSet() + self.view_instance.request = self.request + self.view_instance.get_object = get_object_mock = MagicMock() + get_object_mock.return_value = self.mock_motion = MagicMock() + + def test_activate_version(self): + self.request.method = 'PUT' + self.request.user.has_perm.return_value = True + self.view_instance.manage_version(self.request) + self.mock_motion.save.assert_called_with(update_fields=['active_version']) + + def test_delete_version(self): + self.request.method = 'DELETE' + self.request.user.has_perm.return_value = True + self.view_instance.manage_version(self.request) + self.mock_motion.versions.get.return_value.delete.assert_called_with()