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


Python Trigger.get_all方法代码示例

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


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

示例1: test_create_or_update_trigger_db_simple_triggers

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_create_or_update_trigger_db_simple_triggers(self):
        test_fixtures = {
            'triggertypes': ['triggertype1.yaml']
        }
        loader = FixturesLoader()
        fixtures = loader.save_fixtures_to_db(fixtures_pack='generic', fixtures_dict=test_fixtures)
        triggertypes = fixtures['triggertypes']
        trigger_type_ref = ResourceReference.to_string_reference(
            name=triggertypes['triggertype1.yaml']['name'],
            pack=triggertypes['triggertype1.yaml']['pack'])

        trigger = {
            'name': triggertypes['triggertype1.yaml']['name'],
            'pack': triggertypes['triggertype1.yaml']['pack'],
            'type': trigger_type_ref
        }
        trigger_service.create_or_update_trigger_db(trigger)
        triggers = Trigger.get_all()
        self.assertTrue(len(triggers) == 1, 'Only one trigger should be created.')
        self.assertTrue(triggers[0]['name'] == triggertypes['triggertype1.yaml']['name'])

        # Try adding duplicate
        trigger_service.create_or_update_trigger_db(trigger)
        triggers = Trigger.get_all()
        self.assertTrue(len(triggers) == 1, 'Only one trigger should be present.')
        self.assertTrue(triggers[0]['name'] == triggertypes['triggertype1.yaml']['name'])
开发者ID:lyandut,项目名称:st2,代码行数:28,代码来源:test_trigger_services.py

示例2: test_existing_rules_are_loaded_on_start

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_existing_rules_are_loaded_on_start(self):
        # Assert that we dispatch message for every existing Trigger object
        St2Timer._handle_create_trigger = mock.Mock()

        timer = St2Timer()
        timer._scheduler = mock.Mock()
        timer._trigger_watcher.run = mock.Mock()

        # Verify there are no Trigger and TriggerType in the db wh:w
        self.assertItemsEqual(Trigger.get_all(), [])
        self.assertItemsEqual(TriggerType.get_all(), [])

        # Add a dummy timer Trigger object
        type_ = TIMER_TRIGGER_TYPES.keys()[0]
        parameters = {'unit': 'seconds', 'delta': 1000}
        trigger_db = TriggerDB(id=bson.ObjectId(), name='test_trigger_1', pack='dummy',
                               type=type_, parameters=parameters)
        trigger_db = Trigger.add_or_update(trigger_db)

        # Verify object has been added
        self.assertEqual(len(Trigger.get_all()), 1)

        timer.start()
        timer._trigger_watcher._load_thread.wait()

        # Verify handlers are called
        timer._handle_create_trigger.assert_called_with(trigger_db)
开发者ID:jonico,项目名称:st2,代码行数:29,代码来源:test_timer.py

示例3: test_register_rules

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_register_rules(self):
        # Verify DB is empty at the beginning
        self.assertEqual(len(Rule.get_all()), 0)
        self.assertEqual(len(Trigger.get_all()), 0)

        registrar = RulesRegistrar()
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        # Verify modeles are created
        rule_dbs = Rule.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(rule_dbs), 2)
        self.assertEqual(len(trigger_dbs), 1)

        self.assertEqual(rule_dbs[0].name, 'sample.with_the_same_timer')
        self.assertEqual(rule_dbs[1].name, 'sample.with_timer')
        self.assertTrue(trigger_dbs[0].name is not None)

        # Verify second register call updates existing models
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        rule_dbs = Rule.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(rule_dbs), 2)
        self.assertEqual(len(trigger_dbs), 1)
开发者ID:LindsayHill,项目名称:st2,代码行数:27,代码来源:test_sensor_and_rule_registration.py

示例4: test_register_triggers_from_pack

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_register_triggers_from_pack(self):
        base_path = get_fixtures_base_path()
        pack_dir = os.path.join(base_path, 'dummy_pack_1')

        trigger_type_dbs = TriggerType.get_all()
        self.assertEqual(len(trigger_type_dbs), 0)

        count = triggers_registrar.register_triggers(pack_dir=pack_dir)
        self.assertEqual(count, 2)

        # Verify TriggerTypeDB and corresponding TriggerDB objects have been created
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(trigger_type_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_type_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].type, 'dummy_pack_1.event_handler')

        self.assertEqual(trigger_type_dbs[1].name, 'head_sha_monitor')
        self.assertEqual(trigger_type_dbs[1].pack, 'dummy_pack_1')
        self.assertEqual(trigger_type_dbs[1].payload_schema['type'], 'object')
