class TestCommandTranscoder(TestCase):
    def setUp(self):
        self.base_command = BaseCommand()
        self.command_transcoder = CommandTranscoder()

    def test_encode_command(self):
        self.assertDictEqual(self.base_command.as_dict(), self.command_transcoder.encode_command(self.base_command))

    def test_decode_command(self):
        dictionary = self.base_command.__dict__
        self.assertEqual(self.base_command, self.command_transcoder.decode_command(dictionary))
Ejemplo n.º 2
0
 def _send_command(self, command):
     socket = JSONSocket(
         self._server_address,
         self._server_port
     )
     try:
         socket.send_dict(
             CommandTranscoder.encode_command(
                 command
             )
         )
     except Exception:
         return False
     return True
Ejemplo n.º 3
0
 def _enqueue_command(self, command: BaseCommand):
     """
     Puts a command that should be sent to the client into
     the outgoing message queue.
     :param command: The command to enqueue
     :return: None
     """
     out_free.acquire()
     out_mutex.acquire()
     self._out_queue.append(
         CommandTranscoder.encode_command(
             command
         )
     )
     out_mutex.release()
     out_full.release()