def test_init_values(self): getcommand = GetCommand(path='/a/path/here', offset=5, length=10) et = getcommand.get_etree() self.assertEqual(et.tag, 'get_file') self.assertEqual('/a/path/here', et.get('path')) self.assertEqual('5', et.get('offset', None)) self.assertEqual('10', et.get('length', None)) self.assertEqual(0, len(list(et))) self.assertEqual(None, et.text)
def test_send_command_block_mixed_commands(self): command_block = FileSystemServiceCommandBlock() command_block.add_command(DeleteCommand(path='/a/path/1.txt')) command_block.add_command(GetCommand(path='/a/path/2.txt')) data_string = base64.b64encode(six.b('testing string')).decode('ascii') fsr = FileSystemResponse() fsr.add_device_block(self.dev1_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + GET_FILE_BLOCK.format(data=data_string))) fsr.add_device_block(self.dev2_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + GET_FILE_BLOCK.format(data=data_string))) self.prep_sci_response(fsr) out_dict = self.fss_api.send_command_block(self.target, command_block) expected_dict = { self.dev1_id: [None, six.b('testing string')], self.dev2_id: [None, six.b('testing string')], } self.assertDictEqual(expected_dict, out_dict)
def test_send_command_block_errors(self): command_block = FileSystemServiceCommandBlock() command_block.add_command(DeleteCommand(path='/a/path/1.txt')) command_block.add_command(GetCommand(path='/a/path/2.txt')) fsr = FileSystemResponse() fsr.add_device_block(self.dev1_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + ERROR_BLOCK.format(command='get_file', errno=1, errtext="an error message"))) fsr.add_device_block(self.dev2_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + ERROR_BLOCK.format(command='get_file', errno=1, errtext="an error message"))) self.prep_sci_response(fsr) out_dict = self.fss_api.send_command_block(self.target, command_block) # Check empty DeleteCommand responses self.assertIsNone(out_dict[self.dev1_id][0]) self.assertIsNone(out_dict[self.dev2_id][0]) # Check error info values self.assertEqual(1, out_dict[self.dev1_id][1].errno) self.assertEqual(1, out_dict[self.dev2_id][1].errno) self.assertEqual("an error message", out_dict[self.dev1_id][1].message) self.assertEqual("an error message", out_dict[self.dev2_id][1].message)
def test_parse_error(self): errinfo = GetCommand.parse_response( ET.fromstring(ERROR_BLOCK.format(command='get_file', errno=1, errtext="error text"))) self.assertEqual(errinfo.errno, 1) self.assertEqual(errinfo.message, "error text")
def test_parse(self): data_str = base64.b64encode(six.b("File Data")).decode('ascii') data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data=data_str))) self.assertEqual(six.b("File Data"), data)
def test_parse_empty(self): data = GetCommand.parse_response(ET.fromstring(GET_FILE_BLOCK.format(data=''))) self.assertEqual(six.b(""), data)