def test_initialize_class_on_blueprint_with_url_prefix_and_config(): app = Sanic("sanic-jwt-test") bp = Blueprint("test", url_prefix="/test") app.blueprint(bp) init = Initialize(bp, app=app, authenticate=lambda: True, url_prefix="/a") assert init._get_url_prefix() == "/test/a"
def test_initialize_class_on_blueprint_with_url_prefix_and_config(): app = Sanic() bp = Blueprint('test', url_prefix='/test') app.blueprint(bp) init = Initialize(bp, app=app, authenticate=lambda: True, url_prefix='/a') assert init._get_url_prefix() == '/test/a'
def app_with_bp(username_table, authenticate): sanic_app = Sanic() sanic_jwt_init = Initialize( sanic_app, authenticate=authenticate, ) @sanic_app.route("/") async def helloworld(request): return json({"hello": "world"}) @sanic_app.route("/protected") @protected() async def protected_request(request): return json({"protected": True}) sanic_bp = Blueprint('bp', url_prefix='/bp') sanic_app.blueprint(sanic_bp) sanic_jwt_init_bp = Initialize( sanic_bp, app=sanic_app, authenticate=authenticate, ) print('sanic_bp', sanic_bp.url_prefix) print('sanic_jwt_init_bp', sanic_jwt_init_bp._get_url_prefix()) print('sanic_bp', sanic_bp.routes) @sanic_bp.route("/") async def bp_helloworld(request): return json({"hello": "world"}) @sanic_bp.route("/protected") @protected() async def bp_protected_request(request): return json({"protected": True}) yield (sanic_app, sanic_jwt_init, sanic_bp, sanic_jwt_init_bp)