Beispiel #1
0
def test_same_plugin_twice():
    """Run setup_plugins with a single working plugin twice"""
    cfg = build_config([
            ('mediagoblin', {}, []),
            ('plugins', {}, [
                    ('mediagoblin.plugins.sampleplugin', {}, []),
                    ('mediagoblin.plugins.sampleplugin', {}, []),
                    ])
            ])

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we only found one plugin
    eq_(len(pman.plugins), 1)
    # Make sure the plugin is the one we think it is.
    eq_(pman.plugins[0], 'mediagoblin.plugins.sampleplugin')
    # Make sure there was one hook registered
    eq_(len(pman.hooks), 1)
    # Make sure _setup_plugin_called was called once
    import mediagoblin.plugins.sampleplugin
    eq_(mediagoblin.plugins.sampleplugin._setup_plugin_called, 1)
Beispiel #2
0
def test_no_plugins():
    """Run setup_plugins with no plugins in config"""
    cfg = build_config([('mediagoblin', {}, [])])
    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we didn't load anything.
    assert len(pman.plugins) == 0
Beispiel #3
0
def test_no_plugins():
    """Run setup_plugins with no plugins in config"""
    cfg = build_config([('mediagoblin', {}, [])])
    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we didn't load anything.
    eq_(len(pman.plugins), 0)
Beispiel #4
0
def test_hook_transform():
    """
    Test the hook_transform method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    assert pluginapi.hook_transform("expand_tuple",
                                    (-1, 0)) == (-1, 0, 1, 2, 3)
Beispiel #5
0
def test_hook_transform():
    """
    Test the hook_transform method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    assert pluginapi.hook_transform(
        "expand_tuple", (-1, 0)) == (-1, 0, 1, 2, 3)
Beispiel #6
0
def test_disabled_plugin():
    """Run setup_plugins with a single working plugin twice"""
    cfg = build_config([('mediagoblin', {}, []),
                        ('plugins', {}, [
                            ('-mediagoblin.plugins.sampleplugin', {}, []),
                        ])])

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we didn't load the plugin
    assert len(pman.plugins) == 0
Beispiel #7
0
def test_disabled_plugin():
    """Run setup_plugins with a single working plugin twice"""
    cfg = build_config([
            ('mediagoblin', {}, []),
            ('plugins', {}, [
                    ('-mediagoblin.plugins.sampleplugin', {}, []),
                    ])
            ])

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we didn't load the plugin
    eq_(len(pman.plugins), 0)
Beispiel #8
0
def test_hook_runall():
    """
    Test the hook_runall method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    # Just one hook, check results
    call_log = []
    assert pluginapi.hook_runall(
        "just_one", call_log) == ["Called just once"]
    assert call_log == ["expect this one call"]

    # None provided, check results
    call_log = []
    assert pluginapi.hook_runall(
        "nothing_handling", call_log) == []
    assert call_log == []

    # Multiple provided, check results
    call_log = []
    assert pluginapi.hook_runall(
        "multi_handle", call_log) == [
            "the first returns",
            "the second returns",
            "the third returns",
        ]
    assert call_log == [
        "Hi, I'm the first",
        "Hi, I'm the second",
        "Hi, I'm the third"]

    # Multiple provided, one has CantHandleIt, check results
    call_log = []
    assert pluginapi.hook_runall(
        "multi_handle_with_canthandle", call_log) == [
            "the second returns",
            "the third returns",
        ]
    assert call_log == [
        "Hi, I'm the second",
        "Hi, I'm the third"]
Beispiel #9
0
def test_hook_handle():
    """
    Test the hook_handle method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    # Just one hook provided
    call_log = []
    assert pluginapi.hook_handle(
        "just_one", call_log) == "Called just once"
    assert call_log == ["expect this one call"]

    # Nothing provided and unhandled not okay
    call_log = []
    pluginapi.hook_handle(
        "nothing_handling", call_log) == None
    assert call_log == []

    # Nothing provided and unhandled okay
    call_log = []
    assert pluginapi.hook_handle(
        "nothing_handling", call_log, unhandled_okay=True) is None
    assert call_log == []
    
    # Multiple provided, go with the first!
    call_log = []
    assert pluginapi.hook_handle(
        "multi_handle", call_log) == "the first returns"
    assert call_log == ["Hi, I'm the first"]

    # Multiple provided, one has CantHandleIt
    call_log = []
    assert pluginapi.hook_handle(
        "multi_handle_with_canthandle",
        call_log) == "the second returns"
    assert call_log == ["Hi, I'm the second"]
Beispiel #10
0
def test_one_plugin():
    """Run setup_plugins with a single working plugin"""
    cfg = build_config([('mediagoblin', {}, []),
                        ('plugins', {}, [('mediagoblin.plugins.sampleplugin',
                                          {}, [])])])

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we only found one plugin
    assert len(pman.plugins) == 1
    # Make sure the plugin is the one we think it is.
    assert pman.plugins[0] == 'mediagoblin.plugins.sampleplugin'
    # Make sure there was one hook registered
    assert len(pman.hooks) == 1
    # Make sure _setup_plugin_called was called once
    import mediagoblin.plugins.sampleplugin
    assert mediagoblin.plugins.sampleplugin._setup_plugin_called == 1
