Ejemplo n.º 1
0
def setup_module(module):
    engine = sqlalchemy.create_engine('sqlite:///:memory:')
    Session.configure(bind=engine)
    Base.metadata.create_all(engine)

    morepath.scan(morepath_sqlalchemy)
    morepath.commit(App)
Ejemplo n.º 2
0
def test_scenario():
    morepath.scan(scenario)

    c = Client(app.Root())

    response = c.get('/document')
    assert response.body == b'Document root'

    response = c.get('/foo')
    assert response.body == b'Generic root'

    response = c.get('/document/a')
    assert response.body == b'Document model a'

    response = c.get('/foo/a')
    assert response.body == b'Generic model a'

    response = c.get('/')
    assert response.json == ['http://localhost/foo/a',
                             'http://localhost/document/b']

    response = c.get('/foo/a/link')
    assert response.body == b'http://localhost/document/c'

    response = c.get('/document/a/link')
    assert response.body == b'http://localhost/foo/d'
Ejemplo n.º 3
0
def make_wsgi_app(settings_filepath=None, testing=False):
    with start_action(action_type='morepath_scan'):
        morepath.autoscan()
        morepath.scan(ekklesia_portal)

    if testing:
        log_message(
            message_type="testing",
            msg="running in testing mode, not loading any config from file")
    else:
        with start_action(action_type='settings'):
            settings = get_app_settings(settings_filepath)
            App._loaded_settings = settings
            App.init_settings(settings)

    with start_action(action_type='make_app'):
        App.commit()
        app = App()

    database.configure_sqlalchemy(app.settings.database, testing)
    app.babel_init()
    app.babel.localeselector(get_locale)
    log_message(message_type="environment",
                env=dict(os.environ),
                encoding=locale.getpreferredencoding(),
                default_locale=locale.getdefaultlocale())
    return app
Ejemplo n.º 4
0
def test_scenario():
    morepath.scan(scenario)

    c = Client(app.Root())

    response = c.get("/document")
    assert response.body == b"Document root"

    response = c.get("/foo")
    assert response.body == b"Generic root"

    response = c.get("/document/a")
    assert response.body == b"Document model a"

    response = c.get("/foo/a")
    assert response.body == b"Generic model a"

    response = c.get("/")
    assert response.json == [
        "http://localhost/foo/a",
        "http://localhost/document/b",
    ]

    response = c.get("/foo/a/link")
    assert response.body == b"http://localhost/document/c"

    response = c.get("/document/a/link")
    assert response.body == b"http://localhost/foo/d"
Ejemplo n.º 5
0
def test_scenario():
    morepath.scan(scenario)

    c = Client(app.Root())

    response = c.get('/document')
    assert response.body == b'Document root'

    response = c.get('/foo')
    assert response.body == b'Generic root'

    response = c.get('/document/a')
    assert response.body == b'Document model a'

    response = c.get('/foo/a')
    assert response.body == b'Generic model a'

    response = c.get('/')
    assert response.json == [
        'http://localhost/foo/a', 'http://localhost/document/b'
    ]

    response = c.get('/foo/a/link')
    assert response.body == b'http://localhost/document/c'

    response = c.get('/document/a/link')
    assert response.body == b'http://localhost/foo/d'
Ejemplo n.º 6
0
def test_root():
    morepath.scan(synonymista_api)
    morepath.commit(synonymista_api.App)

    client = Client(synonymista_api.App())
    root = client.get('/')

    assert root.status_code == 200
    assert len(root.json['greetings']) == 2
Ejemplo n.º 7
0
def test_root():
    morepath.scan(rassle)
    morepath.commit(rassle.App)

    client = Client(rassle.App())
    root = client.get('/')

    assert root.status_code == 200
    assert '/greeting/world' in root
    assert '/greeting/mundo' in root
Ejemplo n.º 8
0
def test_root():
    morepath.scan(ntv.api)
    morepath.commit(ntv.api.App)

    client = Client(ntv.api.App())
    root = client.get('/')

    assert root.status_code == 200
    assert len(root.json) == 1
    resource = root.json[0]
    assert '@id' in resource
Ejemplo n.º 9
0
def test_get_games():
    """ Test getting a collection of games
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App)

    api_client = Client(falchion.App())

    response = api_client.get('/games')

    assert response.status_code == 200
    assert len(response.json['games']) == 14
Ejemplo n.º 10
0
def test_get_game_tags():
    """ Test retrieving tags for a game
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App)

    api_client = Client(falchion.App())

    response = api_client.get('/games/10')

    assert response.status_code == 200
    assert 'jrpg' in response.json['tags']
