def action_get(backend, inp, out): filename = read_safe_filename(inp) tmp = NamedTemporaryFile(delete=False) try: tmp.file.close() backend.get(filename, duplicity.path.Path(tmp.name)) with open(tmp.name, "rb") as f: out.write(StatusCodes.OK) copyfileobj(f, out) finally: os.remove(tmp.name)
def try_basic(self, backend): """Try basic operations with given backend. Requires backend be empty at first, and all operations are allowed. """ def cmp_list(l): """Assert that backend.list is same as l""" blist = backend.list() blist.sort() l.sort() assert blist == l, \ ("Got list: %s\nWanted: %s\n" % (repr(blist), repr(l))) # Identify test that's running print self.my_test_id, "... ", assert not os.system("rm -rf testfiles/backend_tmp") assert not os.system("mkdir testfiles/backend_tmp") regpath = path.Path("testfiles/various_file_types/regular_file") normal_file = "testfile" colonfile = ("file%swith.%scolons_-and%s%setc" % ((globals.time_separator,) * 4)) tmpregpath = path.Path("testfiles/backend_tmp/regfile") # Test list and put cmp_list([]) backend.put(regpath, normal_file) cmp_list([normal_file]) backend.put(regpath, colonfile) cmp_list([normal_file, colonfile]) # Test get regfilebuf = regpath.open("rb").read() backend.get(colonfile, tmpregpath) backendbuf = tmpregpath.open("rb").read() assert backendbuf == regfilebuf # Test delete backend.delete([colonfile, normal_file]) cmp_list([])
def try_basic(self, backend): """Try basic operations with given backend. Requires backend be empty at first, and all operations are allowed. """ def cmp_list(l): """Assert that backend.list is same as l""" blist = backend.list() blist.sort() l.sort() assert blist == l, \ ("Got list: %s Wanted: %s\n" % (repr(blist), repr(l))) # Identify test that's running print self.my_test_id, "... ", assert not os.system("rm -rf testfiles/backend_tmp") assert not os.system("mkdir testfiles/backend_tmp") regpath = path.Path("testfiles/various_file_types/regular_file") normal_file = "testfile" colonfile = ("file%swith.%scolons_-and%s%setc" % ((globals.time_separator,) * 4)) tmpregpath = path.Path("testfiles/backend_tmp/regfile") # Test list and put cmp_list([]) backend.put(regpath, normal_file) cmp_list([normal_file]) backend.put(regpath, colonfile) cmp_list([normal_file, colonfile]) # Test get regfilebuf = regpath.open("rb").read() backend.get(colonfile, tmpregpath) backendbuf = tmpregpath.open("rb").read() assert backendbuf == regfilebuf # Test delete backend.delete([colonfile, normal_file]) cmp_list([])