def test_case3(self):
        """
        cond1: true and cond2: true => [cond1, cond2]
        """
        conditions = {
            'all': [{
                'name': 'true_variable',
                'operator': 'is_true',
                'value': ''
            }, {
                'name': 'true_variable',
                'operator': 'is_true',
                'value': ''
            }]
        }
        variables = TrueVariables()
        rule = {'conditions': conditions, 'actions': []}

        result = engine.check_conditions_recursively(conditions, variables,
                                                     rule)
        self.assertEqual(result, (True, [
            ConditionResult(result=True,
                            name='true_variable',
                            operator='is_true',
                            value='',
                            parameters={}),
            ConditionResult(result=True,
                            name='true_variable',
                            operator='is_true',
                            value='',
                            parameters={}),
        ]))
Пример #2
0
def check_condition(condition, defined_variables, rule):
    """
    Checks a single rule condition - the condition will be made up of
    variables, values, and the comparison operator. The defined_variables
    object must have a variable defined for any variables in this condition.

    :param condition:
    :param defined_variables:
    :param rule:
    :return: business_rules.models.ConditionResult

        .. code-block::
        (
            result of condition: bool,
            condition name: str,
            condition operator: str,
            condition value: ?,
            condition params: {}
        )
    """
    name, op, value = condition['name'], condition['operator'], condition['value']
    params = condition.get('params', {})
    operator_type = _get_variable_value(defined_variables, name, params, rule)
    return ConditionResult(result=_do_operator_comparison(operator_type, op, value), name=name, operator=op,
                           value=value, parameters=params)
    def test_case10(self):
        """
        cond1: true or cond2: false => [cond1]
        """
        conditions = {
            'any': [
                {
                    'name': 'true_variable',
                    'operator': 'is_true',
                    'value': '1'
                },
                {
                    'name': 'true_variable',
                    'operator': 'is_false',
                    'value': '2'
                },
            ]
        }
        variables = TrueVariables()
        rule = {'conditions': conditions, 'actions': []}

        result = engine.check_conditions_recursively(conditions, variables,
                                                     rule)
        self.assertEqual(result, (True, [
            ConditionResult(result=True,
                            name='true_variable',
                            operator='is_true',
                            value='1',
                            parameters={}),
        ]))
Пример #4
0
 def side_effect(condition, _, rule):
     return ConditionResult(result=condition['name'] in [2, 3], name=condition['name'], operator='', value='',
                            parameters='')