コード例 #1
0
ファイル: tester.py プロジェクト: sarkartanzil/st2
 def _get_rule_db_from_file(self, file_path):
     data = self._meta_loader.load(file_path=file_path)
     rule_db = RuleDB()
     rule_db.trigger = data['trigger']['type']
     rule_db.criteria = data.get('criteria', None)
     rule_db.action = {}
     rule_db.enabled = True
     return rule_db
コード例 #2
0
ファイル: tester.py プロジェクト: Kailashkatheth1/st2
 def _get_rule_db_from_file(self, file_path):
     data = self._meta_loader.load(file_path=file_path)
     rule_db = RuleDB()
     rule_db.trigger = data['trigger']['type']
     rule_db.criteria = data.get('criteria', None)
     rule_db.action = {}
     rule_db.enabled = True
     return rule_db
コード例 #3
0
ファイル: test_db.py プロジェクト: wdowling/st2
 def _create_save_rule(trigger, action=None, enabled=True):
     name = 'rule-1'
     pack = 'default'
     ref = ResourceReference.to_string_reference(name=name, pack=pack)
     created = RuleDB(name=name, pack=pack, ref=ref)
     created.description = ''
     created.enabled = enabled
     created.trigger = reference.get_str_resource_ref_from_model(trigger)
     created.criteria = {}
     created.action = ActionExecutionSpecDB()
     action_ref = ResourceReference(pack=action.pack, name=action.name).ref
     created.action.ref = action_ref
     created.action.pack = action.pack
     created.action.parameters = {}
     return Rule.add_or_update(created)
コード例 #4
0
ファイル: test_db.py プロジェクト: azamsheriff/st2
 def _create_save_rule(trigger, action=None, enabled=True):
     name = 'rule-1'
     pack = 'default'
     ref = ResourceReference.to_string_reference(name=name, pack=pack)
     created = RuleDB(name=name, pack=pack, ref=ref)
     created.description = ''
     created.enabled = enabled
     created.trigger = reference.get_str_resource_ref_from_model(trigger)
     created.criteria = {}
     created.action = ActionExecutionSpecDB()
     action_ref = ResourceReference(pack=action.pack, name=action.name).ref
     created.action.ref = action_ref
     created.action.pack = action.pack
     created.action.parameters = {}
     return Rule.add_or_update(created)
コード例 #5
0
ファイル: test_filter.py プロジェクト: sarkartanzil/st2
    'p2': 'preYYYpost',
    'bool': True,
    'int': 1,
    'float': 0.8
}
MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now()

MOCK_ACTION = ActionDB()
MOCK_ACTION.id = bson.ObjectId()
MOCK_ACTION.name = 'action-test-1.name'

MOCK_RULE_1 = RuleDB()
MOCK_RULE_1.id = bson.ObjectId()
MOCK_RULE_1.name = "some1"
MOCK_RULE_1.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_1.criteria = {}
MOCK_RULE_1.action = ActionExecutionSpecDB(ref="somepack.someaction")

MOCK_RULE_2 = RuleDB()
MOCK_RULE_2.id = bson.ObjectId()
MOCK_RULE_1.name = "some2"
MOCK_RULE_2.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_2.criteria = {}
MOCK_RULE_2.action = ActionExecutionSpecDB(ref="somepack.someaction")


@mock.patch.object(reference, 'get_model_by_resource_ref',
                   mock.MagicMock(return_value=MOCK_TRIGGER))
class FilterTest(DbTestCase):
    def test_empty_criteria(self):
        rule = MOCK_RULE_1
コード例 #6
0
ファイル: test_filter.py プロジェクト: ipv1337/st2
MOCK_TRIGGER_INSTANCE = TriggerInstanceDB()
MOCK_TRIGGER_INSTANCE.id = bson.ObjectId()
MOCK_TRIGGER_INSTANCE.trigger = MOCK_TRIGGER.get_reference().ref
MOCK_TRIGGER_INSTANCE.payload = {"p1": "v1", "p2": "preYYYpost", "bool": True, "int": 1, "float": 0.8}
MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now()

MOCK_ACTION = ActionDB()
MOCK_ACTION.id = bson.ObjectId()
MOCK_ACTION.name = "action-test-1.name"

MOCK_RULE_1 = RuleDB()
MOCK_RULE_1.id = bson.ObjectId()
MOCK_RULE_1.name = "some1"
MOCK_RULE_1.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_1.criteria = {}
MOCK_RULE_1.action = ActionExecutionSpecDB(ref="somepack.someaction")

MOCK_RULE_2 = RuleDB()
MOCK_RULE_2.id = bson.ObjectId()
MOCK_RULE_1.name = "some2"
MOCK_RULE_2.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_2.criteria = {}
MOCK_RULE_2.action = ActionExecutionSpecDB(ref="somepack.someaction")


@mock.patch.object(reference, "get_model_by_resource_ref", mock.MagicMock(return_value=MOCK_TRIGGER))
class FilterTest(DbTestCase):
    def test_empty_criteria(self):
        rule = MOCK_RULE_1
        rule.criteria = {}