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))
 def _respond_to_command(
         self,
         command: BaseCommand,
         result: Dict[str, object]=None,
         acknowledged: bool=True,
         timeout: int=2000
 ) -> None:
     """
     Sends the altered command object of a previously
     received command back to the client.
     The command object that is sent back to the client
     should always be the same object that had been received
     from the client.
     the results of the command execution are passed back to client
     inside the command.result dictionary. If this dictionary
     isn't present in the passed command, it will be created.
     All commands that're passed back to the client and that
     have been handled by the server contain an 'acknowledged'
     field inside results. If this is set to true, the command
     has been executed and the networking protocol hasn't been
     breached.
     :param command: The command object that is sent back
     to the client
     :param result: The result dictionary to be attached to
     the command before it's sent back
     :param acknowledged: Whether the command has been
     acknowledged by the server
     :param timeout: The timeout after which the send operation
     will fail if the client hasn't connected yet
     :return: None
     """
     if result is None:
         result = dict({})
     command.result = result
     command.result["acknowledged"] = acknowledged
     self._server.respond(command)
 def encode_command(command: BaseCommand):
     return command.as_dict()
 def setUp(self):
     self.base_command = BaseCommand()
     self.command_transcoder = CommandTranscoder()