Esempio n. 1
0
 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'}])
Esempio n. 2
0
 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"}],
     )
Esempio n. 3
0
 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'}])
Esempio n. 4
0
 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"}],
     )
Esempio n. 5
0
 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"}],
     )
Esempio n. 6
0
 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"}],
     )
Esempio n. 7
0
 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'}])
Esempio n. 8
0
 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'
                      }])
Esempio n. 9
0
 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'}])
Esempio n. 10
0
 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'
                      }])
Esempio n. 11
0
 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'
                      }])
Esempio n. 12
0
 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'}])
Esempio n. 13
0
 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'
         }])
Esempio n. 14
0
 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"},
         ],
     )
Esempio n. 15
0
 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'
         }])
Esempio n. 16
0
 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",
             }
         ],
     )
Esempio n. 17
0
 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'}])
Esempio n. 18
0
 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'
                      }])
Esempio n. 19
0
 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])
Esempio n. 20
0
 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])
Esempio n. 21
0
 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])
Esempio n. 22
0
 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])
Esempio n. 23
0
 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])
Esempio n. 24
0
 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])
Esempio n. 25
0
 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])
Esempio n. 26
0
 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])