def test_init(self): lscommand = LsCommand(path='/a/path/here') et = lscommand.get_etree() self.assertEqual(et.tag, 'ls') self.assertEqual('/a/path/here', et.get('path')) self.assertEqual('any', et.get('hash')) self.assertEqual(0, len(list(et))) self.assertEqual(None, et.text)
def test_parse_error(self): fss_api = mock.Mock() dev_id = 'my_dev_id' errinfo = LsCommand.parse_response( ET.fromstring(ERROR_BLOCK.format(command='ls', errno=1, errtext="error text")), device_id=dev_id, fssapi=fss_api) self.assertEqual(errinfo.errno, 1) self.assertEqual(errinfo.message, "error text")
def test_parse(self): fss_api = mock.Mock() dev_id = 'my_dev_id' file1 = FileInfo(fss_api, dev_id, '/a/path/file1.txt', 1436276773, 7989, "967FDA522517B9CE0C3E056EDEB485BB", 'md5') file2 = FileInfo(fss_api, dev_id, '/a/path/file2.py', 1434377919, 181, "DEA17715739E46079C1A6DDCB38344DF", 'md5') dir1 = DirectoryInfo(fss_api, dev_id, '/a/path/dir', 1436203917) linfo = LsCommand.parse_response(ET.fromstring(LS_BLOCK), device_id=dev_id, fssapi=fss_api) self.assertEqual(linfo, LsInfo(directories=[dir1], files=[file1, file2]))
delete_test_file(fssapi, target, tmp_server_device_file) print("\nList of files in {}".format(base_dir)) out_dict = fssapi.list_files(target, base_dir) print(out_dict) if __name__ == "__main__": dc = get_authenticated_dc() device_id = "your-device-id-here" target = DeviceTarget(device_id) base_dir = '/a/directory/on/your/device' use_filesystem(dc, target, base_dir) fssapi = dc.get_fss_api() tmp_file_path = "{}/{}".format(base_dir, 'test_file.txt') put_test_file(fssapi, target, tmp_file_path) cutoff_time = time.time() get_modified_files(fssapi, target, base_dir, cutoff_time) print("\nModifying file {}".format(tmp_file_path)) fssapi.put_file(target, tmp_file_path, file_data=six.b("data"), offset=4) time.sleep(5) get_modified_files(fssapi, target, base_dir, cutoff_time) delete_test_file(fssapi, target, tmp_file_path) command_block = FileSystemServiceCommandBlock() command_block.add_command(LsCommand(base_dir)) command_block.add_command(LsCommand('/another/directory/on/your/device')) print(fssapi.send_command_block(target, command_block))