def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or 'uid' or type' and 'parameters' keys. :param trigger: Trigger reference or dictionary with trigger query filters. :type trigger: ``str`` or ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ trigger_db = get_trigger_db_by_ref_or_dict(trigger=trigger) if not trigger_db: LOG.debug('No trigger in db for %s', trigger) if raise_on_no_trigger: raise StackStormDBObjectNotFoundError('Trigger not found for %s' % trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time trigger_instance.status = TRIGGER_INSTANCE_PENDING return TriggerInstance.add_or_update(trigger_instance)
def test_purge(self): now = date_utils.get_datetime_utc_now() instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger', payload={ 'hola': 'hi', 'kuraci': 'chicken' }, occurrence_time=now - timedelta(days=20), status=TRIGGER_INSTANCE_PROCESSED) TriggerInstance.add_or_update(instance_db) instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger', payload={ 'hola': 'hi', 'kuraci': 'chicken' }, occurrence_time=now - timedelta(days=5), status=TRIGGER_INSTANCE_PROCESSED) TriggerInstance.add_or_update(instance_db) self.assertEqual(len(TriggerInstance.get_all()), 2) purge_trigger_instances(logger=LOG, timestamp=now - timedelta(days=10)) self.assertEqual(len(TriggerInstance.get_all()), 1)
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'type' and 'parameters'. :param trigger: Dictionary with trigger query filters. :type trigger: ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ # TODO: This is nasty, this should take a unique reference and not a dict if isinstance(trigger, six.string_types): trigger_db = TriggerService.get_trigger_db_by_ref(trigger) else: type_ = trigger.get('type', None) parameters = trigger.get('parameters', {}) trigger_db = TriggerService.get_trigger_db_given_type_and_params(type=type_, parameters=parameters) if trigger_db is None: LOG.debug('No trigger in db for %s', trigger) if raise_on_no_trigger: raise StackStormDBObjectNotFoundError('Trigger not found for %s', trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time trigger_instance.status = TRIGGER_INSTANCE_PENDING return TriggerInstance.add_or_update(trigger_instance)
def create_trigger_instance(trigger, payload, occurrence_time): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'type' and 'parameters'. :param trigger: Dictionary with trigger query filters. :type trigger: ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ # TODO: This is nasty, this should take a unique reference and not a dict if isinstance(trigger, six.string_types): trigger_db = TriggerService.get_trigger_db_by_ref(trigger) else: type_ = trigger.get('type', None) parameters = trigger.get('parameters', {}) trigger_db = TriggerService.get_trigger_db_given_type_and_params( type=type_, parameters=parameters) if trigger_db is None: LOG.info('No trigger in db for %s', trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time return TriggerInstance.add_or_update(trigger_instance)
def _create_trigger_instance(cls, trigger_ref, payload): trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = date_utils.get_datetime_utc_now() created = TriggerInstance.add_or_update(trigger_instance) cls.triggerinstance_count += 1 return created
def _create_trigger_instance(cls, trigger_ref, payload): trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = datetime.datetime.utcnow() created = TriggerInstance.add_or_update(trigger_instance) cls.triggerinstance_count += 1 return created
def _get_trigger_instance_db_from_file(self, file_path): data = self._meta_loader.load(file_path=file_path) instance = TriggerInstanceDB(**data) instance.id = 'rule_tester_instance' trigger_ref = ResourceReference.from_string_reference(instance['trigger']) trigger_db = TriggerDB(pack=trigger_ref.pack, name=trigger_ref.name, type=trigger_ref.ref) return instance, trigger_db
def _get_trigger_instance_db_from_file(self, file_path): data = self._meta_loader.load(file_path=file_path) instance = TriggerInstanceDB(**data) instance.id = 'rule_tester_instance' trigger_ref = ResourceReference.from_string_reference( instance['trigger']) trigger_db = TriggerDB(pack=trigger_ref.pack, name=trigger_ref.name, type=trigger_ref.ref) return instance, trigger_db
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or 'uid' or type' and 'parameters' keys. :param trigger: Trigger reference or dictionary with trigger query filters. :type trigger: ``str`` or ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ # TODO: This is nasty, this should take a unique reference and not a dict if isinstance(trigger, six.string_types): trigger_db = TriggerService.get_trigger_db_by_ref(trigger) else: # If id / uid is available we try to look up Trigger by id. This way we can avoid bug in # pymongo / mongoengine related to "parameters" dictionary lookups trigger_id = trigger.get('id', None) trigger_uid = trigger.get('uid', None) # TODO: Remove parameters dictionary look up when we can confirm each trigger dictionary # passed to this method always contains id or uid if trigger_id: LOG.debug('Looking up TriggerDB by id: %s', trigger_id) trigger_db = TriggerService.get_trigger_db_by_id(id=trigger_id) elif trigger_uid: LOG.debug('Looking up TriggerDB by uid: %s', trigger_uid) trigger_db = TriggerService.get_trigger_db_by_uid(uid=trigger_uid) else: # Last resort - look it up by parameters trigger_type = trigger.get('type', None) parameters = trigger.get('parameters', {}) LOG.debug('Looking up TriggerDB by type and parameters: type=%s, parameters=%s', trigger_type, parameters) trigger_db = TriggerService.get_trigger_db_given_type_and_params(type=trigger_type, parameters=parameters) if trigger_db is None: LOG.debug('No trigger in db for %s', trigger) if raise_on_no_trigger: raise StackStormDBObjectNotFoundError('Trigger not found for %s', trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time trigger_instance.status = TRIGGER_INSTANCE_PENDING return TriggerInstance.add_or_update(trigger_instance)
def _create_trigger_instance(cls, trigger_ref, payload, seconds): # Note: We use 1 second intervals between occurence time to prevent # occasional test failures occurrence_time = date_utils.get_datetime_utc_now() occurrence_time = occurrence_time + datetime.timedelta(seconds=seconds) trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time created = TriggerInstance.add_or_update(trigger_instance) cls.triggerinstance_count += 1 return created
def _create_save_triggerinstance(trigger): created = TriggerInstanceDB( trigger=trigger.get_reference().ref, payload={}, occurrence_time=date_utils.get_datetime_utc_now(), status=TRIGGER_INSTANCE_PROCESSED) return TriggerInstance.add_or_update(created)
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or 'uid' or type' and 'parameters' keys. :param trigger: Trigger reference or dictionary with trigger query filters. :type trigger: ``str`` or ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ trigger_db = get_trigger_db_by_ref_or_dict(trigger=trigger) if not trigger_db: LOG.debug("No trigger in db for %s", trigger) if raise_on_no_trigger: raise StackStormDBObjectNotFoundError("Trigger not found for %s" % trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time trigger_instance.status = TRIGGER_INSTANCE_PENDING return TriggerInstance.add_or_update(trigger_instance)
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False): """ This creates a trigger instance object given trigger and payload. Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or 'uid' or type' and 'parameters' keys. :param trigger: Trigger reference or dictionary with trigger query filters. :type trigger: ``str`` or ``dict`` :param payload: Trigger payload. :type payload: ``dict`` """ # TODO: This is nasty, this should take a unique reference and not a dict if isinstance(trigger, six.string_types): trigger_db = TriggerService.get_trigger_db_by_ref(trigger) else: # If id / uid is available we try to look up Trigger by id. This way we can avoid bug in # pymongo / mongoengine related to "parameters" dictionary lookups trigger_id = trigger.get('id', None) trigger_uid = trigger.get('uid', None) # TODO: Remove parameters dictionary look up when we can confirm each trigger dictionary # passed to this method always contains id or uid if trigger_id: LOG.debug('Looking up TriggerDB by id: %s', trigger_id) trigger_db = TriggerService.get_trigger_db_by_id(id=trigger_id) elif trigger_uid: LOG.debug('Looking up TriggerDB by uid: %s', trigger_uid) trigger_db = TriggerService.get_trigger_db_by_uid(uid=trigger_uid) else: # Last resort - look it up by parameters trigger_type = trigger.get('type', None) parameters = trigger.get('parameters', {}) LOG.debug( 'Looking up TriggerDB by type and parameters: type=%s, parameters=%s', trigger_type, parameters) trigger_db = TriggerService.get_trigger_db_given_type_and_params( type=trigger_type, parameters=parameters) if trigger_db is None: LOG.debug('No trigger in db for %s', trigger) if raise_on_no_trigger: raise StackStormDBObjectNotFoundError('Trigger not found for %s', trigger) return None trigger_ref = trigger_db.get_reference().ref trigger_instance = TriggerInstanceDB() trigger_instance.trigger = trigger_ref trigger_instance.payload = payload trigger_instance.occurrence_time = occurrence_time trigger_instance.status = TRIGGER_INSTANCE_PENDING return TriggerInstance.add_or_update(trigger_instance)
def test_no_timestamp_doesnt_delete(self): now = date_utils.get_datetime_utc_now() instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger', payload={'hola': 'hi', 'kuraci': 'chicken'}, occurrence_time=now - timedelta(days=20), status=TRIGGER_INSTANCE_PROCESSED) TriggerInstance.add_or_update(instance_db) self.assertEqual(len(TriggerInstance.get_all()), 1) expected_msg = 'Specify a valid timestamp' self.assertRaisesRegexp(ValueError, expected_msg, purge_trigger_instances, logger=LOG, timestamp=None) self.assertEqual(len(TriggerInstance.get_all()), 1)
"trace_for_test_enforce_3.yaml", ], } FIXTURES_2 = { "rules": [ "rule1.yaml", "rule2.yaml", "rule_use_none_filter.yaml", "rule_none_no_use_none_filter.yaml", "rule_action_default_value.yaml", "rule_action_default_value_overridden.yaml", "rule_action_default_value_render_fail.yaml", ] } MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = "triggerinstance-test" MOCK_TRIGGER_INSTANCE.payload = {"t1_p": "t1_p_v"} MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_2 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_2.id = "triggerinstance-test2" MOCK_TRIGGER_INSTANCE_2.payload = {"t1_p": None} MOCK_TRIGGER_INSTANCE_2.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_3 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_3.id = "triggerinstance-test3" MOCK_TRIGGER_INSTANCE_3.payload = {"t1_p": None, "t2_p": "value2"} MOCK_TRIGGER_INSTANCE_3.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_PAYLOAD = {
def _create_save_triggerinstance(trigger): created = TriggerInstanceDB( trigger=trigger.get_reference().ref, payload={}, occurrence_time=date_utils.get_datetime_utc_now()) return TriggerInstance.add_or_update(created)
def _get_trigger_instance_db_from_file(self, file_path): data = self._meta_loader.load(file_path=file_path) instance = TriggerInstanceDB(**data) return instance
MOCK_TRIGGER = TriggerDB(pack='dummy_pack_1', name='trigger-test.name', type='system.test') MOCK_TRIGGER_INSTANCE = TriggerInstanceDB( trigger=MOCK_TRIGGER.get_reference().ref, occurrence_time=date_utils.get_datetime_utc_now(), payload={ 'p1': 'v1', 'p2': 'preYYYpost', 'bool': True, 'int': 1, 'float': 0.8, 'list': ['v1', True, 1], 'recursive_list': [{ 'field_name': "Status", 'to_value': "Approved", }, { 'field_name': "Signed off by", 'to_value': "Stanley", }], }) MOCK_ACTION = ActionDB(id=bson.ObjectId(), pack='wolfpack', name='action-test-1.name')
PACK = 'generic' FIXTURES_1 = { 'runners': ['testrunner1.yaml', 'testrunner2.yaml'], 'actions': ['action1.yaml', 'a2.yaml'], 'triggertypes': ['triggertype1.yaml'], 'triggers': ['trigger1.yaml'], 'traces': ['trace_for_test_enforce.yaml', 'trace_for_test_enforce_2.yaml', 'trace_for_test_enforce_3.yaml'] } FIXTURES_2 = { 'rules': ['rule1.yaml', 'rule2.yaml', 'rule_use_none_filter.yaml', 'rule_none_no_use_none_filter.yaml'] } MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = 'triggerinstance-test' MOCK_TRIGGER_INSTANCE.payload = {'t1_p': 't1_p_v'} MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_2 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_2.id = 'triggerinstance-test2' MOCK_TRIGGER_INSTANCE_2.payload = {'t1_p': None} MOCK_TRIGGER_INSTANCE_2.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_3 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_3.id = 'triggerinstance-test3' MOCK_TRIGGER_INSTANCE_3.payload = {'t1_p': None, 't2_p': 'value2'} MOCK_TRIGGER_INSTANCE_3.occurrence_time = date_utils.get_datetime_utc_now() MOCK_LIVEACTION = LiveActionDB()
from st2tests import DbTestCase from st2tests.fixturesloader import FixturesLoader PACK = 'generic' FIXTURES_1 = { 'runners': ['testrunner1.yaml', 'testrunner2.yaml'], 'actions': ['action1.yaml', 'a2.yaml'], 'triggertypes': ['triggertype1.yaml'], 'triggers': ['trigger1.yaml'], 'traces': ['trace_for_test_enforce.yaml'] } FIXTURES_2 = { 'rules': ['rule1.yaml', 'rule2.yaml'] } MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = 'triggerinstance-test' MOCK_TRIGGER_INSTANCE.payload = {'t1_p': 't1_p_v'} MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now() MOCK_LIVEACTION = LiveActionDB() MOCK_LIVEACTION.id = 'liveaction-test-1.id' MOCK_LIVEACTION.status = 'requested' MOCK_EXECUTION = ActionExecutionDB() MOCK_EXECUTION.id = 'exec-test-1.id' MOCK_EXECUTION.status = 'requested' class EnforceTest(DbTestCase):
from st2common.util import reference from st2common.util import date as date_utils from st2reactor.rules.enforcer import RuleEnforcer from st2tests import DbTestCase from st2tests.fixturesloader import FixturesLoader PACK = 'generic' FIXTURES_1 = { 'runners': ['testrunner1.yaml', 'testrunner2.yaml'], 'actions': ['action1.yaml', 'a2.yaml'], 'triggertypes': ['triggertype1.yaml'], 'triggers': ['trigger1.yaml'] } FIXTURES_2 = {'rules': ['rule1.yaml', 'rule2.yaml']} MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = 'triggerinstance-test' MOCK_TRIGGER_INSTANCE.payload = {'t1_p': 't1_p_v'} MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now() MOCK_LIVEACTION = LiveActionDB() MOCK_LIVEACTION.id = 'liveaction-test-1.id' MOCK_LIVEACTION.name = 'liveaction-test-1.name' MOCK_LIVEACTION.status = 'requested' class EnforceTest(DbTestCase): models = None @classmethod
def _create_save_triggerinstance(trigger): created = TriggerInstanceDB() created.trigger = trigger.get_reference().ref created.payload = {} created.occurrence_time = date_utils.get_datetime_utc_now() return TriggerInstance.add_or_update(created)
type="system.test") MOCK_TRIGGER_INSTANCE = TriggerInstanceDB( trigger=MOCK_TRIGGER.get_reference().ref, occurrence_time=date_utils.get_datetime_utc_now(), payload={ "p1": "v1", "p2": "preYYYpost", "bool": True, "int": 1, "float": 0.8, "list": ["v1", True, 1], "recursive_list": [ { "field_name": "Status", "to_value": "Approved", }, { "field_name": "Signed off by", "to_value": "Stanley", }, ], }, ) MOCK_ACTION = ActionDB(id=bson.ObjectId(),
'actions': ['action1.yaml', 'a2.yaml'], 'triggertypes': ['triggertype1.yaml'], 'triggers': ['trigger1.yaml'], 'traces': [ 'trace_for_test_enforce.yaml', 'trace_for_test_enforce_2.yaml', 'trace_for_test_enforce_3.yaml' ] } FIXTURES_2 = { 'rules': [ 'rule1.yaml', 'rule2.yaml', 'rule_use_none_filter.yaml', 'rule_none_no_use_none_filter.yaml' ] } MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = 'triggerinstance-test' MOCK_TRIGGER_INSTANCE.payload = {'t1_p': 't1_p_v'} MOCK_TRIGGER_INSTANCE.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_2 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_2.id = 'triggerinstance-test2' MOCK_TRIGGER_INSTANCE_2.payload = {'t1_p': None} MOCK_TRIGGER_INSTANCE_2.occurrence_time = date_utils.get_datetime_utc_now() MOCK_TRIGGER_INSTANCE_3 = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE_3.id = 'triggerinstance-test3' MOCK_TRIGGER_INSTANCE_3.payload = {'t1_p': None, 't2_p': 'value2'} MOCK_TRIGGER_INSTANCE_3.occurrence_time = date_utils.get_datetime_utc_now() MOCK_LIVEACTION = LiveActionDB()
from st2common.models.db.action import ActionDB from st2common.models.db.rule import RuleDB, ActionExecutionSpecDB from st2common.models.db.trigger import TriggerDB, TriggerInstanceDB from st2common.util import reference from st2common.util import date as date_utils from st2reactor.rules.filter import RuleFilter from st2tests import DbTestCase MOCK_TRIGGER = TriggerDB() MOCK_TRIGGER.id = bson.ObjectId() MOCK_TRIGGER.name = 'trigger-test.name' MOCK_TRIGGER.pack = 'dummy_pack_1' MOCK_TRIGGER.type = 'system.test' 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'
from st2common.models.db.rule import RuleDB, ActionExecutionSpecDB from st2common.models.db.trigger import TriggerDB, TriggerInstanceDB from st2common.util import reference from st2common.util import date as date_utils from st2reactor.rules.filter import RuleFilter from st2tests import DbTestCase MOCK_TRIGGER = TriggerDB(pack='dummy_pack_1', name='trigger-test.name', type='system.test') MOCK_TRIGGER_INSTANCE = TriggerInstanceDB( trigger=MOCK_TRIGGER.get_reference().ref, occurrence_time=date_utils.get_datetime_utc_now(), payload={ 'p1': 'v1', 'p2': 'preYYYpost', 'bool': True, 'int': 1, 'float': 0.8 }) MOCK_ACTION = ActionDB(id=bson.ObjectId(), pack='wolfpack', name='action-test-1.name') MOCK_RULE_1 = RuleDB( id=bson.ObjectId(), pack='wolfpack', name='some1', trigger=reference.get_str_resource_ref_from_model(MOCK_TRIGGER), criteria={},
from st2common.models.db.action import ActionDB from st2common.models.db.rule import RuleDB, ActionExecutionSpecDB from st2common.models.db.trigger import TriggerDB, TriggerInstanceDB from st2common.util import reference from st2common.util import date as date_utils from st2reactor.rules.filter import RuleFilter from st2tests import DbTestCase MOCK_TRIGGER = TriggerDB() MOCK_TRIGGER.id = bson.ObjectId() MOCK_TRIGGER.name = "trigger-test.name" MOCK_TRIGGER.pack = "dummy_pack_1" MOCK_TRIGGER.type = "system.test" 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")