开发者ID:ddevalco,项目名称:st2,代码行数:27,代码来源:test_triggers_registrar.py

示例5: get_all

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def get_all(self, requester_user=None):
        """
            List all triggers.

            Handles requests:
                GET /triggers/
        """
        trigger_dbs = Trigger.get_all()
        trigger_apis = [TriggerAPI.from_model(trigger_db) for trigger_db in trigger_dbs]
        return trigger_apis
开发者ID:StackStorm,项目名称:st2,代码行数:12,代码来源:triggers.py

示例6: test_trigger_cleanup

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_trigger_cleanup(self):
        post_resp = self.__do_post(self.RULE_1)
        rule_1_id = self.__get_rule_id(post_resp)
        self.assertEqual(post_resp.status_int, http_client.CREATED)

        rule_2 = copy.copy(self.RULE_1)
        rule_2['name'] = rule_2['name'] + '-2'
        post_resp = self.__do_post(rule_2)
        rule_2_id = self.__get_rule_id(post_resp)
        self.assertEqual(post_resp.status_int, http_client.CREATED)

        triggers = Trigger.get_all(**{'type': post_resp.json['trigger']['type']})
        self.assertEqual(len(triggers), 1, 'Exactly 1 should exist')
        self.assertEqual(triggers[0].ref_count, 2, 'ref_count should be 1')

        self.__do_delete(rule_1_id)
        self.__do_delete(rule_2_id)

        # validate cleanup
        triggers = Trigger.get_all(**{'type': post_resp.json['trigger']['type']})
        self.assertEqual(len(triggers), 0, 'Exactly 1 should exist')
开发者ID:peak6,项目名称:st2,代码行数:23,代码来源:test_rules.py

示例7: test_ref_count_trigger_increment

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_ref_count_trigger_increment(self):
        post_resp = self.__do_post(self.RULE_1)
        rule_1_id = self.__get_rule_id(post_resp)
        self.assertEqual(post_resp.status_int, http_client.CREATED)
        # ref_count is not served over API. Likely a choice that will prove unwise.
        triggers = Trigger.get_all(**{'type': post_resp.json['trigger']['type']})
        self.assertEqual(len(triggers), 1, 'Exactly 1 should exist')
        self.assertEqual(triggers[0].ref_count, 1, 'ref_count should be 1')

        # different rule same params
        rule_2 = copy.copy(self.RULE_1)
        rule_2['name'] = rule_2['name'] + '-2'
        post_resp = self.__do_post(rule_2)
        rule_2_id = self.__get_rule_id(post_resp)
        self.assertEqual(post_resp.status_int, http_client.CREATED)
        triggers = Trigger.get_all(**{'type': post_resp.json['trigger']['type']})
        self.assertEqual(len(triggers), 1, 'Exactly 1 should exist')
        self.assertEqual(triggers[0].ref_count, 2, 'ref_count should be 1')

        self.__do_delete(rule_1_id)
        self.__do_delete(rule_2_id)
开发者ID:peak6,项目名称:st2,代码行数:23,代码来源:test_rules.py

示例8: test_register_all_triggers

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_register_all_triggers(self):
        trigger_type_dbs = TriggerType.get_all()
        self.assertEqual(len(trigger_type_dbs), 0)

        packs_base_path = get_fixtures_base_path()
        count = triggers_registrar.register_triggers(packs_base_paths=[packs_base_path])
        self.assertEqual(count, 3)

        # Verify TriggerTypeDB and corresponding TriggerDB objects have been created
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(trigger_type_dbs), 3)
        self.assertEqual(len(trigger_dbs), 3)
开发者ID:ddevalco,项目名称:st2,代码行数:15,代码来源:test_triggers_registrar.py