Beispiel #11
0
def test_hook_runall():
    """
    Test the hook_runall method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    # Just one hook, check results
    call_log = []
    assert pluginapi.hook_runall("just_one", call_log) == ["Called just once"]
    assert call_log == ["expect this one call"]

    # None provided, check results
    call_log = []
    assert pluginapi.hook_runall("nothing_handling", call_log) == []
    assert call_log == []

    # Multiple provided, check results
    call_log = []
    assert pluginapi.hook_runall("multi_handle", call_log) == [
        "the first returns",
        "the second returns",
        "the third returns",
    ]
    assert call_log == [
        "Hi, I'm the first", "Hi, I'm the second", "Hi, I'm the third"
    ]

    # Multiple provided, one has CantHandleIt, check results
    call_log = []
    assert pluginapi.hook_runall("multi_handle_with_canthandle", call_log) == [
        "the second returns",
        "the third returns",
    ]
    assert call_log == ["Hi, I'm the second", "Hi, I'm the third"]
Beispiel #12
0
def test_hook_handle():
    """
    Test the hook_handle method
    """
    cfg = build_config(CONFIG_ALL_CALLABLES)

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    setup_plugins()

    # Just one hook provided
    call_log = []
    assert pluginapi.hook_handle("just_one", call_log) == "Called just once"
    assert call_log == ["expect this one call"]

    # Nothing provided and unhandled not okay
    call_log = []
    pluginapi.hook_handle("nothing_handling", call_log) == None
    assert call_log == []

    # Nothing provided and unhandled okay
    call_log = []
    assert pluginapi.hook_handle(
        "nothing_handling", call_log, unhandled_okay=True) is None
    assert call_log == []

    # Multiple provided, go with the first!
    call_log = []
    assert pluginapi.hook_handle("multi_handle",
                                 call_log) == "the first returns"
    assert call_log == ["Hi, I'm the first"]

    # Multiple provided, one has CantHandleIt
    call_log = []
    assert pluginapi.hook_handle("multi_handle_with_canthandle",
                                 call_log) == "the second returns"
    assert call_log == ["Hi, I'm the second"]
Beispiel #13
0
def test_one_plugin():
    """Run setup_plugins with a single working plugin"""
    cfg = build_config([
            ('mediagoblin', {}, []),
            ('plugins', {}, [
                    ('mediagoblin.plugins.sampleplugin', {}, [])
                    ])
            ])

    mg_globals.app_config = cfg['mediagoblin']
    mg_globals.global_config = cfg

    pman = pluginapi.PluginManager()
    setup_plugins()

    # Make sure we only found one plugin
    assert len(pman.plugins) == 1
    # Make sure the plugin is the one we think it is.
    assert pman.plugins[0] == 'mediagoblin.plugins.sampleplugin'
    # Make sure there was one hook registered
    assert len(pman.hooks) == 1
    # Make sure _setup_plugin_called was called once
    import mediagoblin.plugins.sampleplugin
    assert mediagoblin.plugins.sampleplugin._setup_plugin_called == 1
Beispiel #14
0
    def __init__(self, config_path, setup_celery=True):
        """
        Initialize the application based on a configuration file.

        Arguments:
         - config_path: path to the configuration file we're opening.
         - setup_celery: whether or not to setup celery during init.
           (Note: setting 'celery_setup_elsewhere' also disables
           setting up celery.)
        """
        _log.info("GNU MediaGoblin %s main server starting", __version__)
        _log.debug("Using config file %s", config_path)
        ##############
        # Setup config
        ##############

        # Open and setup the config
        global_config, app_config = setup_global_and_app_config(config_path)

        media_type_warning()

        setup_crypto()

        ##########################################
        # Setup other connections / useful objects
        ##########################################

        # Setup Session Manager, not needed in celery
        self.session_manager = session.SessionManager()

        # load all available locales
        setup_locales()

        # Set up plugins -- need to do this early so that plugins can
        # affect startup.
        _log.info("Setting up plugins.")
        setup_plugins()

        # Set up the database
        self.db = setup_database(app_config['run_migrations'])

        # Quit app if need to run dbupdate
        check_db_up_to_date()

        # Register themes
        self.theme_registry, self.current_theme = register_themes(app_config)

        # Get the template environment
        self.template_loader = get_jinja_loader(
            app_config.get('local_templates'),
            self.current_theme,
            PluginManager().get_template_paths()
            )

        # Check if authentication plugin is enabled and respond accordingly.
        self.auth = check_auth_enabled()
        if not self.auth:
            app_config['allow_comments'] = False

        # Set up storage systems
        self.public_store, self.queue_store = setup_storage()

        # set up routing
        self.url_map = get_url_map()

        # set up staticdirector tool
        self.staticdirector = get_staticdirector(app_config)

        # Setup celery, if appropriate
        if setup_celery and not app_config.get('celery_setup_elsewhere'):
            if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true':
                setup_celery_from_config(
                    app_config, global_config,
                    force_celery_always_eager=True)
            else:
                setup_celery_from_config(app_config, global_config)

        #######################################################
        # Insert appropriate things into mediagoblin.mg_globals
        #
        # certain properties need to be accessed globally eg from
        # validators, etc, which might not access to the request
        # object.
        #######################################################

        setup_globals(app=self)

        # Workbench *currently* only used by celery, so this only
        # matters in always eager mode :)
        setup_workbench()

        # instantiate application meddleware
        self.meddleware = [common.import_component(m)(self)
                           for m in meddleware.ENABLED_MEDDLEWARE]