def testMultiPluginInstallFromTgz(self): self.assertEqual( sorted(install.install_plugin(self.combinedPluginTarball)), ['multi1', 'multi2'] ) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'multi1', 'plugin.json') ) ) # make sure it fails when force is off self.assertEqual( install.install_plugin(self.combinedPluginTarball), [] ) # make sure it succeeds when force is on self.assertEqual( sorted(install.install_plugin( self.combinedPluginTarball, force=True )), ['multi1', 'multi2'] )
def testDevDependencies(self): with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin( PluginOpts( plugin=[ os.path.join(pluginRoot, "has_dev_deps"), os.path.join(constants.ROOT_DIR, "plugins", "jobs"), ] ) ) self.assertTrue(os.path.exists(os.path.join(self.pluginDir, "has_dev_deps", "plugin.json"))) self.assertTrue("--production" in p.mock_calls[0][1][0]) with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin( PluginOpts( plugin=[ os.path.join(pluginRoot, "has_dev_deps"), os.path.join(constants.ROOT_DIR, "plugins", "jobs"), ], force=True, dev=True, ) ) self.assertTrue("--production" not in p.mock_calls[0][1][0])
def testDevDependencies(self): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_dev_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ])) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'has_dev_deps', 'plugin.json'))) install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_dev_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ], force=True, dev=True))
def testSinglePluginInstallFromTgz(self): self.assertEqual(install.install_plugin(self.singlePluginTarball), ['single']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'single', 'plugin.json'))) # make sure it fails when force is off self.assertEqual(install.install_plugin(self.singlePluginTarball), []) # make sure it succeeds when force is on self.assertEqual( install.install_plugin(self.singlePluginTarball, force=True), ['single'])
def testMultiPluginInstallFromTgz(self): self.assertEqual( sorted(install.install_plugin(self.combinedPluginTarball)), ['multi1', 'multi2']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'multi1', 'plugin.json'))) # make sure it fails when force is off self.assertEqual(install.install_plugin(self.combinedPluginTarball), []) # make sure it succeeds when force is on self.assertEqual( sorted( install.install_plugin(self.combinedPluginTarball, force=True)), ['multi1', 'multi2'])
def testDevDependencies(self): with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_dev_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ])) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'has_dev_deps', 'plugin.json'))) self.assertTrue('--production' in p.mock_calls[0][1][0]) with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_dev_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ], force=True, dev=True)) self.assertTrue('--production' not in p.mock_calls[0][1][0])
def testSinglePluginInstallFromDir(self): l = install.install_plugin( os.path.join(pluginRoot, 'has_deps') ) self.assertEqual(l, ['has_deps']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'has_deps', 'plugin.json') ) )
def testPluginWithNoConfig(self): l = install.install_plugin( os.path.join(pluginRoot, 'test_plugin') ) self.assertEqual(l, ['test_plugin']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'test_plugin', 'server.py') ) )
def testPluginWithYaml(self): l = install.install_plugin( os.path.join(pluginRoot, 'plugin_yaml') ) self.assertEqual(l, ['plugin_yaml']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'plugin_yaml', 'plugin.yml') ) )
def testStaticDependencies(self): for p in ('does_nothing', 'has_deps', 'has_static_deps', 'has_webroot', 'test_plugin'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, p) ])) with mock.patch('subprocess.Popen', return_value=ProcMock()) as p: install.install_web(PluginOpts(plugins='has_static_deps')) self.assertEqual(len(p.mock_calls), 2) self.assertEqual(list(p.mock_calls[1][1][0][:-1]), [ 'npm', 'run', 'build', '--', '--no-progress=true', '--env=prod', '--plugins=has_static_deps', ]) lastArg = p.mock_calls[1][1][0][-1] six.assertRegex(self, lastArg, '--configure-plugins=.*') self.assertEqual( set(lastArg.split('=')[-1].split(',')), { 'does_nothing', 'has_deps', 'has_webroot', 'test_plugin' })
def testSinglePluginInstallFromTgz(self): self.assertEqual( install.install_plugin(self.singlePluginTarball), ['single'] ) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'single', 'plugin.json') ) ) # make sure it fails when force is off self.assertEqual( install.install_plugin(self.singlePluginTarball), [] ) # make sure it succeeds when force is on self.assertEqual( install.install_plugin(self.singlePluginTarball, force=True), ['single'] )
def testInstallPlugin(self): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ])) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'jobs', 'plugin.yml'))) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'has_deps', 'plugin.json'))) # Should fail if exists and force=False with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Should succeed if force=True install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Test skip_requirements install.install_plugin(PluginOpts( force=True, skip_requirements=True, plugin=[os.path.join(pluginRoot, 'has_deps')])) # If bad path is given, should fail gracefully with six.assertRaisesRegex(self, Exception, 'Invalid plugin directory'): install.install_plugin(PluginOpts(force=True, plugin=[ '/bad/install/path' ])) # If src == dest, we should still run npm and succeed. install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(self.pluginDir, 'has_deps') ])) # Should fail if exists as directory and symlink is true with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ], symlink=True)) # Should be a link if force=True and symlink=True install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ], symlink=True)) self.assertTrue(os.path.islink(os.path.join( self.pluginDir, 'has_deps'))) # Should fail if exists as link and symlink is false with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Should not be a link if force=True and symlink=False install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ])) self.assertFalse(os.path.islink(os.path.join( self.pluginDir, 'has_deps')))
def testInstallPlugin(self): with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps'), os.path.join(constants.ROOT_DIR, 'plugins', 'jobs') ])) self.assertEqual(len(p.mock_calls), 1) self.assertEqual(p.mock_calls[0][1][0][:2], ('npm', 'install')) self.assertEqual(p.mock_calls[0][2]['cwd'], constants.PACKAGE_DIR) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'jobs', 'plugin.yml'))) self.assertTrue(os.path.exists( os.path.join(self.pluginDir, 'has_deps', 'plugin.json'))) # Should fail if exists and force=False with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Should succeed if force=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # If npm install returns 1, should fail with mock.patch(POPEN, return_value=ProcMock(rc=1)), \ six.assertRaisesRegex(self, Exception, 'npm install returned 1'): install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Using skip_web_client and skip_requirements should circumvent install steps with mock.patch(POPEN, return_value=ProcMock(rc=1)) as mockPopen: install.install_plugin(PluginOpts( force=True, skip_requirements=True, skip_web_client=True, plugin=[os.path.join(pluginRoot, 'has_deps')])) self.assertEqual(len(mockPopen.mock_calls), 0) # If bad path is given, should fail gracefuly with six.assertRaisesRegex(self, Exception, 'Invalid plugin directory'): install.install_plugin(PluginOpts(force=True, plugin=[ '/bad/install/path' ])) # If src == dest, we should still run npm and succeed. with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(self.pluginDir, 'has_deps') ])) # Should fail if exists as directory and symlink is true with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ], symlink=True)) # Should be a link if force=True and symlink=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ], symlink=True)) self.assertTrue(os.path.islink(os.path.join( self.pluginDir, 'has_deps'))) # Should fail if exists as link and symlink is false with six.assertRaisesRegex(self, Exception, 'Plugin already exists'): install.install_plugin(PluginOpts(plugin=[ os.path.join(pluginRoot, 'has_deps') ])) # Should not be a link if force=True and symlink=False with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[ os.path.join(pluginRoot, 'has_deps') ])) self.assertFalse(os.path.islink(os.path.join( self.pluginDir, 'has_deps')))
def testGruntDependencies(self): with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin( PluginOpts( plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) self.assertEqual(len(p.mock_calls), 1) self.assertEqual(p.mock_calls[0][1][0][:2], ('npm', 'install')) self.assertEqual(p.mock_calls[0][2]['cwd'], constants.PACKAGE_DIR) self.assertTrue( os.path.exists( os.path.join(self.pluginDir, 'has_grunt_deps', 'plugin.json'))) # Should fail if exists and force=False with self.assertRaisesRegexp(Exception, 'Plugin already exists'): install.install_plugin( PluginOpts( plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) # Should succeed if force=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin( PluginOpts(force=True, plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) # If npm install returns 1, should fail with mock.patch(POPEN, return_value=ProcMock(rc=1)), \ self.assertRaisesRegexp(Exception, 'npm install returned 1'): install.install_plugin( PluginOpts(force=True, plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) # If bad path is given, should fail gracefuly with self.assertRaisesRegexp(Exception, 'Invalid plugin directory'): install.install_plugin( PluginOpts(force=True, plugin=['/bad/install/path'])) # If src == dest, we should still run npm and succeed. with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin( PluginOpts( force=True, plugin=[os.path.join(self.pluginDir, 'has_grunt_deps')])) # Should fail if exists as directory and symlink is true with self.assertRaisesRegexp(Exception, 'Plugin already exists'): install.install_plugin( PluginOpts(plugin=[os.path.join(pluginRoot, 'has_grunt_deps')], symlink=True)) # Should be a link if force=True and symlink=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin( PluginOpts(force=True, plugin=[os.path.join(pluginRoot, 'has_grunt_deps')], symlink=True)) self.assertTrue( os.path.islink(os.path.join(self.pluginDir, 'has_grunt_deps'))) # Should fail if exists as link and symlink is false with self.assertRaisesRegexp(Exception, 'Plugin already exists'): install.install_plugin( PluginOpts( plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) # Should not be a link if force=True and symlink=False with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin( PluginOpts(force=True, plugin=[os.path.join(pluginRoot, 'has_grunt_deps')])) self.assertFalse( os.path.islink(os.path.join(self.pluginDir, 'has_grunt_deps')))
def testPluginWithYaml(self): l = install.install_plugin(os.path.join(pluginRoot, 'plugin_yaml')) self.assertEqual(l, ['plugin_yaml']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'plugin_yaml', 'plugin.yml')))
def testInstallPlugin(self): with mock.patch(POPEN, return_value=ProcMock()) as p: install.install_plugin( PluginOpts( plugin=[os.path.join(pluginRoot, "has_deps"), os.path.join(constants.ROOT_DIR, "plugins", "jobs")] ) ) self.assertEqual(len(p.mock_calls), 1) self.assertEqual(p.mock_calls[0][1][0][:2], ("npm", "install")) self.assertEqual(p.mock_calls[0][2]["cwd"], constants.PACKAGE_DIR) self.assertTrue(os.path.exists(os.path.join(self.pluginDir, "jobs", "plugin.yml"))) self.assertTrue(os.path.exists(os.path.join(self.pluginDir, "has_deps", "plugin.json"))) # Should fail if exists and force=False with self.assertRaisesRegexp(Exception, "Plugin already exists"): install.install_plugin(PluginOpts(plugin=[os.path.join(pluginRoot, "has_deps")])) # Should succeed if force=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[os.path.join(pluginRoot, "has_deps")])) # If npm install returns 1, should fail with mock.patch(POPEN, return_value=ProcMock(rc=1)), self.assertRaisesRegexp( Exception, "npm install returned 1" ): install.install_plugin(PluginOpts(force=True, plugin=[os.path.join(pluginRoot, "has_deps")])) # If bad path is given, should fail gracefuly with self.assertRaisesRegexp(Exception, "Invalid plugin directory"): install.install_plugin(PluginOpts(force=True, plugin=["/bad/install/path"])) # If src == dest, we should still run npm and succeed. with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[os.path.join(self.pluginDir, "has_deps")])) # Should fail if exists as directory and symlink is true with self.assertRaisesRegexp(Exception, "Plugin already exists"): install.install_plugin(PluginOpts(plugin=[os.path.join(pluginRoot, "has_deps")], symlink=True)) # Should be a link if force=True and symlink=True with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[os.path.join(pluginRoot, "has_deps")], symlink=True)) self.assertTrue(os.path.islink(os.path.join(self.pluginDir, "has_deps"))) # Should fail if exists as link and symlink is false with self.assertRaisesRegexp(Exception, "Plugin already exists"): install.install_plugin(PluginOpts(plugin=[os.path.join(pluginRoot, "has_deps")])) # Should not be a link if force=True and symlink=False with mock.patch(POPEN, return_value=ProcMock()): install.install_plugin(PluginOpts(force=True, plugin=[os.path.join(pluginRoot, "has_deps")])) self.assertFalse(os.path.islink(os.path.join(self.pluginDir, "has_deps")))
def testPluginWithNoConfig(self): l = install.install_plugin(os.path.join(pluginRoot, 'test_plugin')) self.assertEqual(l, ['test_plugin']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'test_plugin', 'server.py')))
def testSinglePluginInstallFromDir(self): l = install.install_plugin(os.path.join(pluginRoot, 'has_deps')) self.assertEqual(l, ['has_deps']) self.assertTrue( os.path.isfile( os.path.join(self.pluginDir, 'has_deps', 'plugin.json')))