Ejemplo n.º 11
0
def test_get_game_status():
    """ Test retrieving status for a game
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App())

    api_client = Client(falchion.App())

    response = api_client.get('/games/2')

    assert response.status_code == 200
    assert response.json['status'] == 'unfinished'
Ejemplo n.º 12
0
def test_get_game_achievements():
    """ Test retrieving achievements for a game
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App())

    api_client = Client(falchion.App())

    response = api_client.get('/games/10')

    assert response.status_code == 200
    assert len(response.json['achievements']) == 2
Ejemplo n.º 13
0
def test_get_game_by_id():
    """ Test getting a single game by ID
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App)

    api_client = Client(falchion.App())

    response = api_client.get('/games/1')

    assert response.status_code == 200
    assert response.json['name'] == 'Shovel Knight'
Ejemplo n.º 14
0
def test_get_game_achievement_counts():
    """ Test retrieving achievement counts for a game
    """
    morepath.scan(falchion)
    morepath.commit(falchion.App())

    api_client = Client(falchion.App())

    response = api_client.get('/games/10')

    assert response.status_code == 200
    assert response.json['achievements']['completed'] == 500
    assert response.json['achievements']['total'] == 1200
Ejemplo n.º 15
0
def initdb():
    click.echo('Initialize database...')
    morepath.autoscan()
    morepath.scan()
    App.commit()
    app = App()
    # create database
    dbsession = app.get_dbsession_service()
    Base.metadata.create_all(dbsession.bind)
    # add users
    users = app.get_user_service()
    with transaction.manager:
        for user in USERS:
            users.add(**user)
        transaction.commit()
Ejemplo n.º 16
0
def make_wsgi_app(settings_filepath=None, testing=False):
    with start_action(action_type='morepath_scan'):
        morepath.autoscan()
        morepath.scan(ekklesia_voting)

    with start_action(action_type='settings'):
        settings = get_app_settings(settings_filepath)
        App.init_settings(settings)

    with start_action(action_type='make_app'):
        App.commit()
        app = App()

    database.configure_sqlalchemy(app.settings.database, testing)
    app.babel_init()
    app.babel.localeselector(get_locale)
    return app
Ejemplo n.º 17
0
def get_democms_client():

    morepath.scan(morpfw)
    morepath.scan(morpcc)
    morepath.scan(democms)

    settings_file = os.path.join(os.path.dirname(__file__),
                                 "democms/settings.yml")
    with open(settings_file) as sf:
        settings = yaml.load(sf, Loader=yaml.Loader)

    settings["configuration"][
        "morpfw.storage.sqlstorage.dburl"] = "postgresql://postgres@localhost:45678/morpcc_tests"

    settings["configuration"][
        "morpfw.storage.sqlstorage.dburl.warehouse"] = "postgresql://postgres@localhost:45678/morpcc_warehouse"

    settings["configuration"]["morpfw.beaker.session.type"] = "memory"
    settings["configuration"]["morpfw.beaker.cache.type"] = "memory"

    test_settings = tempfile.mktemp()
    with open(test_settings, "w") as ts:
        yaml.dump(settings, ts)

    c = get_client(test_settings)
    os.unlink(test_settings)

    req = c.mfw_request
    morpsql.Base.metadata.create_all(bind=req.db_session.bind)

    create_admin(req, "admin", "password", "*****@*****.**")

    return c
Ejemplo n.º 18
0
def test_forwarded_app():
    morepath.scan(more.forwarded)

    class App(ForwardedApp):
        pass

    @App.path(path='foo')
    class Root(object):
        pass

    @App.view(model=Root)
    def root_default(self, request):
        return request.link(self)

    App.commit()

    c = Client(App())

    response = c.get('/foo',
                     headers={'Forwarded': 'host=www.example.com'})

    assert response.body == b'http://www.example.com/foo'
Ejemplo n.º 19
0
def test_rescan():
    morepath.scan(basic)

    assert basic.app.commit() == {basic.app}

    morepath.scan(basic)

    class Sub(basic.app):
        pass

    @Sub.view(model=basic.Model, name='extra')
    def extra(self, request):
        return "extra"

    assert Sub.commit() == {Sub}

    c = Client(Sub())

    response = c.get('/1/extra')
    assert response.body == b'extra'

    response = c.get('/1')
    assert response.body == b'The view for model: 1'
Ejemplo n.º 20
0
def setup_module(module):
    morepath.scan(morepath_reactredux)
    morepath.commit(App)
Ejemplo n.º 21
0
def setup_module(module):
    morepath.scan(server)
    morepath.commit(App)
Ejemplo n.º 22
0
def spawn_test_app(tempdir):
    prepare_fixtures(tempdir)

    html = """
        <html>
            <head></head>
            <body>
                <p>Bar</p>
            </body>
        </html>
    """

    def render_plain(content, request):
        response = morepath.Response(content)
        response.content_type = 'text/plain'
        return response

    class App(WebassetsApp):
        pass

    @App.webasset_path()
    def get_default_assets_path():
        return os.path.join(tempdir, 'common')

    @App.webasset_path()
    def get_theme_assets_path():
        return os.path.join(tempdir, 'theme')

    @App.webasset_output()
    def get_output_path():
        return os.path.join(tempdir, 'output')

    @App.webasset_filter('js')
    def get_js_filter():
        return 'rjsmin'

    @App.webasset_filter('scss')
    def get_scss_filter():
        return 'pyscss'

    @App.webasset(name='common')
    def get_common_assets():
        yield 'jquery.js'
        yield 'underscore.js'

    @App.webasset(name='extra')
    def get_extra_asset():
        yield 'extra.js'

    @App.webasset(name='theme')
    def get_theme_asset():
        yield 'main.scss'

    @App.path('')
    class Root(object):
        pass

    @App.html(model=Root)
    def index(self, request):
        bundle = request.params.get('bundle')

        if bundle:
            request.include(bundle)

        return html

    @App.view(model=Root, name='plain', render=render_plain)
    def plain(self, request):
        request.include('common')
        return html

    @App.html(model=Root, name='put', request_method='PUT')
    def put(self, request):
        request.include('common')
        return html

    @App.html(model=Root, name='alljs')
    def alljs(self, request):
        request.include('common')
        request.include('extra')
        return html

    morepath.scan(more.webassets)
    morepath.commit(App)

    return App()
Ejemplo n.º 23
0
def spawn_test_app(tempdir):
    prepare_fixtures(tempdir)

    html = """
        <html>
            <head></head>
            <body>
                <p>Bar</p>
            </body>
        </html>
    """

    def render_plain(content, request):
        response = morepath.Response(content)
        response.content_type = 'text/plain'
        return response

    class App(WebassetsApp):
        pass

    @App.webasset_path()
    def get_default_assets_path():
        return os.path.join(tempdir, 'common')

    @App.webasset_path()
    def get_theme_assets_path():
        return os.path.join(tempdir, 'theme')

    @App.webasset_output()
    def get_output_path():
        return os.path.join(tempdir, 'output')

    @App.webasset_filter('js')
    def get_js_filter():
        return 'rjsmin'

    @App.webasset_filter('scss')
    def get_scss_filter():
        return 'pyscss'

    @App.webasset(name='common')
    def get_common_assets():
        yield 'jquery.js'
        yield 'underscore.js'

    @App.webasset(name='extra')
    def get_extra_asset():
        yield 'extra.js'

    @App.webasset(name='theme')
    def get_theme_asset():
        yield 'main.scss'

    @App.path('')
    class Root(object):
        pass

    @App.html(model=Root)
    def index(self, request):
        bundle = request.params.get('bundle')

        if bundle:
            request.include(bundle)

        return html

    @App.view(model=Root, name='plain', render=render_plain)
    def plain(self, request):
        request.include('common')
        return html

    @App.html(model=Root, name='put', request_method='PUT')
    def put(self, request):
        request.include('common')
        return html

    @App.html(model=Root, name='alljs')
    def alljs(self, request):
        request.include('common')
        request.include('extra')
        return html

    morepath.scan(more.webassets)
    morepath.commit(App)

    return App()
Ejemplo n.º 24
0
# up to hold just those tables targeting a
# particular database. table.tometadata() may be
# helpful here in case a "copy" of
# a MetaData is needed.
# from myapp import mymodel
# target_metadata = {
#       'engine1':mymodel.metadata1,
#       'engine2':mymodel.metadata2
# }

from morpfw.crud.storage.sqlstorage import Base
import morpcc.tests.democms
import morepath

morepath.autoscan()
morepath.scan(morpcc.tests.democms)
target_metadata = {'default': Base.metadata}

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.
Ejemplo n.º 25
0
def setup_module(module):
    morepath.scan(server)
    morepath.commit(App)
Ejemplo n.º 26
0
def test_scanned_some_error():
    with pytest.raises(ZeroDivisionError):
        morepath.scan(pkg)
Ejemplo n.º 27
0
def do_scan():
    import morepath
    morepath.scan()
Ejemplo n.º 28
0
def setup_module(module):
    morepath.scan(app)
    morepath.commit(App)
Ejemplo n.º 29
0
def wsgi_factory():
    morepath.autoscan()
    morepath.scan()
    morepath.commit()
    return App()
Ejemplo n.º 30
0
def wsgi_factory():
    morepath.autoscan()
    morepath.scan()
    App.commit()
    return App()
Ejemplo n.º 31
0
def setup_module(module):
    morepath.scan(morepath_rest_dump_load)
    morepath.commit(App)
Ejemplo n.º 32
0
def create_baseapp(app, settings, scan=True, **kwargs):

    s = copy.deepcopy(default_settings)
    for k in settings.keys():
        if k in s.keys():
            for j, v in settings[k].items():
                s[k][j] = v
        else:
            s[k] = settings[k]

    settings = s

    # initialize app

    if scan:
        morepath.autoscan()
        for scanmodpath in (settings['morpfw']['scan'] or []):
            scanmod = importlib.import_module(scanmodpath)
            morepath.scan(package=scanmod)

    app_settings = settings['application']

    authnpolicy_settings = app_settings['authn_policy_settings']
    authnpol_mod, authnpol_clsname = (
        app_settings['authn_policy'].strip().split(':'))

    authnpolicy = getattr(importlib.import_module(authnpol_mod),
                          authnpol_clsname)(authnpolicy_settings)

    get_identity_policy = authnpolicy.get_identity_policy
    verify_identity = authnpolicy.verify_identity

    mounted_apps = app_settings['mounted_apps']
    if getattr(authnpolicy, 'app_cls', None):
        mounted_apps.append({
            'app_cls':
            authnpolicy.app_cls,
            'authn_policy':
            app_settings['authn_policy'],
            'authn_policy_settings':
            app_settings['authn_policy_settings']
        })
    for iapp in mounted_apps:
        if 'app_cls' in iapp.keys():
            iapp_cls = iapp['app_cls']
        else:
            iapp_path = iapp['app']
            iapp_mod, iapp_clsname = iapp_path.strip().split(':')
            iapp_cls = getattr(importlib.import_module(iapp_mod), iapp_clsname)

        if iapp.get('authn_policy', None):
            iapp_authnpolicy_settings = iapp.get('authn_policy_settings', {})
            iapp_authnpol_mod, iapp_authnpol_clsname = (
                iapp['authn_policy'].strip().split(':'))
            iapp_authnpolicy = getattr(
                importlib.import_module(iapp_authnpol_mod),
                iapp_authnpol_clsname)(iapp_authnpolicy_settings)
            iapp_get_identity_policy = iapp_authnpolicy.get_identity_policy
            iapp_verify_identity = iapp_authnpolicy.verify_identity
            iapp_cls.identity_policy()(iapp_get_identity_policy)
            iapp_cls.verify_identity()(iapp_verify_identity)
            if getattr(iapp_cls, 'authn_provider', None):
                iapp_cls.authn_provider()(iapp_authnpolicy.get_app)
        else:
            iapp_cls.identity_policy()(get_identity_policy)
            iapp_cls.verify_identity()(verify_identity)
            if getattr(iapp_cls, 'authn_provider', None):
                iapp_cls.authn_provider()(authnpolicy.get_app)

        iapp_cls.init_settings(settings)
        iapp_cls._raw_settings = settings
        iapp_cls.commit()

    app.identity_policy()(get_identity_policy)
    app.verify_identity()(verify_identity)
    if authnpolicy.app_cls:
        app.authn_provider()(lambda: authnpolicy.app_cls())
    app.init_settings(settings)
    app._raw_settings = settings

    if settings['application']['development_mode']:
        os.environ['MOREPATH_TEMPLATE_AUTO_RELOAD'] = "1"

    app.commit()

    celery_settings = settings['worker']['celery_settings']
    app.celery.conf.update(**celery_settings)
    application = app()
    return application
Ejemplo n.º 33
0
def do_scan():
    import morepath

    morepath.scan()