How to use the muffin.Application function in muffin

To help you get started, we’ve selected a few muffin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / muffin / tests / test_muffin.py View on Github external
async def test_static(aiohttp_client):
    app = muffin.Application('test', STATIC_FOLDERS=[
        'tests/static1',
        'tests/static2',
    ])
    client = await aiohttp_client(app)

    resp = await client.get('/static/file1')
    assert resp.status == 200
    body = await resp.read()
    assert body == b'content1\n'

    resp = await client.get('/static/file2')
    assert resp.status == 200
    body = await resp.read()
    assert body == b'content2\n'
github klen / muffin / tests / test_plugins.py View on Github external
with pytest.raises(PluginException):
        BasePlugin()

    class Plugin(BasePlugin):
        name = 'plugin'
        defaults = {
            'debug': True
        }

    pl1 = Plugin(test=42)
    pl2 = Plugin(test=24)

    assert pl1 is pl2
    assert pl1.cfg.test == 42

    app = muffin.Application(__name__)
    app.install(pl1)
    assert pl1.name in app.ps
github klen / muffin / tests / test_handlers.py View on Github external
async def test_custom_methods(aiohttp_client):

    app = muffin.Application('test')

    @app.register('/caldav', methods='PROPFIND')
    def propfind(request):
        return b'PROPFIND'

    client = await aiohttp_client(app)

    resp = await client.request('PROPFIND', '/caldav')
    assert resp.status == 200

    text = await resp.text()
    assert text == 'PROPFIND'
    resp.close()
github klen / muffin-admin / tests.py View on Github external
async def test_base(aiohttp_client):
    app = muffin.Application('admin')
    app.install('muffin_jinja2')
    admin = app.install('muffin_admin')

    @app.register
    class Test(admin.Handler):

        columns = 'id', 'name'

        def load_one(self, request):
            resource = request.match_info.get(self.name)
            if resource:
                return self.collection[int(resource) - 1]

        def load_many(self, request):
            return [
                muffin.utils.Struct(id=1, name='test1'),
github klen / muffin / tests / test_handlers.py View on Github external
async def test_handler_func(aiohttp_client):
    """Test convert functions to Muffin's Handlers."""

    app = muffin.Application('test')

    @app.register('/test1')
    def test1(request):
        return 'test1 passed'

    assert 'test1' in app.router

    @app.register('/test2', methods='put')
    def test2(request):
        return 'test2 passed'

    @app.register('/test3', methods=('get', 'post'))
    def test2(request):
        return 'test3 passed'

    @app.register('/test4', methods='*')
github klen / muffin / tests / test_handlers.py View on Github external
async def test_responses(aiohttp_client):

    app = muffin.Application('test')

    @app.register('/none')
    def none(request):
        return None

    @app.register('/str')
    def str(request):
        return 'str'

    @app.register('/bytes')
    def bytes(request):
        return b'bytes'

    @app.register('/json')
    def json(request):
        return {'test': 'passed'}
github klen / py-frameworks-bench / frameworks / muffin / app.py View on Github external
import peewee


HOST = os.environ.get('DHOST', '127.0.0.1')

PEEWEE_CONNECTION = 'postgres+pool://benchmark:benchmark@%s:5432/benchmark' % HOST
PEEWEE_CONNECTION_PARAMS = {'encoding': 'utf-8', 'max_connections': 10}
REMOTE_URL = 'http://%s' % HOST

if os.environ.get('TEST'):
    PEEWEE_CONNECTION = 'sqlite:///:memory:'
    PEEWEE_CONNECTION_PARAMS = {}
    REMOTE_URL = 'http://google.com'


app = muffin.Application(
    'web',

    PLUGINS=('muffin_peewee', 'muffin_jinja2'),

    JINJA2_TEMPLATE_FOLDERS=os.path.dirname(os.path.abspath(__file__)),

    PEEWEE_CONNECTION=PEEWEE_CONNECTION,
    PEEWEE_CONNECTION_MANUAL=True,
    PEEWEE_CONNECTION_PARAMS=PEEWEE_CONNECTION_PARAMS,

)


@app.ps.peewee.register
class Message(peewee.Model):
    content = peewee.CharField(max_length=512)
github klen / muffin / example / __init__.py View on Github external
import muffin


app = application = muffin.Application('example', CONFIG='example.config.debug')


from .admin import *  # noqa Initialize admin views
from .views import *  # noqa Initialize app views
from .manage import * # noqa Initialize app commands
github klen / muffin-admin / example / __init__.py View on Github external
""" Setup the application. """

import muffin


app = application = muffin.Application(
    'example',

    PLUGINS=[
        'muffin_jinja2',
        'muffin_babel',
        'muffin_admin',
        'muffin_peewee',
    ],

    JINJA2_TEMPLATE_FOLDERS='example/templates',
    JINJA2_AUTO_RELOAD=True,

    ADMIN_TEMPLATE_LIST='custom_list.html',
    ADMIN_TEMPLATE_HOME='custom_home.html',
    ADMIN_I18N=True,
)