def testFindEntryPointPluginsJSONConfig(self, iter_entry_points,
                                            resource_exists, resource_stream):
        iter_entry_points.return_value = [
            FakeEntryPoint(name='entry_point_plugin_json')
        ]

        # Load as JSON
        resource_exists.return_value = True

        @contextmanager
        def resource_stream_json_value():
            yield BytesIO(
                b'{"name": "Plugin name from JSON", "description": "Plugin description"}'
            )

        resource_stream.return_value = resource_stream_json_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_json', plugins)
        self.assertEqual(plugins['entry_point_plugin_json']['name'],
                         'Plugin name from JSON')
        self.assertEqual(plugins['entry_point_plugin_json']['description'],
                         'Plugin description')
    def testFindEntryPointPluginsBadJSONConfig(self, iter_entry_points,
                                               resource_exists,
                                               resource_stream):
        iter_entry_points.return_value = [
            FakeEntryPoint(name='entry_point_plugin_bad_json')
        ]

        # Load as JSON
        resource_exists.return_value = True

        @contextmanager
        def resource_stream_json_value():
            yield BytesIO(b'{"name": "Plugin name from JSON", bad_json')

        resource_stream.return_value = resource_stream_json_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_json', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_json', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_json'])
        self.assertIn('ValueError',
                      failures['entry_point_plugin_bad_json']['traceback'])
    def testFindEntryPointPluginsBadYAMLConfig(self, iter_entry_points,
                                               resource_exists,
                                               resource_stream):
        iter_entry_points.return_value = [
            FakeEntryPoint(name='entry_point_plugin_bad_yaml')
        ]

        # Load as YAML
        resource_exists.side_effect = [False, True]

        @contextmanager
        def resource_stream_yaml_value():
            yield BytesIO(b'"name": "Plugin name from YAML"\nbad_yaml\n}')

        resource_stream.return_value = resource_stream_yaml_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_yaml', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_yaml', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_yaml'])
        self.assertIn('ScannerError',
                      failures['entry_point_plugin_bad_yaml']['traceback'])
    def testFindEntryPointPluginsYAMLConfig(self, iter_entry_points,
                                            resource_exists, resource_stream):
        iter_entry_points.return_value = [
            FakeEntryPoint(name='entry_point_plugin_yaml')
        ]

        # Load as YAML
        resource_exists.side_effect = [False, True]

        @contextmanager
        def resource_stream_yml_value():
            yield BytesIO(
                b'"name": "Plugin name from YAML"\n"description": "Plugin description"'
            )

        resource_stream.return_value = resource_stream_yml_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_yaml', plugins)
        self.assertEqual(plugins['entry_point_plugin_yaml']['name'],
                         'Plugin name from YAML')
        self.assertEqual(plugins['entry_point_plugin_yaml']['description'],
                         'Plugin description')
    def testFindEntryPointPluginsBadJSONConfig(self, iter_entry_points, resource_exists,
                                               resource_stream):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry_point_plugin_bad_json')]

        # Load as JSON
        resource_exists.return_value = True

        @contextmanager
        def resource_stream_json_value():
            yield BytesIO(b'{"name": "Plugin name from JSON", bad_json')

        resource_stream.return_value = resource_stream_json_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_json', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_json', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_json'])
        self.assertIn(
            'JSONDecodeError' if six.PY3 else 'ValueError',
            failures['entry_point_plugin_bad_json']['traceback'])
    def testFindEntryPointPluginsBadYAMLConfig(self, iter_entry_points, resource_exists,
                                               resource_stream):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry_point_plugin_bad_yaml')]

        # Load as YAML
        resource_exists.side_effect = [False, True]

        @contextmanager
        def resource_stream_yaml_value():
            yield BytesIO(b'"name": "Plugin name from YAML"\nbad_yaml\n}')

        resource_stream.return_value = resource_stream_yaml_value()

        plugins = {}
        with mock.patch('girder.utility.plugin_utilities.logprint.exception') as logprint:
            findEntryPointPlugins(plugins)
            logprint.assert_called_once()

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_yaml', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_yaml', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_yaml'])
        self.assertIn('ScannerError', failures['entry_point_plugin_bad_yaml']['traceback'])
    def testFindEntryPointPluginsNone(self, iter_entry_points):
        iter_entry_points.return_value = []

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertFalse(plugins)
    def testFindEntryPointPluginsNone(self, iter_entry_points):
        iter_entry_points.return_value = []

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertFalse(plugins)
    def testFindEntryPointPluginsNoConfig(self, iter_entry_points, resource_exists):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry point plugin')]
        resource_exists.return_value = False

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry point plugin', plugins)
Beispiel #10
0
    def testFindEntryPointPluginsNoConfig(self, iter_entry_points, resource_exists):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry point plugin')]
        resource_exists.return_value = False

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry point plugin', plugins)
    def testFindEntryPointPluginsBadLoad(self, iter_entry_points, resource_exists,
                                         _clearPluginFailureInfo):
        iter_entry_points.return_value = [FakeEntryPoint(
            name='entry_point_plugin_bad_load', goodLoad=False)]

        resource_exists.return_value = False
        _clearPluginFailureInfo.return_value = None

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_load', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_load', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_load'])
        self.assertIn('SystemError', failures['entry_point_plugin_bad_load']['traceback'])
Beispiel #12
0
    def testFindEntryPointPluginsBadLoad(self, iter_entry_points, resource_exists,
                                         _clearPluginFailureInfo):
        iter_entry_points.return_value = [FakeEntryPoint(
            name='entry_point_plugin_bad_load', goodLoad=False)]

        resource_exists.return_value = False
        _clearPluginFailureInfo.return_value = None

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_bad_load', plugins)

        failures = getPluginFailureInfo()
        self.assertIn('entry_point_plugin_bad_load', failures)
        self.assertIn('traceback', failures['entry_point_plugin_bad_load'])
        self.assertIn('SystemError', failures['entry_point_plugin_bad_load']['traceback'])
    def testFindEntryPointPluginsJSONConfig(self, iter_entry_points, resource_exists,
                                            resource_stream):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry_point_plugin_json')]

        # Load as JSON
        resource_exists.return_value = True

        @contextmanager
        def resource_stream_json_value():
            yield BytesIO(b'{"name": "Plugin name from JSON", "description": "Plugin description"}')

        resource_stream.return_value = resource_stream_json_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_json', plugins)
        self.assertEqual(plugins['entry_point_plugin_json']['name'], 'Plugin name from JSON')
        self.assertEqual(plugins['entry_point_plugin_json']['description'], 'Plugin description')
    def testFindEntryPointPluginsYAMLConfig(self, iter_entry_points, resource_exists,
                                            resource_stream):
        iter_entry_points.return_value = [FakeEntryPoint(name='entry_point_plugin_yaml')]

        # Load as YAML
        resource_exists.side_effect = [False, True]

        @contextmanager
        def resource_stream_yml_value():
            yield BytesIO(b'"name": "Plugin name from YAML"\n"description": "Plugin description"')

        resource_stream.return_value = resource_stream_yml_value()

        plugins = {}
        findEntryPointPlugins(plugins)

        iter_entry_points.assert_called_once_with(group='girder.plugin')

        self.assertIn('entry_point_plugin_yaml', plugins)
        self.assertEqual(plugins['entry_point_plugin_yaml']['name'], 'Plugin name from YAML')
        self.assertEqual(plugins['entry_point_plugin_yaml']['description'], 'Plugin description')