Esempio n. 1
0
def startServer():
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    setupServer(test=True)

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    cherrypy.server.unsubscribe()
    cherrypy.engine.start()
Esempio n. 2
0
def startServer(mock=True, mockS3=False):
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    # If the server starts, a database will exist and we can remove it later
    dbName = cherrypy.config['database']['uri'].split('/')[-1]
    usedDBs[dbName] = True

    server = setupServer(test=True, plugins=enabledPlugins)

    if mock:
        cherrypy.server.unsubscribe()

    cherrypy.engine.start()

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    # Log all requests if we asked to do so
    if 'cherrypy' in os.environ.get('EXTRADEBUG', '').split():
        cherrypy.config.update({'log.screen': True})
        logHandler = logging.StreamHandler(sys.stdout)
        logHandler.setLevel(logging.DEBUG)
        cherrypy.log.error_log.addHandler(logHandler)

    # Tell CherryPy to throw exceptions in request handling code
    cherrypy.config.update({'request.throw_errors': True})

    mockSmtp.start()
    if mockS3:
        global mockS3Server
        mockS3Server = mock_s3.startMockS3Server()

    return server
Esempio n. 3
0
def startServer(mock=True, mockS3=False):
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    server = setupServer(test=True, plugins=enabledPlugins)

    if mock:
        cherrypy.server.unsubscribe()

    cherrypy.engine.start()

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    # Log all requests if we asked to do so
    if 'cherrypy' in os.environ.get('EXTRADEBUG', '').split():
        cherrypy.config.update({'log.screen': True})
        logHandler = logging.StreamHandler(sys.stdout)
        logHandler.setLevel(logging.DEBUG)
        cherrypy.log.error_log.addHandler(logHandler)

    mockSmtp.start()
    if mockS3:
        global mockS3Server
        mockS3Server = mock_s3.startMockS3Server()

    return server
Esempio n. 4
0
def startServer(mock=True, mockS3=False):
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    # If the server starts, a database will exist and we can remove it later
    dbName = cherrypy.config['database']['uri'].split('/')[-1]
    usedDBs[dbName] = True

    server = setupServer(test=True, plugins=enabledPlugins)

    if mock:
        cherrypy.server.unsubscribe()

    cherrypy.engine.start()

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    # Log all requests if we asked to do so
    if 'cherrypy' in os.environ.get('EXTRADEBUG', '').split():
        cherrypy.config.update({'log.screen': True})
        logHandler = logging.StreamHandler(sys.stdout)
        logHandler.setLevel(logging.DEBUG)
        cherrypy.log.error_log.addHandler(logHandler)

    # Tell CherryPy to throw exceptions in request handling code
    cherrypy.config.update({'request.throw_errors': True})

    mockSmtp.start()
    if mockS3:
        global mockS3Server
        mockS3Server = mock_s3.startMockS3Server()

    return server
Esempio n. 5
0
def startServer(mock=True, mockS3=False):
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    server = setupServer(test=True, plugins=enabledPlugins)

    if mock:
        cherrypy.server.unsubscribe()

    cherrypy.engine.start()

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    # Log all requests if we asked to do so
    if 'cherrypy' in os.environ.get('EXTRADEBUG', '').split():
        cherrypy.config.update({'log.screen': True})
        logHandler = logging.StreamHandler(sys.stdout)
        logHandler.setLevel(logging.DEBUG)
        cherrypy.log.error_log.addHandler(logHandler)

    mockSmtp.start()
    if mockS3:
        global mockS3Server
        mockS3Server = mock_s3.startMockS3Server()

    return server
Esempio n. 6
0
def server(db):
    """
    Require a CherryPy embedded server.

    Provides a started CherryPy embedded server with a request method for performing
    local requests against it. Note: this fixture requires the db fixture.
    """
    # The event daemon cannot be restarted since it is a threading.Thread object, however
    # all references to girder.events.daemon are a singular global daemon due to its side
    # effect on import. We have to hack around this by creating a unique event daemon
    # each time we startup the server and assigning it to the global.
    import girder.events
    from girder.utility.server import setup as setupServer

    girder.events.daemon = girder.events.AsyncEventsThread()

    server = setupServer(test=True)
    server.request = request

    cherrypy.server.unsubscribe()
    cherrypy.config.update({'environment': 'embedded', 'log.screen': False})
    cherrypy.engine.start()

    yield server

    cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
    cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
    cherrypy.engine.stop()
    cherrypy.engine.exit()
    cherrypy.tree.apps = {}
Esempio n. 7
0
def startServer(mock=True):
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    setupServer(test=True, plugins=enabledPlugins)

    # Make server quiet (won't announce start/stop or requests)
    cherrypy.config.update({'environment': 'embedded'})

    if mock:
        cherrypy.server.unsubscribe()

    cherrypy.engine.start()

    mockSmtp.start()
