Ejemplo n.º 1
0
def wsgi(request):
    """
    (Functional Testing) Sets up a full-stacked singleton WSGI app

    :param request: The pytest context

    :returns: a WSGI application
    """
    import tempfile
    import shutil
    import six
    from occams import main

    # The pyramid_who plugin requires a who file, so let's create a
    # barebones files for it...
    who_ini = tempfile.NamedTemporaryFile()
    who = six.moves.configparser.ConfigParser()
    who.add_section('general')
    who.set('general', 'request_classifier',
            'repoze.who.classifiers:default_request_classifier')
    who.set('general', 'challenge_decider',
            'repoze.who.classifiers:default_challenge_decider')
    who.set('general', 'remote_user_key', 'REMOTE_USER')
    who.write(who_ini)
    who_ini.flush()

    db_url = request.config.getoption('--db')
    redis_url = request.config.getoption('--redis')

    tmp_dir = tempfile.mkdtemp()

    wsgi = main(
        {},
        **{
            'redis.url': redis_url,
            'redis.sessions.url': redis_url,
            'redis.sessions.secret': 'sekrit',
            'who.config_file': who_ini.name,
            'who.identifier_id': '',

            # Enable regular error messages so we can see useful traceback
            'debugtoolbar.enabled': True,
            'pyramid.debug_all': True,
            'webassets.debug': True,
            'occams.apps': 'occams_forms',
            'occams.db.url': db_url,
            'occams.groups': [],
            'celery.broker.url': redis_url,
            'celery.backend.url': redis_url,
            'celery.blame': 'celery@localhost',
        })

    who_ini.close()

    def cleanup():
        shutil.rmtree(tmp_dir)

    request.addfinalizer(cleanup)

    return wsgi
Ejemplo n.º 2
0
def wsgi(request):
    """
    (Functional Testing) Sets up a full-stacked singleton WSGI app

    :param request: The pytest context

    :returns: a WSGI application
    """
    import tempfile
    import shutil
    import six
    from occams import main

    # The pyramid_who plugin requires a who file, so let's create a
    # barebones files for it...
    who_ini = tempfile.NamedTemporaryFile()
    who = six.moves.configparser.ConfigParser()
    who.add_section('general')
    who.set('general', 'request_classifier',
            'repoze.who.classifiers:default_request_classifier')
    who.set('general', 'challenge_decider',
            'repoze.who.classifiers:default_challenge_decider')
    who.set('general', 'remote_user_key', 'REMOTE_USER')
    who.write(who_ini)
    who_ini.flush()

    db_url = request.config.getoption('--db')

    tmp_dir = tempfile.mkdtemp()

    wsgi = main({}, **{
        'redis.url': REDIS_URL,
        'redis.sessions.secret': 'sekrit',

        'who.config_file': who_ini.name,
        'who.identifier_id': '',

        # Enable regular error messages so we can see useful traceback
        'debugtoolbar.enabled': True,
        'pyramid.debug_all': True,

        'webassets.debug': True,

        'occams.apps': 'occams_lims',

        'occams.db.url': db_url,
        'occams.groups': [],

        'celery.broker.url': REDIS_URL,
        'celery.backend.url': REDIS_URL,
        'celery.blame': 'celery@localhost',
    })

    who_ini.close()

    def cleanup():
        shutil.rmtree(tmp_dir)

    request.addfinalizer(cleanup)

    return wsgi
