예제 #1
0
def test_validate_rule_data_nested_success():
    valid_rule = {
        'conditions': {
            'any': [{
                'name': 'bool_variable',
                'operator': 'is_false',
                'value': ''
            }, {
                "all": [
                    {
                        'name': 'str_variable',
                        'operator': 'contains',
                        'value': 'test'
                    },
                    {
                        'name': 'select_multiple_variable',
                        'operator': 'contains_all',
                        'value': [1, 2, 3]
                    },
                ]
            }]
        },
        'actions': [{
            'name': 'example_action',
            'params': {
                'param': 1
            }
        }]
    }
    utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                             valid_rule)
예제 #2
0
def test_validate_rule_contions_is_not_a_dictionary():
    invalid_rule = {
        'conditions': [],
        'actions': {}
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions, invalid_rule)
예제 #3
0
def test_validate_rule_data_unknown_action():
    invalid_rule = {
        'conditions': {},
        'actions': [{
            'name': 'unknown',
            'params': {}
        }]
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #4
0
def test_validate_rule_data_missing_action_name():
    invalid_rule = {
        'conditions': {},
        'actions': [
            {
                'params': {}
            }
        ]
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions, invalid_rule)
예제 #5
0
def test_validate_rule_data_bool_value_ignored():
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'bool_variable',
                'operator': 'is_true',
                'value': 'any value here'
            }]
        },
        'actions': []
    }
    utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                             invalid_rule)
예제 #6
0
def test_validate_rule_data_missing_condition_operator():
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'bool_variable',
                'value': ''
            }]
        },
        'actions': []
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #7
0
def test_validate_rule_data_success():
    valid_rule = {
        'conditions': {
            'all': [
                {
                    'name': 'bool_variable',
                    'operator': 'is_false',
                    'value': ''
                },
                {
                    'name': 'str_variable',
                    'operator': 'contains',
                    'value': 'test'
                },
                {
                    'name': 'select_multiple_variable',
                    'operator': 'contains_all',
                    'value': [1, 2, 3]
                },
                {
                    'name': 'numeric_variable',
                    'operator': 'equal_to',
                    'value': 1
                },
                {
                    'name': 'datetime_variable',
                    'operator': 'equal_to',
                    'value': '2016-01-01'
                },
                {
                    'name': 'time_variable',
                    'operator': 'equal_to',
                    'value': '10:00:00'
                },
                {
                    'name': 'select_variable',
                    'operator': 'contains',
                    'value': [1]
                }
            ]
        },
        'actions': [
            {
                'name': 'example_action',
                'params': {
                    'param': 1
                }
            }
        ]
    }
    utils.validate_rule_data(variables.TestVariables, actions.TestActions, valid_rule)
예제 #8
0
def test_validate_rule_data_bad_condition_value():
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'string_variable',
                'operator': 'equal_to',
                'value': 123
            }]
        },
        'actions': []
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #9
0
def test_validate_rule_data_unknown_condition_name():
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'unknown',
                'operator': 'unknown',
                'value': 'unknown'
            }]
        },
        'actions': []
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #10
0
def test_validate_rule_actions_is_not_a_list():
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'bool_variable',
                'operator': 'is_false',
                'value': ''
            }]
        },
        'actions': {}
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #11
0
def test_validate_rule_multiple_special_keys_in_condition():
    """ A rule cannot contain more than one 'any' or 'all' keys """
    invalid_rule = {
        'conditions': {
            'any': [{
                'name': 'bool_variable',
                'operator': 'is_false',
                'value': ''
            }],
            'all': [{
                'name': 'bool_variable',
                'operator': 'is_false',
                'value': ''
            }]
        },
        'actions': []
    }
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #12
0
def test_validate_rule_data_no_actions():
    invalid_rule = {'conditions': {}}
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 invalid_rule)
예제 #13
0
def test_validate_rule_data_empty_dict():
    with pytest.raises(AssertionError):
        utils.validate_rule_data(variables.TestVariables, actions.TestActions,
                                 {})
예제 #14
0
def test_validate_rule_data_no_conditions():
    invalid_rule = {
        'actions': []
    }

    utils.validate_rule_data(variables.TestVariables, actions.TestActions, invalid_rule)