From 01ee197eb67adb300572d72f211763d7a282af96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 14 Jan 2016 23:13:15 +0100 Subject: [PATCH] Enabled the option to disabled version for motion update requests. --- openslides/motions/views.py | 2 +- tests/integration/motions/test_viewset.py | 23 ++++++++++++++++++++++- tests/unit/motions/test_views.py | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index a44afaa46..4e098aa61 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -114,7 +114,7 @@ class MotionViewSet(ModelViewSet): data=request.data, partial=kwargs.get('partial', False)) serializer.is_valid(raise_exception=True) - updated_motion = serializer.save() + updated_motion = serializer.save(disable_versioning=request.data.get('disable_versioning')) # Write the log message, check removal of supporters and initiate response. # TODO: Log if a version was updated. diff --git a/tests/integration/motions/test_viewset.py b/tests/integration/motions/test_viewset.py index b7f664974..d46c7dcd9 100644 --- a/tests/integration/motions/test_viewset.py +++ b/tests/integration/motions/test_viewset.py @@ -7,7 +7,7 @@ from rest_framework.test import APIClient from openslides.core.config import config from openslides.core.models import Tag -from openslides.motions.models import Category, Motion +from openslides.motions.models import Category, Motion, State from openslides.utils.test import TestCase @@ -220,6 +220,27 @@ class UpdateMotion(TestCase): self.assertEqual(motion.title, 'new_title_ohph1aedie5Du8sai2ye') self.assertEqual(motion.supporters.count(), 0) + def test_with_new_version(self): + self.motion.set_state(State.objects.get(name='permitted')) + self.motion.save() + response = self.client.patch( + reverse('motion-detail', args=[self.motion.pk]), + {'text': 'test_text_aeb1iaghahChong5od3a'}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + motion = Motion.objects.get() + self.assertEqual(motion.versions.count(), 2) + + def test_without_new_version(self): + self.motion.set_state(State.objects.get(name='permitted')) + self.motion.save() + response = self.client.patch( + reverse('motion-detail', args=[self.motion.pk]), + {'text': 'test_text_aeThaeroneiroo7Iophu', + 'disable_versioning': True}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + motion = Motion.objects.get() + self.assertEqual(motion.versions.count(), 1) + class ManageVersion(TestCase): """ diff --git a/tests/unit/motions/test_views.py b/tests/unit/motions/test_views.py index f3cbe49be..b53f59ae9 100644 --- a/tests/unit/motions/test_views.py +++ b/tests/unit/motions/test_views.py @@ -47,8 +47,9 @@ class MotionViewSetUpdate(TestCase): @patch('openslides.motions.views.config') def test_simple_update(self, mock_config): self.request.user.has_perm.return_value = True + self.request.data.get.return_value = versioning_mock = MagicMock() self.view_instance.update(self.request) - self.mock_serializer.save.assert_called_with() + self.mock_serializer.save.assert_called_with(disable_versioning=versioning_mock) @patch('openslides.motions.views.config') def test_user_without_perms(self, mock_config):