diff --git a/iceprod/rest/handlers/config.py b/iceprod/rest/handlers/config.py index 52bda1c7..9e81c7dd 100644 --- a/iceprod/rest/handlers/config.py +++ b/iceprod/rest/handlers/config.py @@ -1,5 +1,6 @@ import logging import json +import copy from jsonschema.exceptions import ValidationError import tornado.web @@ -79,11 +80,11 @@ async def put(self, dataset_id): elif data['dataset_id'] != dataset_id: raise tornado.web.HTTPError(400, reason='dataset_id mismatch') try: - c = Config(data) + c = Config(copy.deepcopy(data)) c.fill_defaults() c.validate() except ValidationError as e: - raise tornado.web.HTTPError(400, reason=str(e)) + raise tornado.web.HTTPError(400, reason=str(e).split('\n', 1)[0]) except Exception: logger.warning('unknown config validation error', exc_info=True) raise tornado.web.HTTPError(400, reason='unknown validation error') diff --git a/tests/rest/config_test.py b/tests/rest/config_test.py index c8ddeeab..b6182202 100644 --- a/tests/rest/config_test.py +++ b/tests/rest/config_test.py @@ -1,6 +1,8 @@ import pytest import requests.exceptions +from iceprod.core.config import Config + async def test_rest_config_err(server): client = server(roles=['system']) @@ -14,7 +16,22 @@ async def test_rest_config(server): data = { 'name': 'foo' } - await client.request('PUT', '/config/bar', data) + with pytest.raises(requests.exceptions.HTTPError) as exc_info: + await client.request('PUT', '/config/bar', data) + assert exc_info.value.response.status_code == 400 + assert 'required property' in exc_info.value.response.text + + data = { + 'tasks': [{ + 'name': 'task', + 'trays': [{ + 'modules': [{ + }], + }], + }], + } + await client.request('PUT', '/config/bar', data) + ret = await client.request('GET', '/config/bar') assert ret == data