Esempio n. 8
0
def server(db, request):
    """
    Require a CherryPy embedded server.

    Provides a started CherryPy embedded server with a request method for performing
    local requests against it. Note: this fixture requires the db fixture.
    """
    # The event daemon cannot be restarted since it is a threading.Thread object, however
    # all references to girder.events.daemon are a singular global daemon due to its side
    # effect on import. We have to hack around this by creating a unique event daemon
    # each time we startup the server and assigning it to the global.
    import girder.events
    from girder.api import docs
    from girder.constants import SettingKey
    from girder.models.setting import Setting
    from girder.utility import plugin_utilities
    from girder.utility.server import setup as setupServer

    oldPluginDir = plugin_utilities.getPluginDir

    girder.events.daemon = girder.events.AsyncEventsThread()

    enabledPlugins = []
    testPluginMarkers = request.node.get_marker('testPlugin')
    if testPluginMarkers is not None:
        for testPluginMarker in testPluginMarkers:
            pluginName = testPluginMarker.args[0]
            enabledPlugins.append(pluginName)

        # testFilePath is a py.path.local object that we *assume* lives in 'test/',
        # with 'test/test_plugins' nearby
        testFilePath = request.node.fspath
        testPluginsPath = testFilePath.dirpath('test_plugins').strpath
        plugin_utilities.getPluginDir = mock.Mock(return_value=testPluginsPath)

        Setting().set(SettingKey.PLUGINS_ENABLED, enabledPlugins)

    server = setupServer(test=True, plugins=enabledPlugins)
    server.request = restRequest

    cherrypy.server.unsubscribe()
    cherrypy.config.update({'environment': 'embedded',
                            'log.screen': False,
                            'request.throw_errors': True})
    cherrypy.engine.start()

    yield server

    cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
    cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
    cherrypy.engine.stop()
    cherrypy.engine.exit()
    cherrypy.tree.apps = {}
    plugin_utilities.getPluginDir = oldPluginDir
    plugin_utilities.getPluginWebroots().clear()
    plugin_utilities.getPluginFailureInfo().clear()
    docs.routes.clear()
Esempio n. 9
0
def server(db, request):
    """
    Require a CherryPy embedded server.

    Provides a started CherryPy embedded server with a request method for performing
    local requests against it. Note: this fixture requires the db fixture.
    """
    # The event daemon cannot be restarted since it is a threading.Thread object, however
    # all references to girder.events.daemon are a singular global daemon due to its side
    # effect on import. We have to hack around this by creating a unique event daemon
    # each time we startup the server and assigning it to the global.
    import girder.events
    from girder.api import docs
    from girder.constants import SettingKey
    from girder.models.setting import Setting
    from girder.utility.server import setup as setupServer

    girder.events.daemon = girder.events.AsyncEventsThread()

    enabledPlugins = []
    hasPluginMarkers = request.node.get_marker('plugin') is not None
    pluginRegistry = PluginRegistry()

    with pluginRegistry():
        if hasPluginMarkers:
            for pluginMarker in request.node.iter_markers('plugin'):
                pluginName = pluginMarker.args[0]
                shouldEnable = pluginMarker.kwargs.pop('enabled', True)
                if len(pluginMarker.args) > 1:
                    pluginRegistry.registerTestPlugin(*pluginMarker.args,
                                                      **pluginMarker.kwargs)
                if shouldEnable:
                    enabledPlugins.append(pluginName)

        Setting().set(SettingKey.PLUGINS_ENABLED, enabledPlugins)

        server = setupServer(test=True, plugins=enabledPlugins)
        server.request = restRequest
        server.uploadFile = uploadFile

        cherrypy.server.unsubscribe()
        cherrypy.config.update({
            'environment': 'embedded',
            'log.screen': False,
            'request.throw_errors': True
        })
        cherrypy.engine.start()

        yield server

        cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
        cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
        cherrypy.engine.stop()
        cherrypy.engine.exit()
        cherrypy.tree.apps = {}
        docs.routes.clear()
Esempio n. 10
0
def server(db, request):
    """
    Require a CherryPy embedded server.

    Provides a started CherryPy embedded server with a request method for performing
    local requests against it. Note: this fixture requires the db fixture.
    """
    # The event daemon cannot be restarted since it is a threading.Thread object, however
    # all references to girder.events.daemon are a singular global daemon due to its side
    # effect on import. We have to hack around this by creating a unique event daemon
    # each time we startup the server and assigning it to the global.
    import girder.events
    from girder.api import docs
    from girder.constants import SettingKey
    from girder.models.setting import Setting
    from girder.utility.server import setup as setupServer

    girder.events.daemon = girder.events.AsyncEventsThread()

    enabledPlugins = []
    hasPluginMarkers = request.node.get_marker('plugin') is not None
    pluginRegistry = PluginRegistry()

    with pluginRegistry():
        if hasPluginMarkers:
            for pluginMarker in request.node.iter_markers('plugin'):
                pluginName = pluginMarker.args[0]
                shouldEnable = pluginMarker.kwargs.pop('enabled', True)
                if len(pluginMarker.args) > 1:
                    pluginRegistry.registerTestPlugin(
                        *pluginMarker.args, **pluginMarker.kwargs
                    )
                if shouldEnable:
                    enabledPlugins.append(pluginName)

        Setting().set(SettingKey.PLUGINS_ENABLED, enabledPlugins)

        server = setupServer(test=True, plugins=enabledPlugins)
        server.request = restRequest
        server.uploadFile = uploadFile

        cherrypy.server.unsubscribe()
        cherrypy.config.update({'environment': 'embedded',
                                'log.screen': False,
                                'request.throw_errors': True})
        cherrypy.engine.start()

        yield server

        cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
        cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
        cherrypy.engine.stop()
        cherrypy.engine.exit()
        cherrypy.tree.apps = {}
        docs.routes.clear()
