예제 #1
0
def test_raise_app():
    with raises(AttributeError):
        app = Sanic(__name__)
        spf = SanicPluginsFramework(app)
        oauth = spf.register_plugin(oauthclient)
        plugin = app.extensions['oauthlib.client']
        client = spf.get_plugin_assoc(plugin)
        assert client.demo.name == 'dev'
예제 #2
0
def test_app(request):
    app = Sanic(request.node.name)
    spf = SanicPluginsFramework(app)
    oauth = spf.register_plugin(oauthclient)
    remote = oauth.remote_app(
        'dev',
        consumer_key='dev',
        consumer_secret='dev',
        request_token_params={'scope': 'email'},
        base_url='http://127.0.0.1:5000/api/',
        request_token_url=None,
        access_token_method='POST',
        access_token_url='http://127.0.0.1:5000/oauth/token',
        authorize_url='http://127.0.0.1:5000/oauth/authorize')
    plugin = app.extensions['oauthlib.client']
    client = spf.get_plugin_assoc(plugin)
    assert client.dev.name == 'dev'
예제 #3
0
from sanic import Sanic
from sanic.response import text
from spf import SanicPluginsFramework
from spf.plugins.contextualize import instance as contextualize

app = Sanic(__name__)
app.config['SPF_LOAD_INI'] = True
app.config['SPF_INI_FILE'] = 'example_spf.ini'
spf = SanicPluginsFramework(app)

# We can get the assoc object from SPF, it is already registered
contextualize = spf.get_plugin_assoc('Contextualize')


@contextualize.middleware
def middle3(request, context):
    shared = context.shared
    r = shared.request
    r.test = "true"


@contextualize.middleware(priority=7)
def middle4(request, context):
    shared = context.shared
    r = shared.request
    _ = r.test


@contextualize.route('/1/<args>')
def index2(request, args, context):
    shared = context.shared
예제 #4
0
from sanic.exceptions import ServerError
from spf import SanicPluginsFramework
import logging

app = Sanic('SanicCorsAppBasedExample')
logging.basicConfig(level=logging.INFO)

# To enable logging for sanic-cors,
logging.getLogger('sanic_cors').level = logging.DEBUG

app.config['SPF_LOAD_INI'] = True
app.config['SPF_INI_FILE'] = 'spf_cors.ini'
spf = SanicPluginsFramework(app)

# We can get the assoc object from SPF, it is already registered
assoc = spf.get_plugin_assoc('CORS')


@app.route("/")
def hello_world(request):
    '''
        Since the path '/' does not match the regular expression r'/api/*',
        this route does not have CORS headers set.
    '''
    return text('''
<html>
    <h1>Hello CORS!</h1>
    <h3> End to end editable example with jquery! </h3>
    <a class="jsbin-embed" href="http://jsbin.com/zazitas/embed?js,console">JS Bin on jsbin.com</a>
    <script src="//static.jsbin.com/js/embed.min.js?3.35.12"></script>