Beispiel #1
0
 def testInvalidClientInstall(self):
     self.assertFalse(
         install.install_web('http://notvalid.kitware.com')
     )
     self.assertFalse(
         install.install_web(
             os.path.join(
                 pluginRoot, 'has_deps', 'plugin.json'
             )
         )
     )
Beispiel #2
0
    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'
                })
Beispiel #3
0
    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'
                })
Beispiel #4
0
    def testWebInstall(self):
        with mock.patch('subprocess.Popen', return_value=ProcMock(rc=2)) as p,\
                six.assertRaisesRegex(self, Exception, 'npm install .* returned 2'):
            install.install_web()

            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)

        with mock.patch('subprocess.Popen', return_value=ProcMock()):
            install.install_web()

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web()
            self.assertNotIn('--production', p.mock_calls[0][1][0])

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web(PluginOpts(dev=True))

            self.assertNotIn('--production', p.mock_calls[0][1][0])

        # Test initiation of web install via the REST API
        user = self.model('user').createUser(login='******',
                                             firstName='admin',
                                             lastName='admin',
                                             email='*****@*****.**',
                                             password='******',
                                             admin=True)

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            # Test without progress
            resp = self.request('/system/web_build', method='POST', user=user)
            self.assertStatusOk(resp)

            self.assertEqual(len(p.mock_calls), 2)
            self.assertEqual(list(p.mock_calls[0][1][0]),
                             ['npm', 'install', '--unsafe-perm'])
            self.assertEqual(list(p.mock_calls[1][1][0]), [
                'npm', 'run', 'build', '--', '--no-progress=true',
                '--env=prod', '--plugins='
            ])

        # Test with progress (requires actually calling a subprocess)
        os.environ['PATH'] = '%s:%s' % (os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'mockpath'), os.environ.get('PATH', ''))
        resp = self.request('/system/web_build',
                            method='POST',
                            user=user,
                            params={'progress': True})
        self.assertStatusOk(resp)
Beispiel #5
0
    def testWebInstall(self):
        with mock.patch(POPEN, return_value=ProcMock(rc=2)) as p,\
                six.assertRaisesRegex(self, Exception, 'npm install returned 2'):
            install.install_web()

            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)

        with mock.patch(POPEN, return_value=ProcMock()):
            install.install_web()

        with mock.patch(POPEN, return_value=ProcMock()) as p:
            install.install_web()
            self.assertTrue('--production' in p.mock_calls[0][1][0])

        with mock.patch(POPEN, return_value=ProcMock()) as p:
            install.install_web(PluginOpts(dev=True))

            self.assertTrue('--production' not in p.mock_calls[0][1][0])
Beispiel #6
0
    def testWebInstall(self):
        with mock.patch(POPEN, return_value=ProcMock(rc=2)) as p, self.assertRaisesRegexp(
            Exception, "npm install returned 2"
        ):
            install.install_web()

            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)

        with mock.patch(POPEN, return_value=ProcMock()):
            install.install_web()

        with mock.patch(POPEN, return_value=ProcMock()) as p:
            install.install_web()
            self.assertTrue("--production" in p.mock_calls[0][1][0])

        with mock.patch(POPEN, return_value=ProcMock()) as p:
            install.install_web(PluginOpts(dev=True))

            self.assertTrue("--production" not in p.mock_calls[0][1][0])
Beispiel #7
0
 def testInvalidClientInstall(self):
     self.assertFalse(install.install_web('http://notvalid.kitware.com'))
     self.assertFalse(
         install.install_web(
             os.path.join(pluginRoot, 'has_deps', 'plugin.json')))
Beispiel #8
0
    def testWebInstall(self):
        with mock.patch('subprocess.Popen', return_value=ProcMock(rc=2)) as p,\
                six.assertRaisesRegex(self, Exception, 'npm install .* returned 2'):
            install.install_web()

            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)

        with mock.patch('subprocess.Popen', return_value=ProcMock()):
            install.install_web()

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web()
            self.assertIn('--production', p.mock_calls[0][1][0])

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web(PluginOpts(dev=True))

            self.assertNotIn('--production', p.mock_calls[0][1][0])

        # Test initiation of web install via the REST API
        user = self.model('user').createUser(
            login='******', firstName='admin', lastName='admin', email='*****@*****.**',
            password='******', admin=True)

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            # Test without progress
            resp = self.request('/system/web_build', method='POST', user=user)
            self.assertStatusOk(resp)

            self.assertEqual(len(p.mock_calls), 2)
            self.assertEqual(
                list(p.mock_calls[0][1][0]), ['npm', 'install', '--unsafe-perm', '--production'])
            self.assertEqual(
                list(p.mock_calls[1][1][0]),
                ['npm', 'run', 'build', '--',
                 '--no-progress=true', '--env=prod', '--plugins=', '--configure-plugins='])

        # Test with progress (requires actually calling a subprocess)
        os.environ['PATH'] = '%s:%s' % (
            os.path.join(os.path.abspath(os.path.dirname(__file__)), 'mockpath'),
            os.environ.get('PATH', '')
        )
        resp = self.request('/system/web_build', method='POST', user=user, params={
            'progress': True
        })
        self.assertStatusOk(resp)

        # Test watch commands
        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web(PluginOpts(watch=True))

            self.assertEqual(len(p.mock_calls), 1)
            self.assertEqual(list(p.mock_calls[0][1][0]), ['npm', 'run', 'watch'])

        with mock.patch('subprocess.Popen', return_value=ProcMock()) as p:
            install.install_web(PluginOpts(watch_plugin='jobs'))

            self.assertEqual(len(p.mock_calls), 1)
            self.assertEqual(
                list(p.mock_calls[0][1][0]),
                ['npm', 'run', 'watch', '--', '--plugins=jobs', '--configure-plugins=',
                 'webpack:plugin_jobs']
            )

        # Keyboard interrupt should be handled gracefully
        with mock.patch('subprocess.Popen', return_value=ProcMock(keyboardInterrupt=True)):
            install.install_web(PluginOpts(watch=True))