def test_check_incorrect_method_name(self):
     condition = {'name': 'food',
                  'operator': 'equal_to',
                  'value': 'm'}
     err_string = 'Variable food is not defined in class SomeVariables'
     with self.assertRaisesRegexp(AssertionError, err_string):
         check_condition(condition, SomeVariables())
 def test_check_incorrect_method_name(self):
     condition = {'name': 'food',
                  'operator': 'equal_to',
                  'value': 'm'}
     err_string = 'Variable food is not defined in class SomeVariables'
     with self.assertRaisesRegexp(AssertionError, err_string):
         check_condition(condition, SomeVariables())
 def test_check_incorrect_operator_name(self):
     condition = {
         'name': 'foo',
         'operator': 'equal_tooooze',
         'value': 'foo'
     }
     with self.assertRaises(AssertionError):
         check_condition(condition, SomeVariables())
 def test_check_missing_params(self):
     condition = {'name': 'x_plus_one',
                  'operator': 'equal_to',
                  'value': 10,
                  'params': {}}
     err_string = 'Missing parameters x for variable x_plus_one'
     with self.assertRaisesRegexp(AssertionError, err_string):
         check_condition(condition, SomeVariables())
 def test_check_invalid_params(self):
     condition = {'name': 'x_plus_one',
                  'operator': 'equal_to',
                  'value': 10,
                  'params': {'x': 9, 'y': 9}}
     err_string = 'Invalid parameters y for variable x_plus_one'
     with self.assertRaisesRegexp(AssertionError, err_string):
         check_condition(condition, SomeVariables())
    def test_check_missing_params(self):
        condition = {
            'name': 'x_plus_one',
            'operator': 'equal_to',
            'value': 10,
            'params': {}
        }

        rule = {'conditions': condition}

        err_string = 'Missing parameters x for variable x_plus_one'

        with self.assertRaisesRegexp(AssertionError, err_string):
            check_condition(condition, SomeVariables(), rule)
 def test_check_numeric_rule_works_with_tuples(self):
     condition = {
         'name': 'returns_tuple',
         'operator': 'equal_to',
         'value': 10
     }
     self.assertTrue(check_condition(condition, SomeVariables()))
    def test_false_boolean_variable(self):
        condition = {'name': 'true_bool', 'operator': 'is_false', 'value': ''}

        rule = {'conditions': condition}

        condition_result = check_condition(condition, SomeVariables(), rule)
        self.assertFalse(condition_result.result)
    def test_check_invalid_params(self):
        condition = {
            'name': 'x_plus_one',
            'operator': 'equal_to',
            'value': 10,
            'params': {'x': 9, 'y': 9}
        }

        rule = {
            'conditions': condition
        }

        err_string = 'Invalid parameters y for variable x_plus_one'

        with self.assertRaisesRegex(AssertionError, err_string):
            check_condition(condition, SomeVariables(), rule)
    def test_check_true_condition_happy_path(self):
        condition = {'name': 'foo', 'operator': 'contains', 'value': 'o'}

        rule = {'conditions': condition}

        condition_result = check_condition(condition, SomeVariables(), rule)
        self.assertTrue(condition_result.result)
 def test_check_false_condition_happy_path_with_context(self):
     condition = {
         'name': 'series_of_values_indexed_by_minute',
         'operator': 'equal_to',
         'value': 1,
         'context': 10
     }
     self.assertFalse(check_condition(condition, SomeVariables()))
 def test_false_boolean_variable(self):
     condition = {
         'name': 'true_bool',
         'operator': 'is_false',
         'value': ''
     }
     res = check_condition(condition, SomeVariables())
     self.assertFalse(res)
 def test_false_boolean_variable(self):
     condition = {
         'name': 'true_bool',
         'operator': 'is_false',
         'value': ''
     }
     res = check_condition(condition, SomeVariables())
     self.assertFalse(res)
    def test_string_variable_with_options_with_wrong_value(self):
        condition = {
            'name': 'string_variable_with_options',
            'operator': 'equal_to',
            'value': 'foo',
        }

        rule = {'conditions': condition}

        condition_result = check_condition(condition, SomeVariables(), rule)
        self.assertTrue(condition_result)
    def test_variable_received_rules(self):
        condition = {
            'name': 'rule_received',
            'operator': 'is_true',
            'value': 'true',
        }

        rule = {'conditions': condition}

        condition_result = check_condition(condition, SomeVariables(), rule)
        self.assertTrue(condition_result)
    def test_numeric_variable_with_params(self):
        condition = {
            'name': 'x_plus_one',
            'operator': 'equal_to',
            'value': 10,
            'params': {
                'x': 9
            }
        }

        rule = {'conditions': condition}

        condition_result = check_condition(condition, SomeVariables(), rule)

        self.assertTrue(condition_result.result)
    def test_check_condition_no_override(self, *args):
        condition = {
            'name': 'name_x',
            'operator': 'operator_x',
            'value': 'value_x'
        }
        variables = BaseVariables()

        result, overrides = engine.check_condition(condition, variables)
        self.assertEqual(
            engine._get_variable_value_and_actions_params.call_count, 1)
        self.assertEqual(engine._do_operator_comparison.call_count, 1)
        engine._get_variable_value_and_actions_params.assert_called_with(
            variables, 'name_x', OVERRIDE_NONE)
        engine._do_operator_comparison.assert_called_with(
            FAKE_OPERATOR, 'operator_x', 'value_x')
        self.assertTrue(result)
        self.assertDictEqual(overrides, OVERRIDE_A1)
 def test_check_false_condition_happy_path(self):
     condition = {'name': 'foo',
                  'operator': 'contains',
                  'value': 'm'}
     self.assertFalse(check_condition(condition, SomeVariables()))
Exemple #19
0
 def test_check_false_condition_happy_path(self):
     condition = {'name': 'foo', 'operator': 'contains', 'value': 'm'}
     result, overrides = check_condition(condition, SomeVariables())
     self.assertFalse(result)
     self.assertDictEqual(overrides, {})
 def test_numeric_variable_with_params(self):
     condition = {'name': 'x_plus_one',
                  'operator': 'equal_to',
                  'value': 10,
                  'params': {'x': 9}}
     self.assertTrue(check_condition(condition, SomeVariables()))
 def test_check_incorrect_operator_name(self):
     condition = {'name': 'foo',
                  'operator': 'equal_tooooze',
                  'value': 'foo'}
     with self.assertRaises(AssertionError):
         check_condition(condition, SomeVariables())
 def test_check_true_condition_happy_path(self):
     condition = {'name': 'foo', 'operator': 'contains', 'value': 'o'}
     self.assertTrue(check_condition(condition, SomeVariables()))