本文整理汇总了Python中st2common.models.api.execution.ActionExecutionAPI.to_model方法的典型用法代码示例。如果您正苦于以下问题:Python ActionExecutionAPI.to_model方法的具体用法?Python ActionExecutionAPI.to_model怎么用?Python ActionExecutionAPI.to_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.execution.ActionExecutionAPI
的用法示例。
在下文中一共展示了ActionExecutionAPI.to_model方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crud_partial
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_crud_partial(self):
# Create the DB record.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
model = ActionExecution.get_by_id(obj.id)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, {})
self.assertDictEqual(model.trigger_type, {})
self.assertDictEqual(model.trigger_instance, {})
self.assertDictEqual(model.rule, {})
self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
doc = copy.deepcopy(self.fake_history_subtasks[0]['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
self.assertListEqual(model.children, [])
# Update the DB record.
children = [str(bson.ObjectId()), str(bson.ObjectId())]
model.children = children
ActionExecution.add_or_update(model)
model = ActionExecution.get_by_id(obj.id)
self.assertListEqual(model.children, children)
# Delete the DB record.
ActionExecution.delete(model)
self.assertRaises(StackStormDBObjectNotFoundError, ActionExecution.get_by_id, obj.id)
示例2: test_crud_complete
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_crud_complete(self):
# Create the DB record.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_workflow))
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
model = ActionExecution.get_by_id(obj.id)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(model.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(model.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(model.action, self.fake_history_workflow['action'])
self.assertDictEqual(model.runner, self.fake_history_workflow['runner'])
doc = copy.deepcopy(self.fake_history_workflow['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertIsNone(getattr(model, 'parent', None))
self.assertListEqual(model.children, self.fake_history_workflow['children'])
# Update the DB record.
children = [str(bson.ObjectId()), str(bson.ObjectId())]
model.children = children
ActionExecution.add_or_update(model)
model = ActionExecution.get_by_id(obj.id)
self.assertListEqual(model.children, children)
# Delete the DB record.
ActionExecution.delete(model)
self.assertRaises(ValueError, ActionExecution.get_by_id, obj.id)
示例3: setUpClass
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestActionExecutionFilters, cls).setUpClass()
cls.dt_base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
cls.num_records = 100
cls.refs = {}
cls.start_timestamps = []
cls.fake_types = [
{
'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance']),
'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
'action': copy.deepcopy(fixture.ARTIFACTS['actions']['chain']),
'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['action-chain']),
'liveaction': copy.deepcopy(fixture.ARTIFACTS['liveactions']['workflow']),
'context': copy.deepcopy(fixture.ARTIFACTS['context']),
'children': []
},
{
'action': copy.deepcopy(fixture.ARTIFACTS['actions']['local']),
'runner': copy.deepcopy(fixture.ARTIFACTS['runners']['run-local']),
'liveaction': copy.deepcopy(fixture.ARTIFACTS['liveactions']['task1'])
}
]
def assign_parent(child):
candidates = [v for k, v in cls.refs.items() if v.action['name'] == 'chain']
if candidates:
parent = random.choice(candidates)
child['parent'] = str(parent.id)
parent.children.append(child['id'])
cls.refs[str(parent.id)] = ActionExecution.add_or_update(parent)
for i in range(cls.num_records):
obj_id = str(bson.ObjectId())
timestamp = cls.dt_base + datetime.timedelta(seconds=i)
fake_type = random.choice(cls.fake_types)
data = copy.deepcopy(fake_type)
data['id'] = obj_id
data['start_timestamp'] = isotime.format(timestamp, offset=False)
data['end_timestamp'] = isotime.format(timestamp, offset=False)
data['status'] = data['liveaction']['status']
data['result'] = data['liveaction']['result']
if fake_type['action']['name'] == 'local' and random.choice([True, False]):
assign_parent(data)
wb_obj = ActionExecutionAPI(**data)
db_obj = ActionExecutionAPI.to_model(wb_obj)
cls.refs[obj_id] = ActionExecution.add_or_update(db_obj)
cls.start_timestamps.append(timestamp)
cls.start_timestamps = sorted(cls.start_timestamps)
示例4: setUpClass
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestActionExecutionFilters, cls).setUpClass()
cls.dt_base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
cls.num_records = 100
cls.refs = {}
cls.start_timestamps = []
cls.fake_types = [
{
"trigger": copy.deepcopy(fixture.ARTIFACTS["trigger"]),
"trigger_type": copy.deepcopy(fixture.ARTIFACTS["trigger_type"]),
"trigger_instance": copy.deepcopy(fixture.ARTIFACTS["trigger_instance"]),
"rule": copy.deepcopy(fixture.ARTIFACTS["rule"]),
"action": copy.deepcopy(fixture.ARTIFACTS["actions"]["chain"]),
"runner": copy.deepcopy(fixture.ARTIFACTS["runners"]["action-chain"]),
"liveaction": copy.deepcopy(fixture.ARTIFACTS["liveactions"]["workflow"]),
"context": copy.deepcopy(fixture.ARTIFACTS["context"]),
"children": [],
},
{
"action": copy.deepcopy(fixture.ARTIFACTS["actions"]["local"]),
"runner": copy.deepcopy(fixture.ARTIFACTS["runners"]["run-local"]),
"liveaction": copy.deepcopy(fixture.ARTIFACTS["liveactions"]["task1"]),
},
]
def assign_parent(child):
candidates = [v for k, v in cls.refs.iteritems() if v.action["name"] == "chain"]
if candidates:
parent = random.choice(candidates)
child["parent"] = str(parent.id)
parent.children.append(child["id"])
cls.refs[str(parent.id)] = ActionExecution.add_or_update(parent)
for i in range(cls.num_records):
obj_id = str(bson.ObjectId())
timestamp = cls.dt_base + datetime.timedelta(seconds=i)
fake_type = random.choice(cls.fake_types)
data = copy.deepcopy(fake_type)
data["id"] = obj_id
data["start_timestamp"] = isotime.format(timestamp, offset=False)
data["end_timestamp"] = isotime.format(timestamp, offset=False)
data["status"] = data["liveaction"]["status"]
data["result"] = data["liveaction"]["result"]
if fake_type["action"]["name"] == "local" and random.choice([True, False]):
assign_parent(data)
wb_obj = ActionExecutionAPI(**data)
db_obj = ActionExecutionAPI.to_model(wb_obj)
cls.refs[obj_id] = ActionExecution.add_or_update(db_obj)
cls.start_timestamps.append(timestamp)
cls.start_timestamps = sorted(cls.start_timestamps)
示例5: test_datetime_range
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_datetime_range(self):
base = date_utils.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
for i in range(60):
timestamp = base + datetime.timedelta(seconds=i)
doc = copy.deepcopy(self.fake_history_subtasks[0])
doc['id'] = str(bson.ObjectId())
doc['start_timestamp'] = isotime.format(timestamp)
obj = ActionExecutionAPI(**doc)
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
objs = ActionExecution.query(start_timestamp=dt_range)
self.assertEqual(len(objs), 10)
dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
objs = ActionExecution.query(start_timestamp=dt_range)
self.assertEqual(len(objs), 10)
示例6: test_model_complete
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_model_complete(self):
# Create API object.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_workflow))
self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
self.assertEquals(obj.liveaction, self.fake_history_workflow['liveaction'])
self.assertIsNone(getattr(obj, 'parent', None))
self.assertListEqual(obj.children, self.fake_history_workflow['children'])
# Convert API object to DB model.
model = ActionExecutionAPI.to_model(obj)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(model.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(model.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(model.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(model.action, self.fake_history_workflow['action'])
self.assertDictEqual(model.runner, self.fake_history_workflow['runner'])
doc = copy.deepcopy(self.fake_history_workflow['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertIsNone(getattr(model, 'parent', None))
self.assertListEqual(model.children, self.fake_history_workflow['children'])
# Convert DB model to API object.
obj = ActionExecutionAPI.from_model(model)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(obj.trigger, self.fake_history_workflow['trigger'])
self.assertDictEqual(obj.trigger_type, self.fake_history_workflow['trigger_type'])
self.assertDictEqual(obj.trigger_instance, self.fake_history_workflow['trigger_instance'])
self.assertDictEqual(obj.rule, self.fake_history_workflow['rule'])
self.assertDictEqual(obj.action, self.fake_history_workflow['action'])
self.assertDictEqual(obj.runner, self.fake_history_workflow['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_workflow['liveaction'])
self.assertIsNone(getattr(obj, 'parent', None))
self.assertListEqual(obj.children, self.fake_history_workflow['children'])
示例7: test_model_partial
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_model_partial(self):
# Create API object.
obj = ActionExecutionAPI(**copy.deepcopy(self.fake_history_subtasks[0]))
self.assertIsNone(getattr(obj, 'trigger', None))
self.assertIsNone(getattr(obj, 'trigger_type', None))
self.assertIsNone(getattr(obj, 'trigger_instance', None))
self.assertIsNone(getattr(obj, 'rule', None))
self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_subtasks[0]['liveaction'])
self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
self.assertIsNone(getattr(obj, 'children', None))
# Convert API object to DB model.
model = ActionExecutionAPI.to_model(obj)
self.assertEqual(str(model.id), obj.id)
self.assertDictEqual(model.trigger, {})
self.assertDictEqual(model.trigger_type, {})
self.assertDictEqual(model.trigger_instance, {})
self.assertDictEqual(model.rule, {})
self.assertDictEqual(model.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(model.runner, self.fake_history_subtasks[0]['runner'])
doc = copy.deepcopy(self.fake_history_subtasks[0]['liveaction'])
doc['start_timestamp'] = doc['start_timestamp']
doc['end_timestamp'] = doc['end_timestamp']
self.assertDictEqual(model.liveaction, doc)
self.assertEqual(model.parent, self.fake_history_subtasks[0]['parent'])
self.assertListEqual(model.children, [])
# Convert DB model to API object.
obj = ActionExecutionAPI.from_model(model)
self.assertEqual(str(model.id), obj.id)
self.assertIsNone(getattr(obj, 'trigger', None))
self.assertIsNone(getattr(obj, 'trigger_type', None))
self.assertIsNone(getattr(obj, 'trigger_instance', None))
self.assertIsNone(getattr(obj, 'rule', None))
self.assertDictEqual(obj.action, self.fake_history_subtasks[0]['action'])
self.assertDictEqual(obj.runner, self.fake_history_subtasks[0]['runner'])
self.assertDictEqual(obj.liveaction, self.fake_history_subtasks[0]['liveaction'])
self.assertEqual(obj.parent, self.fake_history_subtasks[0]['parent'])
self.assertIsNone(getattr(obj, 'children', None))
示例8: test_sort_by_start_timestamp
# 需要导入模块: from st2common.models.api.execution import ActionExecutionAPI [as 别名]
# 或者: from st2common.models.api.execution.ActionExecutionAPI import to_model [as 别名]
def test_sort_by_start_timestamp(self):
base = isotime.add_utc_tz(datetime.datetime(2014, 12, 25, 0, 0, 0))
for i in range(60):
timestamp = base + datetime.timedelta(seconds=i)
doc = copy.deepcopy(self.fake_history_subtasks[0])
doc['id'] = str(bson.ObjectId())
doc['start_timestamp'] = isotime.format(timestamp)
obj = ActionExecutionAPI(**doc)
ActionExecution.add_or_update(ActionExecutionAPI.to_model(obj))
dt_range = '2014-12-25T00:00:10Z..2014-12-25T00:00:19Z'
objs = ActionExecution.query(start_timestamp=dt_range,
order_by=['start_timestamp'])
self.assertLess(objs[0]['start_timestamp'],
objs[9]['start_timestamp'])
dt_range = '2014-12-25T00:00:19Z..2014-12-25T00:00:10Z'
objs = ActionExecution.query(start_timestamp=dt_range,
order_by=['-start_timestamp'])
self.assertLess(objs[9]['start_timestamp'],
objs[0]['start_timestamp'])