Exemplo n.º 1
0
 def to_model(cls, rule):
     model = super(cls, cls).to_model(rule)
     trigger_db = TriggerService.create_trigger_db_from_rule(rule)
     model.trigger = reference.get_str_resource_ref_from_model(trigger_db)
     model.criteria = dict(getattr(rule, 'criteria', {}))
     validator.validate_criteria(model.criteria)
     model.action = ActionExecutionSpecDB()
     model.action.ref = rule.action['ref']
     model.action.parameters = rule.action['parameters']
     model.enabled = rule.enabled
     model.tags = TagsHelper.to_model(getattr(rule, 'tags', []))
     return model
Exemplo n.º 2
0
 def _create_save_rule(trigger, action=None, enabled=True):
     created = RuleDB()
     created.name = 'rule-1'
     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)
Exemplo n.º 3
0
MOCK_TRIGGER_INSTANCE.occurrence_time = datetime.datetime.utcnow()

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

MOCK_ACTION_EXECUTION = ActionExecutionDB()
MOCK_ACTION_EXECUTION.id = 'actionexec-test-1.id'
MOCK_ACTION_EXECUTION.name = 'actionexec-test-1.name'
MOCK_ACTION_EXECUTION.status = 'scheduled'

MOCK_RULE_1 = RuleDB()
MOCK_RULE_1.id = 'rule-test-1'
MOCK_RULE_1.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_1.criteria = {}
MOCK_RULE_1.action = ActionExecutionSpecDB()
MOCK_RULE_1.action.ref = reference.get_ref_from_model(MOCK_ACTION)
MOCK_RULE_1.enabled = True

MOCK_RULE_2 = RuleDB()
MOCK_RULE_2.id = 'rule-test-2'
MOCK_RULE_2.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER)
MOCK_RULE_2.criteria = {}
MOCK_RULE_2.action = ActionExecutionSpecDB()
MOCK_RULE_2.action.ref = reference.get_ref_from_model(MOCK_ACTION)
MOCK_RULE_2.enabled = True


class EnforceTest(unittest2.TestCase):
    @classmethod
    def setUpClass(cls):
Exemplo n.º 4
0
    'bool': True,
    'int': 1,
    'float': 0.8
}
MOCK_TRIGGER_INSTANCE.occurrence_time = datetime.datetime.utcnow()

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