def test_packing_single_line(self): expected_string = 'Hello world' cmd_type = protocol.GEARMAN_COMMAND_TEXT_COMMAND cmd_args = dict(raw_text=expected_string) packed_command = protocol.pack_text_command(cmd_type, cmd_args) self.assertEquals(packed_command, expected_string)
def test_packing_single_line(self): expected_string = 'Hello world' cmd_type = protocol.GEARMAN_COMMAND_TEXT_COMMAND cmd_args = {u"raw_text": expected_string} packed_command = protocol.pack_text_command(cmd_type, cmd_args) assert packed_command == expected_string
def _pack_command(self, cmd_type, cmd_args): """Converts a command to its raw binary format""" if cmd_type not in GEARMAN_PARAMS_FOR_COMMAND: raise ProtocolError('Unknown command: %r' % get_command_name(cmd_type)) if _DEBUG_MODE_: gearman_logger.debug('%s - Send - %s - %r', hex(id(self)), get_command_name(cmd_type), cmd_args) if cmd_type == GEARMAN_COMMAND_TEXT_COMMAND: return pack_text_command(cmd_type, cmd_args) else: # We'll be sending a response if we know we're a server side command is_response = bool(self._is_server_side) return pack_binary_command(cmd_type, cmd_args, is_response)
def _pack_command(self, cmd_type, cmd_args): """Converts a command to its raw binary format""" if cmd_type not in protocol.GEARMAN_PARAMS_FOR_COMMAND: raise ProtocolError('Unknown command: %r' % protocol.get_command_name(cmd_type)) log.msg("%s - send - %s - %r" % ( id(self), protocol.get_command_name(cmd_type), cmd_args), logging.DEBUG) if cmd_type == protocol.GEARMAN_COMMAND_TEXT_COMMAND: return protocol.pack_text_command(cmd_type, cmd_args) else: return protocol.pack_binary_command(cmd_type, cmd_args)
def test_packing_errors(self, cmd_type, cmd_args): with pytest.raises(ProtocolError): protocol.pack_text_command(cmd_type=cmd_type, cmd_args=cmd_args)