Merge "Fix a bug with empty context"
This commit is contained in:
@@ -27,32 +27,27 @@ class Execution(base.Resource):
|
|||||||
class ExecutionManager(base.ResourceManager):
|
class ExecutionManager(base.ResourceManager):
|
||||||
resource_class = Execution
|
resource_class = Execution
|
||||||
|
|
||||||
def _validate_context_str(self, context):
|
def _get_context_as_str(self, context):
|
||||||
msg = 'Context must be a dictionary or json compatible string.'
|
msg = 'Context must be a dictionary or json compatible string.'
|
||||||
|
context_as_str = str(context)
|
||||||
if not isinstance(context, str):
|
|
||||||
raise ex.IllegalArgumentException(msg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json.loads(context)
|
json.loads(context_as_str)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ex.IllegalArgumentException(msg + e)
|
raise ex.IllegalArgumentException(msg + e)
|
||||||
|
return context_as_str
|
||||||
|
|
||||||
def create(self, workbook_name, task, context=None):
|
def create(self, workbook_name, task, context=None):
|
||||||
self._ensure_not_empty(workbook_name=workbook_name, task=task)
|
self._ensure_not_empty(workbook_name=workbook_name, task=task)
|
||||||
|
|
||||||
if isinstance(context, dict):
|
|
||||||
context_str = str(context)
|
|
||||||
else:
|
|
||||||
self._validate_context_str(context)
|
|
||||||
context_str = context
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'workbook_name': workbook_name,
|
'workbook_name': workbook_name,
|
||||||
'task': task,
|
'task': task
|
||||||
'context': context_str
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if context is not None:
|
||||||
|
data['context'] = self._get_context_as_str(context)
|
||||||
|
|
||||||
return self._create('/workbooks/%s/executions' % workbook_name, data)
|
return self._create('/workbooks/%s/executions' % workbook_name, data)
|
||||||
|
|
||||||
def update(self, workbook_name, id, state):
|
def update(self, workbook_name, id, state):
|
||||||
|
@@ -53,6 +53,15 @@ class TestExecutions(base.BaseClientTest):
|
|||||||
self.assertEqual(EXECS[0]['state'], ex.state)
|
self.assertEqual(EXECS[0]['state'], ex.state)
|
||||||
self.assertEqual(EXECS[0]['context'], ex.context)
|
self.assertEqual(EXECS[0]['context'], ex.context)
|
||||||
|
|
||||||
|
def test_create_with_empty_context(self):
|
||||||
|
execs = EXECS[0].copy()
|
||||||
|
execs.pop('context')
|
||||||
|
self.mock_http_post(json=execs)
|
||||||
|
ex = self.executions.create(execs['workbook_name'],
|
||||||
|
execs['target_task'])
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
ex.context
|
||||||
|
|
||||||
@unittest2.expectedFailure
|
@unittest2.expectedFailure
|
||||||
def test_create_failure1(self):
|
def test_create_failure1(self):
|
||||||
self.executions.create(EXECS[0]['workbook_name'],
|
self.executions.create(EXECS[0]['workbook_name'],
|
||||||
|
Reference in New Issue
Block a user