示例9: test_add_trigger_type_no_params

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_add_trigger_type_no_params(self):
        # Trigger type with no params should create a trigger with same name as trigger type.
        trig_type = {
            'name': 'myawesometriggertype',
            'pack': 'dummy_pack_1',
            'description': 'Words cannot describe how awesome I am.',
            'parameters_schema': {},
            'payload_schema': {}
        }
        trigtype_dbs = trigger_service.add_trigger_models(trigger_types=[trig_type])
        trigger_type, trigger = trigtype_dbs[0]

        trigtype_db = TriggerType.get_by_id(trigger_type.id)
        self.assertEqual(trigtype_db.pack, 'dummy_pack_1')
        self.assertEqual(trigtype_db.name, trig_type.get('name'))
        self.assertTrue(trigger is not None)
        self.assertEqual(trigger.name, trigtype_db.name)

        # Add duplicate
        trigtype_dbs = trigger_service.add_trigger_models(trigger_types=[trig_type])
        triggers = Trigger.get_all()
        self.assertTrue(len(triggers) == 1)
开发者ID:lyandut,项目名称:st2,代码行数:24,代码来源:test_trigger_services.py

示例10: test_register_sensors

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import get_all [as 别名]
    def test_register_sensors(self):
        # Verify DB is empty at the beginning
        self.assertEqual(len(SensorType.get_all()), 0)
        self.assertEqual(len(TriggerType.get_all()), 0)
        self.assertEqual(len(Trigger.get_all()), 0)

        registrar = SensorsRegistrar()
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        # Verify objects have been created
        sensor_dbs = SensorType.get_all()
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()

        self.assertEqual(len(sensor_dbs), 2)
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(sensor_dbs[0].name, 'TestSensor')
        self.assertEqual(sensor_dbs[0].poll_interval, 10)
        self.assertTrue(sensor_dbs[0].enabled)

        self.assertEqual(sensor_dbs[1].name, 'TestSensorDisabled')
        self.assertEqual(sensor_dbs[1].poll_interval, 10)
        self.assertFalse(sensor_dbs[1].enabled)

        self.assertEqual(trigger_type_dbs[0].name, 'trigger_type_1')
        self.assertEqual(trigger_type_dbs[0].pack, 'pack_with_sensor')
        self.assertEqual(len(trigger_type_dbs[0].tags), 0)
        self.assertEqual(trigger_type_dbs[1].name, 'trigger_type_2')
        self.assertEqual(trigger_type_dbs[1].pack, 'pack_with_sensor')
        self.assertEqual(len(trigger_type_dbs[1].tags), 2)
        self.assertEqual(trigger_type_dbs[1].tags[0].name, 'tag1name')
        self.assertEqual(trigger_type_dbs[1].tags[0].value, 'tag1 value')

        # Verify second call to registration doesn't create a duplicate objects
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        sensor_dbs = SensorType.get_all()
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()

        self.assertEqual(len(sensor_dbs), 2)
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(sensor_dbs[0].name, 'TestSensor')
        self.assertEqual(sensor_dbs[0].poll_interval, 10)

        self.assertEqual(trigger_type_dbs[0].name, 'trigger_type_1')
        self.assertEqual(trigger_type_dbs[0].pack, 'pack_with_sensor')
        self.assertEqual(trigger_type_dbs[1].name, 'trigger_type_2')
        self.assertEqual(trigger_type_dbs[1].pack, 'pack_with_sensor')

        # Verify sensor and trigger data is updated on registration
        original_load = registrar._meta_loader.load

        def mock_load(*args, **kwargs):
            # Update poll_interval and trigger_type_2 description
            data = original_load(*args, **kwargs)
            data['poll_interval'] = 50
            data['trigger_types'][1]['description'] = 'test 2'
            return data
        registrar._meta_loader.load = mock_load

        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        sensor_dbs = SensorType.get_all()
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()

        self.assertEqual(len(sensor_dbs), 2)
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(sensor_dbs[0].name, 'TestSensor')
        self.assertEqual(sensor_dbs[0].poll_interval, 50)

        self.assertEqual(trigger_type_dbs[0].name, 'trigger_type_1')
        self.assertEqual(trigger_type_dbs[0].pack, 'pack_with_sensor')
        self.assertEqual(trigger_type_dbs[1].name, 'trigger_type_2')
        self.assertEqual(trigger_type_dbs[1].pack, 'pack_with_sensor')
        self.assertEqual(trigger_type_dbs[1].description, 'test 2')
开发者ID:LindsayHill,项目名称:st2,代码行数:85,代码来源:test_sensor_and_rule_registration.py


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