示例#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': {}
     })
示例#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)
示例#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)
示例#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)
示例#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)
示例#6
0
 def test_message_component_get_component_json(self):
     message_component = MessageComponent()
     self.assertDictEqual(message_component.get_component_json(), {})
示例#7
0
 def test_message_component_init_requires_response(self):
     message_component = MessageComponent(requires_response=True)
     self.assertTrue(message_component.requires_response)
示例#8
0
 def test_message_component_init(self):
     message_component = MessageComponent()
     self.assertEqual(message_component.message_type, '__base')
     self.assertFalse(message_component.requires_response)
示例#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)
示例#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)
示例#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': {}})
示例#12
0
 def test_message_component_get_component_json(self):
     message_component = MessageComponent()
     self.assertDictEqual(message_component.get_component_json(), {})