当前位置: 首页>>代码示例>>Python>>正文


Python NotificationsHelper.to_model方法代码示例

本文整理汇总了Python中st2common.models.api.notification.NotificationsHelper.to_model方法的典型用法代码示例。如果您正苦于以下问题:Python NotificationsHelper.to_model方法的具体用法?Python NotificationsHelper.to_model怎么用?Python NotificationsHelper.to_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.models.api.notification.NotificationsHelper的用法示例。


在下文中一共展示了NotificationsHelper.to_model方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: to_model

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def to_model(cls, action):
        name = getattr(action, 'name', None)
        description = getattr(action, 'description', None)
        enabled = bool(getattr(action, 'enabled', True))
        entry_point = str(action.entry_point)
        pack = str(action.pack)
        runner_type = {'name': str(action.runner_type)}
        parameters = getattr(action, 'parameters', dict())
        tags = TagsHelper.to_model(getattr(action, 'tags', []))
        ref = ResourceReference.to_string_reference(pack=pack, name=name)

        if getattr(action, 'notify', None):
            notify = NotificationsHelper.to_model(action.notify)
        else:
            # We use embedded document model for ``notify`` in action model. If notify is
            # set notify to None, Mongoengine interprets ``None`` as unmodified
            # field therefore doesn't delete the embedded document. Therefore, we need
            # to use an empty document.
            notify = NotificationsHelper.to_model({})

        model = cls.model(name=name, description=description, enabled=enabled,
                          entry_point=entry_point, pack=pack, runner_type=runner_type,
                          tags=tags, parameters=parameters, notify=notify,
                          ref=ref)

        return model
开发者ID:Bala96,项目名称:st2,代码行数:28,代码来源:action.py

示例2: to_model

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def to_model(cls, live_action):
        name = getattr(live_action, 'name', None)
        description = getattr(live_action, 'description', None)
        action = live_action.action

        if getattr(live_action, 'start_timestamp', None):
            start_timestamp = isotime.parse(live_action.start_timestamp)
        else:
            start_timestamp = None

        if getattr(live_action, 'end_timestamp', None):
            end_timestamp = isotime.parse(live_action.end_timestamp)
        else:
            end_timestamp = None

        status = getattr(live_action, 'status', None)
        parameters = getattr(live_action, 'parameters', dict())
        context = getattr(live_action, 'context', dict())
        callback = getattr(live_action, 'callback', dict())
        result = getattr(live_action, 'result', None)

        if getattr(live_action, 'notify', None):
            notify = NotificationsHelper.to_model(live_action.notify)
        else:
            notify = None

        model = cls.model(name=name, description=description, action=action,
                          start_timestamp=start_timestamp, end_timestamp=end_timestamp,
                          status=status, parameters=parameters, context=context,
                          callback=callback, result=result, notify=notify)

        return model
开发者ID:hejin,项目名称:st2,代码行数:34,代码来源:action.py

示例3: to_model

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def to_model(cls, action):
        name = getattr(action, "name", None)
        description = getattr(action, "description", None)
        enabled = bool(getattr(action, "enabled", True))
        entry_point = str(action.entry_point)
        pack = str(action.pack)
        runner_type = {"name": str(action.runner_type)}
        parameters = getattr(action, "parameters", dict())
        tags = TagsHelper.to_model(getattr(action, "tags", []))
        ref = ResourceReference.to_string_reference(pack=pack, name=name)

        if getattr(action, "notify", None):
            notify = NotificationsHelper.to_model(action.notify)
        else:
            notify = None

        model = cls.model(
            name=name,
            description=description,
            enable=enabled,
            enabled=enabled,
            entry_point=entry_point,
            pack=pack,
            runner_type=runner_type,
            tags=tags,
            parameters=parameters,
            notify=notify,
            ref=ref,
        )

        return model
开发者ID:jspittman,项目名称:st2,代码行数:33,代码来源:action.py

