Fixed server error in config update view. Fixed #1828.

This commit is contained in:
Norman Jäckel 2016-01-13 15:04:47 +01:00
parent 919425cbb3
commit 3fc82a596c
2 changed files with 11 additions and 1 deletions

View File

@ -475,7 +475,9 @@ class ConfigViewSet(ViewSet):
Example: {"value": 42} Example: {"value": 42}
""" """
key = kwargs['pk'] 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. # Validate and change value.
try: try:

View File

@ -154,6 +154,14 @@ class ConfigViewSet(TestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data, {'detail': 'Invalid input.'}) 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): def validator_for_testing(value):
""" """