Esempio n. 1
0
 def test_get_extension_tasks(self, app):
     main()
     extensions = sorted(entrypoint.get_extension_tasks('plugin2'))
     self.assertEqual(extensions, [
         'girder_worker._test_plugins.tasks.celery_task',
         'girder_worker._test_plugins.tasks.function_task'
     ])
Esempio n. 2
0
def test_get_extension_tasks():
    with mock.patch('girder_worker.__main__.app'):
        main()
        extensions = sorted(entrypoint.get_extension_tasks('plugin2'))
        assert extensions == [
            'girder_worker._test_plugins.tasks.celery_task',
            'girder_worker._test_plugins.tasks.function_task'
        ]
Esempio n. 3
0
def test_get_extensions():
    with mock.patch('girder_worker.__main__.app'):
        main()
        extensions = sorted(entrypoint.get_extensions())
        if six.PY2:
            assert extensions == ['core', 'plugin1', 'plugin2']
        else:
            assert extensions == ['plugin1', 'plugin2']
    def test_plugin_throws_import_error(self, app, pr):
        core = EntryPoint.parse('core = girder_worker:GirderWorkerPlugin')
        core.load = mock.Mock(side_effect=ImportError(
            'Intentionally throw import error'))
        pr.iter_entry_points.return_value = [core]

        main()

        app.conf.update.assert_any_call({'CELERY_IMPORTS': []})
    def test_core_plugin(self, app, pr):
        ep = EntryPoint.parse('core = girder_worker:GirderWorkerPlugin')
        ep.load = mock.Mock(return_value=girder_worker.GirderWorkerPlugin)
        pr.iter_entry_points.return_value = [ep]

        main()

        app.conf.update.assert_any_call({'CELERY_IMPORTS':
                                         ['girder_worker.tasks']})
        app.conf.update.assert_any_call({'CELERY_INCLUDE': []})
    def test_exclude_core_tasks(self, config, app, pr):

        core = EntryPoint.parse('core = girder_worker:GirderWorkerPlugin')
        core.load = mock.Mock(return_value=girder_worker.GirderWorkerPlugin)
        pr.iter_entry_points.return_value = [core]
        config.getboolean.return_value = False

        main()

        # Called once with no plugins,  ie.  core_tasks were not added
        app.conf.update.assert_called_once_with({'CELERY_INCLUDE': []})
    def test_plugin_task_imports_throws_exception(self, app, pr):
        core = EntryPoint.parse('core = girder_worker:GirderWorkerPlugin')
        MockPlugin = mock_plugin([])
        MockPlugin.task_imports = mock.Mock(side_effect=Exception(
            'Intentionally throw exception'))

        core.load = mock.Mock(return_value=MockPlugin)
        pr.iter_entry_points.return_value = [core]

        main()

        app.conf.update.assert_any_call({'CELERY_IMPORTS': []})
    def test_core_and_other_plugin(self, app, pr):

        core = EntryPoint.parse('core = girder_worker:GirderWorkerPlugin')
        core.load = mock.Mock(return_value=girder_worker.GirderWorkerPlugin)

        plugin = EntryPoint.parse('mock = mockplugin:MockPlugin')
        plugin.load = mock.Mock(return_value=mock_plugin(['mock.plugin.tasks']))

        pr.iter_entry_points.return_value = [core, plugin]

        main()

        app.conf.update.assert_any_call({'CELERY_IMPORTS':
                                         ['girder_worker.tasks']})
        app.conf.update.assert_any_call({'CELERY_INCLUDE':
                                         ['mock.plugin.tasks']})
Esempio n. 9
0
 def test_get_extensions(self, app):
     main()
     extensions = sorted(entrypoint.get_extensions())
     self.assertEqual(extensions, ['core', 'plugin1', 'plugin2'])
Esempio n. 10
0
 def test_external_plugins(self, app):
     main()
     app.conf.update.assert_any_call({'CELERY_IMPORTS': ['os.path']})
     app.conf.update.assert_any_call(
         {'CELERY_INCLUDE': ['girder_worker._test_plugins.tasks']})
Esempio n. 11
0
 def test_core_plugin(self, app):
     main()
     app.conf.update.assert_any_call(
         {'CELERY_IMPORTS': ['girder_worker.tasks']})