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': {} })
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)
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)
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)
def test_message_component_from_component_json(self): self.assertIsInstance(MessageComponent.from_component_json({}), MessageComponent) self.assertIsInstance(MessageComponent.from_component_json({'a': 'b'}), MessageComponent)
def test_message_component_get_component_json(self): message_component = MessageComponent() self.assertDictEqual(message_component.get_component_json(), {})
def test_message_component_init_requires_response(self): message_component = MessageComponent(requires_response=True) self.assertTrue(message_component.requires_response)
def test_message_component_init(self): message_component = MessageComponent() self.assertEqual(message_component.message_type, '__base') self.assertFalse(message_component.requires_response)
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)
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': {}})