Skip to content

Commit

Permalink
fix rest handler test
Browse files Browse the repository at this point in the history
  • Loading branch information
dsschult committed Oct 15, 2024
1 parent 6165e8a commit ec91f13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions iceprod/rest/handlers/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import json
import copy

from jsonschema.exceptions import ValidationError
import tornado.web
Expand Down Expand Up @@ -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')
Expand Down
19 changes: 18 additions & 1 deletion tests/rest/config_test.py
Original file line number Diff line number Diff line change
@@ -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'])
Expand All @@ -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

0 comments on commit ec91f13

Please sign in to comment.