Exemple #1
0
def test_create_rule():
    data = {'ordinal': "0", 'actions': [], 'conditions': []}

    rule = Rule(name="rule_0", partition="Test", **data)

    assert rule.name == "rule_0"
    assert rule.partition == "Test"
    assert len(rule.data['conditions']) == 0
    assert len(rule.data['actions']) == 0

    data['conditions'].append(condition_0)
    data['actions'].append(action_0)

    rule = Rule(name="rule_1", partition="Test", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 1

    data['conditions'] = [condition_2]
    data['actions'] = [action_0]

    rule = Rule(name="rule_1", partition="Test", **data)
    assert len(rule.data['conditions']) == 0
    assert len(rule.data['actions']) == 1

    data['conditions'].append(condition_0)
    rule = Rule(name="rule_1", partition="Test", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 1

    data['conditions'] = [condition_0]
    data['actions'] = [action_2]

    rule = Rule(name="rule_1", partition="Test", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 0
Exemple #2
0
def rule_1():
    data = {'ordinal': "1",
            'actions': [],
            'conditions': []}
    data['conditions'].append(condition_1)
    data['actions'].append(action_1)
    return Rule(name="rule_1",  **data)
Exemple #3
0
def rule_0_clone():
    data = {'ordinal': "0",
            'actions': [],
            'conditions': []}
    data['conditions'].append(condition_0)
    data['actions'].append(action_0)
    return Rule(name="rule_0", **data)
Exemple #4
0
def test_create_rule():
    data = {
        'ordinal': "0",
        'actions': [],
        'conditions': [],
        'description': 'This is a rule description'
    }

    rule = Rule(name="rule_0", **data)

    assert rule.name == "rule_0"
    assert len(rule.data['conditions']) == 0
    assert len(rule.data['actions']) == 0
    assert rule.data['description'] == 'This is a rule description'

    data['conditions'].append(condition_0)
    data['actions'].append(action_0)

    rule = Rule(name="rule_1", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 1

    data['conditions'] = [condition_2]
    data['actions'] = [action_0]

    rule = Rule(name="rule_1", **data)
    assert len(rule.data['conditions']) == 0
    assert len(rule.data['actions']) == 1

    data['conditions'].append(condition_0)
    rule = Rule(name="rule_1", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 1

    data['conditions'] = [condition_0]
    data['actions'] = [action_2]

    rule = Rule(name="rule_1", **data)
    assert len(rule.data['conditions']) == 1
    assert len(rule.data['actions']) == 0
Exemple #5
0
def rule_no_conditions():
    data = {'ordinal': "0", 'actions': [], 'conditions': []}
    data['actions'].append(action_1)
    return Rule(name="rule_1", partition="Test", **data)