def test_message_is_changed(self): """ Event's message is changed with msg type if found. otter_msg_type is added """ e = {'message': ('delete-server',), 'a': 'b'} self.assertEqual( get_validated_event(e), [{'message': ('Deleting {server_id} server',), 'a': 'b', 'otter_msg_type': 'delete-server'}])
def test_error_why_is_changed(self): """ Error-based event's why is changed if found in msg_types. otter_msg_type is added """ e = {"isError": True, "why": "delete-server", "a": "b"} self.assertEqual( get_validated_event(e), [{"why": "Deleting {server_id} server", "isError": True, "a": "b", "otter_msg_type": "delete-server"}], )
def test_error_no_why_but_message(self): """ When error-based event does not have "why", then its message is tried """ e = {'isError': True, 'a': 'b', "message": ('delete-server',)} self.assertEqual( get_validated_event(e), [{'message': ('Deleting {server_id} server',), 'isError': True, 'why': 'Deleting {server_id} server', 'a': 'b', 'otter_msg_type': 'delete-server'}])
def test_message_is_changed(self): """ Event's message is changed with msg type if found. otter_msg_type is added """ e = {"message": ("delete-server",), "a": "b"} self.assertEqual( get_validated_event(e), [{"message": ("Deleting {server_id} server",), "a": "b", "otter_msg_type": "delete-server"}], )
def test_callable_spec(self): """ Spec values can be callable, in which case they will be called with the event dict, and their return value will be used as the new `message`. """ e = {"message": ("foo-bar",), "ab": "cd"} self.assertEqual( get_validated_event(e, specs={"foo-bar": lambda e: [(e, e["ab"])]}), [{"message": ("cd",), "otter_msg_type": "foo-bar", "ab": "cd"}], )
def test_callable_spec_error(self): """ Spec values will be called for errors as well, and their return will be used as the new value for `why`. """ e = {"isError": True, "why": "foo-bar", "ab": "cd"} self.assertEqual( get_validated_event(e, specs={"foo-bar": lambda e: [(e, e["ab"])]}), [{"why": "cd", "isError": True, "otter_msg_type": "foo-bar", "ab": "cd"}], )
def test_error_why_is_changed(self): """ Error-based event's why is changed if found in msg_types. otter_msg_type is added """ e = {'isError': True, 'why': 'delete-server', 'a': 'b'} self.assertEqual( get_validated_event(e), [{'why': 'Deleting {server_id} server', 'isError': True, 'a': 'b', 'otter_msg_type': 'delete-server'}])
def test_message_is_changed(self): """ Event's message is changed with msg type if found. otter_msg_type is added """ e = {'message': ('delete-server', ), 'a': 'b'} self.assertEqual(get_validated_event(e), [{ 'message': ('Deleting {server_id} server', ), 'a': 'b', 'otter_msg_type': 'delete-server' }])
def test_callable_spec(self): """ Spec values can be callable, in which case they will be called with the event dict, and their return value will be used as the new `message`. """ e = {"message": ('foo-bar',), 'ab': 'cd'} self.assertEqual( get_validated_event(e, specs={'foo-bar': lambda e: [(e, e['ab'])]}), [{'message': ('cd',), 'otter_msg_type': 'foo-bar', 'ab': 'cd'}])
def test_error_why_is_changed(self): """ Error-based event's why is changed if found in msg_types. otter_msg_type is added """ e = {'isError': True, 'why': 'delete-server', 'a': 'b'} self.assertEqual(get_validated_event(e), [{ 'why': 'Deleting {server_id} server', 'isError': True, 'a': 'b', 'otter_msg_type': 'delete-server' }])
def test_error_no_why_but_message(self): """ When error-based event does not have "why", then its message is tried """ e = {'isError': True, 'a': 'b', "message": ('delete-server', )} self.assertEqual(get_validated_event(e), [{ 'message': ('Deleting {server_id} server', ), 'isError': True, 'why': 'Deleting {server_id} server', 'a': 'b', 'otter_msg_type': 'delete-server' }])
def test_callable_spec_error(self): """ Spec values will be called for errors as well, and their return will be used as the new value for `why`. """ e = {'isError': True, 'why': 'foo-bar', 'ab': 'cd'} self.assertEqual( get_validated_event(e, specs={'foo-bar': lambda e: [(e, e['ab'])]}), [{'why': 'cd', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd'}])
def test_callable_spec(self): """ Spec values can be callable, in which case they will be called with the event dict, and their return value will be used as the new `message`. """ e = {"message": ('foo-bar', ), 'ab': 'cd'} self.assertEqual( get_validated_event(e, specs={'foo-bar': lambda e: [(e, e['ab'])]}), [{ 'message': ('cd', ), 'otter_msg_type': 'foo-bar', 'ab': 'cd' }])
def test_callable_spec_split_events(self): """ Event dictionaries returned will have a field tracking how many events the original event was split into. """ e = {"isError": True, "why": "foo-bar", "ab": "cd"} specs = {"foo-bar": lambda e: [(e, e["ab"]), (e.copy(), "another")]} self.assertEqual( get_validated_event(e, specs), [ {"why": "cd", "isError": True, "otter_msg_type": "foo-bar", "ab": "cd", "split_message": "1 of 2"}, {"why": "another", "isError": True, "otter_msg_type": "foo-bar", "ab": "cd", "split_message": "2 of 2"}, ], )
def test_callable_spec_error(self): """ Spec values will be called for errors as well, and their return will be used as the new value for `why`. """ e = {'isError': True, 'why': 'foo-bar', 'ab': 'cd'} self.assertEqual( get_validated_event(e, specs={'foo-bar': lambda e: [(e, e['ab'])]}), [{ 'why': 'cd', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd' }])
def test_error_no_why_but_message(self): """ When error-based event does not have "why", then its message is tried """ e = {"isError": True, "a": "b", "message": ("delete-server",)} self.assertEqual( get_validated_event(e), [ { "message": ("Deleting {server_id} server",), "isError": True, "why": "Deleting {server_id} server", "a": "b", "otter_msg_type": "delete-server", } ], )
def test_callable_spec_split_events(self): """ Event dictionaries returned will have a field tracking how many events the original event was split into. """ e = {'isError': True, 'why': 'foo-bar', 'ab': 'cd'} specs = {'foo-bar': lambda e: [(e, e['ab']), (e.copy(), 'another')]} self.assertEqual( get_validated_event(e, specs), [{'why': 'cd', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd', 'split_message': '1 of 2'}, {'why': 'another', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd', 'split_message': '2 of 2'}])
def test_callable_spec_split_events(self): """ Event dictionaries returned will have a field tracking how many events the original event was split into. """ e = {'isError': True, 'why': 'foo-bar', 'ab': 'cd'} specs = {'foo-bar': lambda e: [(e, e['ab']), (e.copy(), 'another')]} self.assertEqual(get_validated_event(e, specs), [{ 'why': 'cd', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd', 'split_message': '1 of 2' }, { 'why': 'another', 'isError': True, 'otter_msg_type': 'foo-bar', 'ab': 'cd', 'split_message': '2 of 2' }])
def test_error_not_found(self): """ Nothing is changed if Error-based event is not found in msg_types """ e = {"isError": True, "why": "unknown", "a": "b"} self.assertEqual(get_validated_event(e), [e])
def test_error_not_found(self): """ Nothing is changed if Error-based event is not found in msg_types """ e = {'isError': True, 'why': 'unknown', 'a': 'b'} self.assertEqual(get_validated_event(e), [e])
def test_error_no_why_in_event(self): """ If error-based event's does not have "why", then it is not changed """ e = {'isError': True, 'a': 'b'} self.assertEqual(get_validated_event(e), [e])
def test_msg_not_found(self): """ Event is not changed if msg_type is not found """ e = {'message': ('unknown', ), 'a': 'b'} self.assertEqual(get_validated_event(e), [e])
def test_msg_not_found(self): """ Event is not changed if msg_type is not found """ e = {"message": ("unknown",), "a": "b"} self.assertEqual(get_validated_event(e), [e])
def test_error_no_why_in_event(self): """ If error-based event's does not have "why", then it is not changed """ e = {"isError": True, "a": "b"} self.assertEqual(get_validated_event(e), [e])
def test_msg_not_found(self): """ Event is not changed if msg_type is not found """ e = {'message': ('unknown',), 'a': 'b'} self.assertEqual(get_validated_event(e), [e])