def test_make_zip(self): test_file_creator = FileCreator() test_file_creator.append_file('index.js', 'exports handler = (event, context, callback) => {callback(null, event);}') dirname = test_file_creator.rootdir expected_files = set(['index.js']) random_name = ''.join(random.choice(string.ascii_letters) for _ in range(10)) outfile = os.path.join(tempfile.gettempdir(), random_name) zipfile_name = None try: zipfile_name = make_zip(outfile, dirname) test_zip_file = zipfile.ZipFile(zipfile_name, "r") with closing(test_zip_file) as zf: files_in_zip = set() for info in zf.infolist(): files_in_zip.add(info.filename) self.assertEquals(files_in_zip, expected_files) finally: if zipfile_name: os.remove(zipfile_name) test_file_creator.remove_all()
def test_make_zip(self): test_file_creator = FileCreator() test_file_creator.append_file( 'index.js', 'exports handler = (event, context, callback) => {callback(null, event);}' ) dirname = test_file_creator.rootdir expected_files = {'index.js'} random_name = ''.join( random.choice(string.ascii_letters) for _ in range(10)) outfile = os.path.join(tempfile.gettempdir(), random_name) zipfile_name = None try: zipfile_name = make_zip(outfile, dirname) test_zip_file = zipfile.ZipFile(zipfile_name, "r") with closing(test_zip_file) as zf: files_in_zip = set() for info in zf.infolist(): files_in_zip.add(info.filename) self.assertEquals(files_in_zip, expected_files) finally: if zipfile_name: os.remove(zipfile_name) test_file_creator.remove_all()
def test_must_follow_symlinks(self): data = "hello world" data_file = os.path.join(self.rootdir, "data.txt") with open(data_file, "w") as fp: fp.write(data) # Create symlink within the zip root link_name = os.path.join(self.ziproot, "data-link.txt") os.symlink(data_file, link_name) # Zip up the contents of folder `ziproot` which contains the symlink zipfile_path = make_zip(os.path.join(self.rootdir, "archive"), self.ziproot) # Now verify that the zipfile includes contents of the data file we created myzip = zipfile.ZipFile(zipfile_path) # Data file should be the only file within the zip self.assertEquals(["data-link.txt"], myzip.namelist()) myfile = myzip.open("data-link.txt", "r") # Its content should be equal the value we wrote. self.assertEquals(data.encode("utf-8"), myfile.read())
def test_must_follow_symlinks(self): data = "hello world" data_file = os.path.join(self.rootdir, "data.txt") with open(data_file, "w") as fp: fp.write(data) # Create symlink within the zip root link_name = os.path.join(self.ziproot, "data-link.txt") os.symlink(data_file, link_name) # Zip up the contents of folder `ziproot` which contains the symlink zipfile_path = make_zip(os.path.join(self.rootdir, "archive"), self.ziproot) # Now verify that the zipfile includes contents of the data file we created myzip = zipfile.ZipFile(zipfile_path) # Data file should be the only file within the zip self.assertEquals(["data-link.txt"], myzip.namelist()) myfile = myzip.open("data-link.txt", "r") # Its content should be equal the value we wrote. self.assertEquals(data.encode("utf-8"), myfile.read())