def test_verify_plugin_bad_structure(self): """Verify that verify_plugin method returns False if the plugin appears invalid due to having an invalid structure (support files in sub-folder; only module.py and README allowed in root)""" bad_plugin_installer = podmodel_installer.PODModelInstaller(self.badstructure_plugin_loc) bad_plugin_installer.fetch() self.assertFalse(bad_plugin_installer.verify_plugin())
def test_fetch(self): """Verify retrieval of the plugin archive""" a_plugin_fetcher = podmodel_installer.PODModelInstaller(self.good_plugin_loc) a_plugin_fetcher.fetch() with open(self.good_plugin_loc, 'rb') as fidin: local_plugin = fidin.read() self.assertEqual(local_plugin, a_plugin_fetcher.plugin) self.assertEqual(cStringIO.StringIO(local_plugin).getvalue(), a_plugin_fetcher.plugin_contents.getvalue())
def test_init(self): """Verify correct initialization""" zip_pword = random.sample(string.ascii_letters, 9) a_plugin_fetcher = podmodel_installer.PODModelInstaller(self.good_plugin_loc, zip_password=zip_pword) self.assertEqual(self.good_plugin_loc, a_plugin_fetcher.plugin_url) self.assertEqual(zip_pword, a_plugin_fetcher.zip_password) self.assertIsNone(a_plugin_fetcher.plugin) self.assertIsNone(a_plugin_fetcher.plugin_contents)
def get_plugin(self, url_dict): """Fetches the plugin""" plugin_url = url_dict.get('url') module_logger.info("Attempting to fetch POD Model from {0}".format(plugin_url)) if url_dict.get('zip_encrypted', False): zip_password = url_dict.get('zip_password') module_logger.info("zip_password field has been set") else: zip_password = None module_logger.info("zip_password field has been set to None") self.plugin_fetcher = podmodel_installer.PODModelInstaller(plugin_url, zip_password) self.plugin_fetcher.fetch()
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 test_verify_plugin_bad_name(self): """Verify that verify_plugin method returns False if the plugin appears invalid due to improperly-named plugin module.""" bad_plugin_installer = podmodel_installer.PODModelInstaller(self.badname_plugin_loc) bad_plugin_installer.fetch() self.assertFalse(bad_plugin_installer.verify_plugin())
def setUp(self): self.good_plugin_installer = podmodel_installer.PODModelInstaller(self.good_plugin_loc) self.plugin_reader = zipper.UnZipper(self.good_plugin_loc)
def test_verify_plugin_bad_noreadme(self): """Verify that verify_plugin method returns False if the plugin appears invalid due to not having a README file in the root.""" bad_plugin_installer = podmodel_installer.PODModelInstaller(self.badnoreadme_plugin_loc) bad_plugin_installer.fetch() self.assertFalse(bad_plugin_installer.verify_plugin())