def test_get_readme(self): """Verify model returns the plugin archive's README""" self.server_thd.start() readme_fetcher = zipper.UnZipper(self.plugin) expected_readme = readme_fetcher.read("readme.txt") self.model.get_plugin(self.plugin_url_params) retrieved_readme = self.model.get_readme(self.plugin_url_params) self.assertEqual(expected_readme, retrieved_readme)
def test_init_file(self): """Verify instantiation with a file-like object handle to a ZIP file""" a_zip = self.get_zip() unzipper = zipper.UnZipper(zip_file=a_zip, password="******") self.assertEqual(unzipper.file, a_zip) self.assertEqual(unzipper.password, "123") if not a_zip.closed: a_zip.close()
def test_extractall(self): """Verify extraction of all the files in the ZIP""" unzipper = zipper.UnZipper(zip_file=TestUnzipper.zip_file_path) original_files = { os.path.basename(orig_file): orig_file for orig_file in self.generate_file_list() } unzipper.extractall(TestUnzipper.destination_folder) for root, dirs, files in os.walk(TestUnzipper.destination_folder): for fname in files: basename, ext = os.path.splitext(fname) if ext.lower() in ('.png', '.jpg'): file_name = os.path.join(root, fname) self.assertTrue( filecmp.cmp(file_name, original_files[fname]))
def test_read(self): """Verify reading a single file from the ZIP""" unzipper = zipper.UnZipper(zip_file=TestUnzipper.zip_file_path) for root, dirs, files in os.walk(TestUnzipper.file_folder): for fname in files: basename, ext = os.path.splitext(fname) if ext.lower() in ('.png', '.jpg'): file_name = os.path.join(root, fname) # Files are stored with relative paths # in ZIPs, remove the '/' or 'drive:\' # from root rel_path = os.path.normpath(file_name.split(os.sep, 1)[-1]) if sys.platform == 'win32': # zip module uses / character in its filesystem rel_path = rel_path.replace('\\', '/') with open(file_name, "rb") as original_file: self.assertEqual(original_file.read(), unzipper.read(rel_path))
def test_install_plugin(self): """Verify install_plugin method correctly installs a plugin; also verifies handling of encrypted ZIPs""" sample_plugin_url = TestPODModelInstaller.local_plugin('good_podmodel.zip') installed_plugin_name = os.path.join(pathfinder.podmodels_path(), 'good_podmodel.py') installer = podmodel_installer.PODModelInstaller(sample_plugin_url) installer.fetch() self.assertTrue(installer.verify_plugin()) install_success = installer.install_plugin() self.assertTrue(os.path.exists(installed_plugin_name)) self.assertTrue(install_success) # Clean up - attempt to remove the sample POD Model if it already exists podmodel_files = zipper.UnZipper(sample_plugin_url).list_contents() for each_file in podmodel_files: full_path = os.path.join(pathfinder.podmodels_path(), each_file) if os.path.exists(full_path): try: os.remove(full_path) except WindowsError: # file in use return
def setUp(self): self.good_plugin_installer = podmodel_installer.PODModelInstaller(self.good_plugin_loc) self.plugin_reader = zipper.UnZipper(self.good_plugin_loc)
def setUp(self): """Creates a SimpleHTTPServer instance to handle a single request. Use self.server_thd.start() to initiate.""" #self.server_thd = threading.Thread(target=TestRemotePluginInstaller.httpd.handle_request) self.good_plugin_installer = podmodel_installer.RemotePODModelInstaller(self.good_plugin_url) self.plugin_reader = zipper.UnZipper(self.good_plugin)
def setUp(self): self.good_plugin_installer = plugin_installer.PluginInstaller(self.good_plugin_loc) self.plugin_reader = zipper.UnZipper(self.good_plugin_loc)
def test_is_ok(self): """Verify UnZipper returns True if files appear ok""" unzipper = zipper.UnZipper(zip_file=TestUnzipper.zip_file_path) self.assertTrue(unzipper.is_ok())
def test_list_contents(self): """Verify listing of ZIP contents""" unzipper = zipper.UnZipper(zip_file=TestUnzipper.zip_file_path) with zipfile.ZipFile(TestUnzipper.zip_file_path, 'r') as a_zip: self.assertListEqual(a_zip.namelist(), unzipper.list_contents())
def test_init_bad_zip(self): """Verify instantiation raises a TypeError if the specified file is not a ZIP archive""" with self.assertRaises(TypeError): zipper.UnZipper(zip_file=__file__)
def test_init_path(self): """Verify instantiation with a path to a ZIP file""" unzipper = zipper.UnZipper(zip_file=TestUnzipper.zip_file_path, password="******") self.assertEqual(unzipper.file, TestUnzipper.zip_file_path) self.assertEqual(unzipper.password, "123")
def setUp(self): self.good_plugin_installer = adamodel_installer.ADAModelInstaller( self.good_plugin_loc) self.plugin_reader = zipper.UnZipper(self.good_plugin_loc)
def setUp(self): """Creates a SimpleHTTPServer instance to handle a single request. Use self.server_thd.start() to initiate.""" self.good_plugin_installer = adamodel_installer.RemoteADAModelInstaller( self.good_plugin_url) self.plugin_reader = zipper.UnZipper(self.good_plugin)