Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    ],
}
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 = {
    "k1": "v1",
Beispiel #4
0
    '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()
MOCK_LIVEACTION.id = 'liveaction-test-1.id'
Beispiel #5
0
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()
Beispiel #6
0
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 setUpClass(cls):
Beispiel #7
0
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()
MOCK_LIVEACTION.id = 'liveaction-test-1.id'
Beispiel #8
0
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):

    models = None
Beispiel #9
0
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")