Exemple #1
0
 def test_message_component_requires_response_as_json(self):
     message_component = MessageComponent(requires_response=True)
     self.assertDictEqual(message_component.as_json(), {
         'type': '__base',
         'requires_response': True,
         'data': {}
     })
Exemple #2
0
 def test_message_component_from_json_unknown_type(self):
     json_in = {
         'type': 'invalid',
         'requires_response': True,
         'data': {
             'a': 42
         }
     }
     self.assertIsInstance(MessageComponent.from_json(json_in),
                           MessageComponent)
Exemple #3
0
    def test_message_component_from_json(self):
        class MessageType1(MessageComponent):
            def __init__(self, a):
                super(MessageType1, self).__init__()
                self.a = a

            @staticmethod
            def from_component_json(json_in):
                return MessageType1(json_in['a'])

        json_in = {'type': MessageType1.message_type, 'requires_response': True, 'data': {'a': 42}}
        generated = MessageComponent.from_json(json_in)
        self.assertIsInstance(generated, MessageType1)
        self.assertEqual(generated.a, 42)
Exemple #4
0
    def test_message_component_from_json(self):
        class MessageType1(MessageComponent):
            def __init__(self, a):
                super(MessageType1, self).__init__()
                self.a = a

            @staticmethod
            def from_component_json(json_in):
                return MessageType1(json_in['a'])

        json_in = {
            'type': MessageType1.message_type,
            'requires_response': True,
            'data': {
                'a': 42
            }
        }
        generated = MessageComponent.from_json(json_in)
        self.assertIsInstance(generated, MessageType1)
        self.assertEqual(generated.a, 42)
Exemple #5
0
 def test_message_component_from_component_json(self):
     self.assertIsInstance(MessageComponent.from_component_json({}),
                           MessageComponent)
     self.assertIsInstance(MessageComponent.from_component_json({'a': 'b'}),
                           MessageComponent)
Exemple #6
0
 def test_message_component_get_component_json(self):
     message_component = MessageComponent()
     self.assertDictEqual(message_component.get_component_json(), {})
Exemple #7
0
 def test_message_component_init_requires_response(self):
     message_component = MessageComponent(requires_response=True)
     self.assertTrue(message_component.requires_response)
Exemple #8
0
 def test_message_component_init(self):
     message_component = MessageComponent()
     self.assertEqual(message_component.message_type, '__base')
     self.assertFalse(message_component.requires_response)
Exemple #9
0
 def test_message_component_from_json_unknown_type(self):
     json_in = {'type': 'invalid', 'requires_response': True, 'data': {'a': 42}}
     self.assertIsInstance(MessageComponent.from_json(json_in), MessageComponent)
Exemple #10
0
 def test_message_component_from_component_json(self):
     self.assertIsInstance(MessageComponent.from_component_json({}), MessageComponent)
     self.assertIsInstance(MessageComponent.from_component_json({'a': 'b'}), MessageComponent)
Exemple #11
0
 def test_message_component_requires_response_as_json(self):
     message_component = MessageComponent(requires_response=True)
     self.assertDictEqual(message_component.as_json(), {'type': '__base', 'requires_response': True, 'data': {}})
Exemple #12
0
 def test_message_component_get_component_json(self):
     message_component = MessageComponent()
     self.assertDictEqual(message_component.get_component_json(), {})