Esempio n. 11
0
def server(db, request):
    """
    Require a CherryPy embedded server.

    Provides a started CherryPy embedded server with a request method for performing
    local requests against it. Note: this fixture requires the db fixture.
    """
    # The event daemon cannot be restarted since it is a threading.Thread object, however
    # all references to girder.events.daemon are a singular global daemon due to its side
    # effect on import. We have to hack around this by creating a unique event daemon
    # each time we startup the server and assigning it to the global.
    import girder.events
    from girder.constants import ROOT_DIR, SettingKey
    from girder.models.setting import Setting
    from girder.utility import plugin_utilities
    from girder.utility.server import setup as setupServer

    oldPluginDir = plugin_utilities.getPluginDir

    girder.events.daemon = girder.events.AsyncEventsThread()

    if request.node.get_marker('testPlugins'):
        # Load plugins from the test path
        path = os.path.join(ROOT_DIR, 'tests', 'test_plugins')

        plugin_utilities.getPluginDir = mock.Mock(return_value=path)
        plugins = request.node.get_marker('testPlugins').args[0]
        Setting().set(SettingKey.PLUGINS_ENABLED, plugins)
    else:
        plugins = []

    server = setupServer(test=True, plugins=plugins)
    server.request = restRequest

    cherrypy.server.unsubscribe()
    cherrypy.config.update({'environment': 'embedded',
                            'log.screen': False,
                            'request.throw_errors': True})
    cherrypy.engine.start()

    yield server

    cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
    cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
    cherrypy.engine.stop()
    cherrypy.engine.exit()
    cherrypy.tree.apps = {}
    plugin_utilities.getPluginDir = oldPluginDir
Esempio n. 12
0
def serverContext(plugins=None, bindPort=False):
    # The event daemon cannot be restarted since it is a threading.Thread
    # object, however all references to girder.events.daemon are a singular
    # global daemon due to its side effect on import. We have to hack around
    # this by creating a unique event daemon each time we startup the server
    # and assigning it to the global.
    import girder.events
    from girder.api import docs
    from girder.utility.server import setup as setupServer
    from girder.constants import ServerMode

    girder.events.daemon = girder.events.AsyncEventsThread()

    if plugins is None:
        # By default, pass "[]" to "plugins", disabling any installed plugins
        plugins = []
    server = setupServer(mode=ServerMode.TESTING, plugins=plugins)
    server.request = request
    server.uploadFile = uploadFile
    cherrypy.server.unsubscribe()
    if bindPort:
        cherrypy.server.subscribe()
        port = _findFreePort()
        cherrypy.config['server.socket_port'] = port
        server.boundPort = port
        # This is needed if cherrypy started once on another port
        cherrypy.server.socket_port = port
    cherrypy.config.update({
        'environment': 'embedded',
        'log.screen': False,
        'request.throw_errors': True
    })
    cherrypy.engine.start()

    try:
        yield server
    finally:
        cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
        cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
        cherrypy.engine.stop()
        cherrypy.engine.exit()
        cherrypy.tree.apps = {}
        # This is needed to allow cherrypy to restart on another port
        cherrypy.server.httpserver = None
        docs.routes.clear()
Esempio n. 13
0
def serverContext(plugins=None, bindPort=False):
    # The event daemon cannot be restarted since it is a threading.Thread
    # object, however all references to girder.events.daemon are a singular
    # global daemon due to its side effect on import. We have to hack around
    # this by creating a unique event daemon each time we startup the server
    # and assigning it to the global.
    import girder.events
    from girder.api import docs
    from girder.utility.server import setup as setupServer

    girder.events.daemon = girder.events.AsyncEventsThread()

    if plugins is None:
        # By default, pass "[]" to "plugins", disabling any installed plugins
        plugins = []
    server = setupServer(test=True, plugins=plugins)
    server.request = request
    server.uploadFile = uploadFile
    cherrypy.server.unsubscribe()
    if bindPort:
        cherrypy.server.subscribe()
        port = _findFreePort()
        cherrypy.config['server.socket_port'] = port
        server.boundPort = port
        # This is needed if cherrypy started once on another port
        cherrypy.server.socket_port = port
    cherrypy.config.update({'environment': 'embedded',
                            'log.screen': False,
                            'request.throw_errors': True})
    cherrypy.engine.start()

    try:
        yield server
    finally:
        cherrypy.engine.unsubscribe('start', girder.events.daemon.start)
        cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
        cherrypy.engine.stop()
        cherrypy.engine.exit()
        cherrypy.tree.apps = {}
        # This is needed to allow cherrypy to restart on another port
        cherrypy.server.httpserver = None
        docs.routes.clear()