def test_evaluate_condition_notimplemented_condition(self, mock_get_entity_value): condition = { 'reference': 'some.reference', 'condition': 'invalidcondition', 'trueval': 'some.other.reference', } with self.assertRaises(NotImplementedError): evaluate_condition({}, condition)
def test_evaluate_condition(self, mock_get_entity_value): mock_get_entity_value.return_value = 'some truthy value' entity = MagicMock() condition = { 'reference': 'some.reference', 'condition': 'isempty', 'trueval': 'some.other.reference', } res = evaluate_condition(entity, condition) mock_get_entity_value.assert_called_with(entity, ['some', 'reference']) self.assertEqual(None, res)
def test_evaluate_condition_trueval(self, mock_get_entity_value): mock_get_entity_value.return_value = '' entity = MagicMock() condition = { 'reference': 'some.reference', 'condition': 'isempty', 'trueval': 'true val' } res = evaluate_condition(entity, condition) mock_get_entity_value.assert_called_with(entity, 'true val') self.assertEqual(mock_get_entity_value.return_value, res)
def test_evaluate_condition_is_none(self, mock_get_entity_value): mock_get_entity_value.return_value = 'some truthy value' entity = MagicMock() condition = { 'reference': 'some.reference', 'condition': 'isnone', 'trueval': 'some.other.reference', } res = evaluate_condition(entity, condition) mock_get_entity_value.assert_called_with(entity, ['some', 'reference']) # Expect falseval (None) self.assertEqual(None, res) mock_get_entity_value.return_value = '' condition = { 'reference': 'some.reference', 'condition': 'isnone', 'trueval': 'some.other.reference', } res = evaluate_condition(entity, condition) # Expect falseval (None) self.assertEqual(None, res) mock_get_entity_value.side_effect = [None, 'some value'] condition = { 'reference': 'some.reference', 'condition': 'isnone', 'trueval': 'some.other.reference', } res = evaluate_condition(entity, condition) # Expect trueval self.assertEqual('some value', res)
def test_evaluate_condition_negated(self, mock_get_entity_value): mock_get_entity_value.side_effect = ['some truthy value', 'some value'] entity = MagicMock() condition = { 'reference': 'some.reference', 'condition': 'isempty', 'trueval': 'some.other.reference', 'negate': True, } res = evaluate_condition(entity, condition) mock_get_entity_value.assert_has_calls([ call(entity, ['some', 'reference']), call(entity, 'some.other.reference'), ]) self.assertEqual('some value', res)