From 3fc82a596c72ff14175999280ede616d4c7cf028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 13 Jan 2016 15:04:47 +0100 Subject: [PATCH] Fixed server error in config update view. Fixed #1828. --- openslides/core/views.py | 4 +++- tests/integration/core/test_views.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openslides/core/views.py b/openslides/core/views.py index 07a72cb74..218e318f6 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -475,7 +475,9 @@ class ConfigViewSet(ViewSet): Example: {"value": 42} """ key = kwargs['pk'] - value = request.data['value'] + value = request.data.get('value') + if value is None: + raise ValidationError({'detail': 'Invalid input. Config value is missing.'}) # Validate and change value. try: diff --git a/tests/integration/core/test_views.py b/tests/integration/core/test_views.py index 0791731fc..4aa88ed03 100644 --- a/tests/integration/core/test_views.py +++ b/tests/integration/core/test_views.py @@ -154,6 +154,14 @@ class ConfigViewSet(TestCase): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'detail': 'Invalid input.'}) + def test_update_only_with_key(self): + self.client = APIClient() + self.client.login(username='admin', password='admin') + response = self.client.put( + reverse('config-detail', args=['test_var_Xeiizi7ooH8Thuk5aida'])) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data, {'detail': 'Invalid input. Config value is missing.'}) + def validator_for_testing(value): """