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
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)
'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
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 = {}