Esempio n. 1
0
    def test_check_all_conditions_with_all_false(self, *args):
        conditions = {'all': [{'thing1': ''}, {'thing2': ''}]}
        variables = BaseVariables()

        result = engine.check_conditions_recursively(conditions, variables)
        self.assertEqual(result, False)
        engine.check_condition.assert_called_once_with({'thing1': ''},
                                                       variables)
Esempio n. 2
0
    def test_check_all_conditions_with_all_true(self, *args):
        conditions = {'all': [{'thing1': ''}, {'thing2': ''}]}
        variables = BaseVariables()

        result = engine.check_conditions_recursively(conditions, variables)
        self.assertEqual(result, True)
        # assert call count and most recent call are as expected
        self.assertEqual(engine.check_condition.call_count, 2)
        engine.check_condition.assert_called_with({'thing2': ''}, variables)
Esempio n. 3
0
    def test_nested_all_and_any(self, *args):
        conditions = {
            'all': [{
                'any': [{
                    'name': 1
                }, {
                    'name': 2
                }]
            }, {
                'name': 3
            }]
        }
        bv = BaseVariables()

        def side_effect(condition, _):
            return condition['name'] in [2, 3]

        engine.check_condition.side_effect = side_effect

        engine.check_conditions_recursively(conditions, bv)
        self.assertEqual(engine.check_condition.call_count, 3)
        engine.check_condition.assert_any_call({'name': 1}, bv)
        engine.check_condition.assert_any_call({'name': 2}, bv)
        engine.check_condition.assert_any_call({'name': 3}, bv)
Esempio n. 4
0
 def test_check_all_and_any_together(self):
     conditions = {'any': [], 'all': []}
     variables = BaseVariables()
     with self.assertRaises(AssertionError):
         engine.check_conditions_recursively(conditions, variables)
Esempio n. 5
0
 def test_check_any_condition_with_no_items_fails(self):
     with self.assertRaises(AssertionError):
         engine.check_conditions_recursively({'any': []}, BaseVariables())