示例4: test_model_transformations

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def test_model_transformations(self):
        notify = {}
        notify['on_complete'] = {
            'message': 'Action completed.',
            'data': {
                'foo': '{{foo}}',
                'bar': 1,
                'baz': [1, 2, 3]
            }
        }
        notify['on_success'] = {
            'message': 'Action succeeded.',
            'data': {
                'foo': '{{foo}}',
                'bar': 1,
            }
        }
        notify_model = NotificationsHelper.to_model(notify)
        self.assertEqual(notify['on_complete']['message'], notify_model.on_complete.message)
        self.assertDictEqual(notify['on_complete']['data'], notify_model.on_complete.data)
        self.assertEqual(notify['on_success']['message'], notify_model.on_success.message)
        self.assertDictEqual(notify['on_success']['data'], notify_model.on_success.data)

        notify_api = NotificationsHelper.from_model(notify_model)
        self.assertEqual(notify['on_complete']['message'], notify_api['on_complete']['message'])
        self.assertDictEqual(notify['on_complete']['data'], notify_api['on_complete']['data'])
        self.assertEqual(notify['on_success']['message'], notify_api['on_success']['message'])
        self.assertDictEqual(notify['on_success']['data'], notify_api['on_success']['data'])
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:30,代码来源:test_notification_helper.py

示例5: test_model_transformations

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def test_model_transformations(self):
        notify = {}

        notify_model = NotificationsHelper.to_model(notify)
        self.assertEqual(notify_model.on_success, None)
        self.assertEqual(notify_model.on_failure, None)
        self.assertEqual(notify_model.on_complete, None)
        notify_api = NotificationsHelper.from_model(notify_model)
        self.assertEqual(notify_api, {})

        notify['on-complete'] = {
            'message': 'Action completed.',
            'routes': [
                '66'
            ],
            'data': {
                'foo': '{{foo}}',
                'bar': 1,
                'baz': [1, 2, 3]
            }
        }
        notify['on-success'] = {
            'message': 'Action succeeded.',
            'routes': [
                '100'
            ],
            'data': {
                'foo': '{{foo}}',
                'bar': 1,
            }
        }
        notify_model = NotificationsHelper.to_model(notify)
        self.assertEqual(notify['on-complete']['message'], notify_model.on_complete.message)
        self.assertDictEqual(notify['on-complete']['data'], notify_model.on_complete.data)
        self.assertListEqual(notify['on-complete']['routes'], notify_model.on_complete.routes)
        self.assertEqual(notify['on-success']['message'], notify_model.on_success.message)
        self.assertDictEqual(notify['on-success']['data'], notify_model.on_success.data)
        self.assertListEqual(notify['on-success']['routes'], notify_model.on_success.routes)

        notify_api = NotificationsHelper.from_model(notify_model)
        self.assertEqual(notify['on-complete']['message'], notify_api['on-complete']['message'])
        self.assertDictEqual(notify['on-complete']['data'], notify_api['on-complete']['data'])
        self.assertListEqual(notify['on-complete']['routes'], notify_api['on-complete']['routes'])
        self.assertEqual(notify['on-success']['message'], notify_api['on-success']['message'])
        self.assertDictEqual(notify['on-success']['data'], notify_api['on-success']['data'])
        self.assertListEqual(notify['on-success']['routes'], notify_api['on-success']['routes'])
开发者ID:Bala96,项目名称:st2,代码行数:48,代码来源:test_notification_helper.py

示例6: _get_notify

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def _get_notify(self, action_node):
        if action_node.name not in self._skip_notify_tasks:
            if action_node.notify:
                task_notify = NotificationsHelper.to_model(action_node.notify)
                return task_notify
            elif self._chain_notify:
                return self._chain_notify

        return None
开发者ID:LindsayHill,项目名称:st2,代码行数:11,代码来源:action_chain_runner.py

示例7: to_model

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def to_model(cls, action):
        model = super(cls, cls).to_model(action)
        model.enabled = bool(action.enabled)
        model.entry_point = str(action.entry_point)
        model.pack = str(action.pack)
        model.runner_type = {'name': str(action.runner_type)}
        model.parameters = getattr(action, 'parameters', dict())
        model.tags = TagsHelper.to_model(getattr(action, 'tags', []))
        model.ref = ResourceReference.to_string_reference(pack=model.pack, name=model.name)
        if getattr(action, 'notify', None):
            model.notify = NotificationsHelper.to_model(action.notify)

        return model
开发者ID:rgaertner,项目名称:st2,代码行数:15,代码来源:action.py

