Beispiel #1
0
 def handler_mock(pkt):
     if pkt['type'] == data_model.WORLD_MESSAGE:
         packet = Packet.from_dict(pkt)
         on_msg(packet)
     elif pkt['type'] == data_model.MESSAGE_BATCH:
         packet = Packet.from_dict(pkt)
         on_msg(packet)
     elif pkt['type'] == data_model.AGENT_ALIVE:
         raise Exception('Invalid alive packet {}'.format(pkt))
     else:
         raise Exception('Invalid Packet type {} received in {}'.format(
             pkt['type'], pkt))
Beispiel #2
0
    def test_dict_conversion(self):
        '''Ensure packets can be converted to and from a representative dict'''
        converted_packet = Packet.from_dict(self.packet_1.as_dict())
        self.assertEqual(self.packet_1.id, converted_packet.id)
        self.assertEqual(self.packet_1.type, converted_packet.type)
        self.assertEqual(self.packet_1.sender_id, converted_packet.sender_id)
        self.assertEqual(self.packet_1.receiver_id, converted_packet.receiver_id)
        self.assertEqual(self.packet_1.assignment_id, converted_packet.assignment_id)
        self.assertEqual(self.packet_1.data, converted_packet.data)
        self.assertEqual(
            self.packet_1.conversation_id, converted_packet.conversation_id
        )

        packet_dict = self.packet_1.as_dict()
        self.assertDictEqual(packet_dict, Packet.from_dict(packet_dict).as_dict())