def test_init(self): delcommand = DeleteCommand(path='/a/path/here') et = delcommand.get_etree() self.assertEqual(et.tag, 'rm') self.assertEqual('/a/path/here', et.get('path')) self.assertEqual(0, len(list(et))) self.assertEqual(None, et.text)
def test_add_command(self): command_block = FileSystemServiceCommandBlock() command_block.add_command(DeleteCommand(path='/a/path')) et = command_block.get_etree() self.assertEqual(et.tag, 'commands') self.assertEqual(1, len(list(et))) self.assertEqual(0, len(et.keys())) self.assertIsNotNone(et.find('./{}'.format(DeleteCommand.command_name)))
def test_send_command_block_all_ok(self): command_block = FileSystemServiceCommandBlock() command_block.add_command(DeleteCommand(path='/a/path/1.txt')) command_block.add_command(DeleteCommand(path='/a/path/2.txt')) fsr = FileSystemResponse() fsr.add_device_block(self.dev1_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + GENERIC_COMMAND_BLOCK.format(command='rm'))) fsr.add_device_block(self.dev2_id, (GENERIC_COMMAND_BLOCK.format(command='rm') + GENERIC_COMMAND_BLOCK.format(command='rm'))) self.prep_sci_response(fsr) out_dict = self.fss_api.send_command_block(self.target, command_block) # Should just be Nones because they are delete commands with no errors expected_dict = { self.dev1_id: [None, None], self.dev2_id: [None, None], } self.assertDictEqual(expected_dict, out_dict)
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_get_command_string(self): command_block = FileSystemServiceCommandBlock() self.assertEqual(six.b('<commands />'), command_block.get_command_string()) command_block.add_command(DeleteCommand(path='/a/path')) self.assertEqual(six.b('<commands><rm path="/a/path" /></commands>'), command_block.get_command_string())
def test_parse_error(self): errinfo = DeleteCommand.parse_response( ET.fromstring(ERROR_BLOCK.format(command='rm', errno=1, errtext="error text"))) self.assertEqual(errinfo.errno, 1) self.assertEqual(errinfo.message, "error text")
def test_parse(self): self.assertIsNone(DeleteCommand.parse_response(ET.fromstring('<rm />')))