Merge pull request #1845 from normanjaeckel/ConfigFix

Fixed server error in config update view. Fixed #1828.
This commit is contained in:
Oskar Hahn 2016-01-13 18:36:34 +01:00
commit 82f5239b8c
2 changed files with 11 additions and 1 deletions

View File

@ -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:

View File

@ -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):
"""