Ejemplo n.º 3
0
def wsgi(request):
    """
    (Functional Testing) Sets up a full-stacked singleton WSGI app

    :param request: The pytest context

    :returns: a WSGI application
    """
    import os
    import tempfile
    import shutil
    import sqlalchemy as sa
    import six
    from occams import main
    from occams_roster import models as roster

    # The pyramid_who plugin requires a who file, so let's create a
    # barebones files for it...
    who_ini = tempfile.NamedTemporaryFile()
    who = six.moves.configparser.ConfigParser()
    who.add_section('general')
    who.set('general', 'request_classifier',
            'repoze.who.classifiers:default_request_classifier')
    who.set('general', 'challenge_decider',
            'repoze.who.classifiers:default_challenge_decider')
    who.set('general', 'remote_user_key', 'REMOTE_USER')
    who.write(who_ini)
    who_ini.flush()

    db_url = request.config.getoption('--db')

    tmp_dir = tempfile.mkdtemp()

    roster_path = os.path.join(tmp_dir, 'roster.db')
    roster_url = 'sqlite:///{}'.format(roster_path)

    roster_engine = sa.create_engine(roster_url)
    roster.Base.metadata.create_all(roster_engine)

    wsgi = main({}, **{
        'redis.url': REDIS_URL,
        'redis.sessions.secret': 'sekrit',

        'who.config_file': who_ini.name,
        'who.identifier_id': '',

        # Enable regular error messages so we can see useful traceback
        'debugtoolbar.enabled': True,
        'pyramid.debug_all': True,

        'webassets.debug': True,

        'occams.apps': ['occams_studies', 'occams_roster'],

        'occams.db.url': db_url,
        'occams.groups': [],

        'celery.broker.url': REDIS_URL,
        'celery.backend.url': REDIS_URL,
        'celery.blame': 'celery@localhost',

        'studies.export.dir': '/tmp',
        'studies.export.plans': [
            'occams_studies.exports.pid.PidPlan',
            'occams_studies.exports.enrollment.EnrollmentPlan',
            'occams_studies.exports.visit.VisitPlan',
            'occams_studies.exports.schema.SchemaPlan.list_all',
        ],
        'studies.pid.package': 'occams_roster',
        'studies.blob.dir': '/tmp',

        'roster.db.url': roster_url,
    })

    who_ini.close()

    def cleanup():
        os.unlink(roster_path)
        shutil.rmtree(tmp_dir)

    request.addfinalizer(cleanup)

    return wsgi
Ejemplo n.º 4
0
def wsgi(request):
    """
    (Functional Testing) Sets up a full-stacked singleton WSGI app

    :param request: The pytest context

    :returns: a WSGI application
    """
    import os
    import tempfile
    import shutil
    import sqlalchemy as sa
    import six
    from occams import main
    from occams_roster import models as roster

    # The pyramid_who plugin requires a who file, so let's create a
    # barebones files for it...
    who_ini = tempfile.NamedTemporaryFile()
    who = six.moves.configparser.ConfigParser()
    who.add_section('general')
    who.set('general', 'request_classifier',
            'repoze.who.classifiers:default_request_classifier')
    who.set('general', 'challenge_decider',
            'repoze.who.classifiers:default_challenge_decider')
    who.set('general', 'remote_user_key', 'REMOTE_USER')
    who.write(who_ini)
    who_ini.flush()

    db_url = request.config.getoption('--db')

    tmp_dir = tempfile.mkdtemp()

    roster_path = os.path.join(tmp_dir, 'roster.db')
    roster_url = 'sqlite:///{}'.format(roster_path)

    roster_engine = sa.create_engine(roster_url)
    roster.Base.metadata.create_all(roster_engine)

    wsgi = main(
        {},
        **{
            'redis.url':
            REDIS_URL,
            'redis.sessions.secret':
            'sekrit',
            'who.config_file':
            who_ini.name,
            'who.identifier_id':
            '',

            # Enable regular error messages so we can see useful traceback
            'debugtoolbar.enabled':
            True,
            'pyramid.debug_all':
            True,
            'webassets.debug':
            True,
            'occams.apps': ['occams_studies', 'occams_roster'],
            'occams.db.url':
            db_url,
            'occams.groups': [],
            'celery.broker.url':
            REDIS_URL,
            'celery.backend.url':
            REDIS_URL,
            'celery.blame':
            'celery@localhost',
            'studies.export.dir':
            '/tmp',
            'studies.export.plans': [
                'occams_studies.exports.pid.PidPlan',
                'occams_studies.exports.enrollment.EnrollmentPlan',
                'occams_studies.exports.visit.VisitPlan',
                'occams_studies.exports.schema.SchemaPlan.list_all',
            ],
            'studies.pid.package':
            'occams_roster',
            'studies.blob.dir':
            '/tmp',
            'roster.db.url':
            roster_url,
        })

    who_ini.close()

    def cleanup():
        os.unlink(roster_path)
        shutil.rmtree(tmp_dir)

    request.addfinalizer(cleanup)

    return wsgi