示例8: test_model_transformations

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def test_model_transformations(self):
        notify = {}

        notify_model = NotificationsHelper.to_model(notify)
        self.assertEqual(notify_model.on_success, None)
        self.assertEqual(notify_model.on_failure, None)
        self.assertEqual(notify_model.on_complete, None)
        notify_api = NotificationsHelper.from_model(notify_model)
        self.assertEqual(notify_api, {})

        notify["on-complete"] = {"message": "Action completed.", "data": {"foo": "{{foo}}", "bar": 1, "baz": [1, 2, 3]}}
        notify["on-success"] = {"message": "Action succeeded.", "data": {"foo": "{{foo}}", "bar": 1}}
        notify_model = NotificationsHelper.to_model(notify)
        self.assertEqual(notify["on-complete"]["message"], notify_model.on_complete.message)
        self.assertDictEqual(notify["on-complete"]["data"], notify_model.on_complete.data)
        self.assertEqual(notify["on-success"]["message"], notify_model.on_success.message)
        self.assertDictEqual(notify["on-success"]["data"], notify_model.on_success.data)

        notify_api = NotificationsHelper.from_model(notify_model)
        self.assertEqual(notify["on-complete"]["message"], notify_api["on-complete"]["message"])
        self.assertDictEqual(notify["on-complete"]["data"], notify_api["on-complete"]["data"])
        self.assertEqual(notify["on-success"]["message"], notify_api["on-success"]["message"])
        self.assertDictEqual(notify["on-success"]["data"], notify_api["on-success"]["data"])
开发者ID:suqi,项目名称:st2,代码行数:25,代码来源:test_notification_helper.py

示例9: _run_action

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    def _run_action(action_node, parent_execution_id, params, wait_for_completion=True):
        execution = LiveActionDB(action=action_node.ref)
        execution.parameters = action_param_utils.cast_params(action_ref=action_node.ref,
                                                              params=params)
        if action_node.notify:
            execution.notify = NotificationsHelper.to_model(action_node.notify)
        execution.context = {
            'parent': str(parent_execution_id),
            'chain': vars(action_node)
        }

        liveaction, _ = action_service.schedule(execution)
        while (wait_for_completion and
               liveaction.status != LIVEACTION_STATUS_SUCCEEDED and
               liveaction.status != LIVEACTION_STATUS_FAILED):
            eventlet.sleep(1)
            liveaction = action_db_util.get_liveaction_by_id(liveaction.id)
        return liveaction
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:20,代码来源:actionchainrunner.py

示例10: FixturesLoader

# 需要导入模块: from st2common.models.api.notification import NotificationsHelper [as 别名]
# 或者: from st2common.models.api.notification.NotificationsHelper import to_model [as 别名]
    FIXTURES_PACK, 'actionchains', 'malformedchain.yaml')
CHAIN_TYPED_PARAMS = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_typed_params.yaml')
CHAIN_SYSTEM_PARAMS = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_typed_system_params.yaml')
CHAIN_WITH_ACTIONPARAM_VARS = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_with_actionparam_vars.yaml')
CHAIN_WITH_SYSTEM_VARS = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_with_system_vars.yaml')
CHAIN_WITH_PUBLISH = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_with_publish.yaml')
CHAIN_WITH_INVALID_ACTION = FixturesLoader().get_fixture_file_path_abs(
    FIXTURES_PACK, 'actionchains', 'chain_with_invalid_action.yaml')

CHAIN_NOTIFY_API = {'notify': {'on-complete': {'message': 'foo happened.'}}}
CHAIN_NOTIFY_DB = NotificationsHelper.to_model(CHAIN_NOTIFY_API)


@mock.patch.object(action_db_util, 'get_runnertype_by_name',
                   mock.MagicMock(return_value=RUNNER))
class TestActionChainRunner(DbTestCase):

    def test_runner_creation(self):
        runner = acr.get_runner()
        self.assertTrue(runner)
        self.assertTrue(runner.runner_id)

    def test_malformed_chain(self):
        try:
            chain_runner = acr.get_runner()
            chain_runner.entry_point = MALFORMED_CHAIN_PATH
开发者ID:amaline,项目名称:st2,代码行数:33,代码来源:test_actionchain.py


注:本文中的st2common.models.api.notification.NotificationsHelper.to_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。