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 = plugin_installer.PluginInstaller(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 = plugin_installer.PluginInstaller(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 = plugin_installer.PluginInstaller(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("Retrieving plugin 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 is set") else: zip_password = None module_logger.info("zip_password field is set to None") self.plugin_fetcher = plugin_installer.PluginInstaller(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 = TestPluginInstaller.local_plugin('greets_plugin.zip') installed_plugin_name = os.path.join(pathfinder.plugins_path(), 'greets_plugin.py') installer = plugin_installer.PluginInstaller(sample_plugin_url, zip_password='******') 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 plugin if it already exists if os.path.exists(installed_plugin_name): try: os.remove(installed_plugin_name) except WindowsError: # file in use return
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_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 = plugin_installer.PluginInstaller(self.badnoreadme_plugin_loc) bad_plugin_installer.fetch() self.assertFalse(bad_plugin_installer.verify_plugin())
def test_verify_plugin_bad_readme(self): """Verify that verify_plugin method returns False if the plugin appears invalid due to improperly-named README.""" bad_plugin_installer = plugin_installer.PluginInstaller(self.badreadme_plugin_loc) bad_plugin_installer.fetch() self.assertFalse(bad_plugin_installer.verify_plugin())