Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test url in Blueprint? #3

Closed
jonahfang opened this issue Jul 26, 2017 · 3 comments
Closed

How to test url in Blueprint? #3

jonahfang opened this issue Jul 26, 2017 · 3 comments

Comments

@jonahfang
Copy link

No description provided.

@jonahfang jonahfang changed the title Howto test url in Blueprint? How to test url in Blueprint? Jul 26, 2017
@yunstanford
Copy link
Owner

You can just test it like normal url, eg.

# module.py
from sanic import Sanic, Blueprint
from sanic.response import json

app = Sanic()
bp = Blueprint("test_blueprints", url_prefix="/blueprint")

@app.route("/")
async def test(request):
    return json({"hello": "world"})

@bp.route("/bp")
async def test_blueprints(request):
    return json({"foo": "bar"})

app.blueprint(bp)

Then,

# test.py
async def test_sanic_route(test_cli):
    resp = await test_cli.get('/')
    assert resp.status == 200
    assert (await resp.json()) == {"hello": "world"}

async def test_sanic_blueprint(test_cli):
    resp = await test_cli.get('/blueprint/bp')
    assert resp.status == 200
    assert (await resp.json()) == {"foo": "bar"}

@yunstanford
Copy link
Owner

yunstanford commented Jul 26, 2017

of course, you have to define test_cli fixture.

BTW, Sanic v0.5.4 has several small issues(a little buggy), but have been fixed in master branch. I'd suggest to use master branch. and i'm working on pushing a new release for Sanic.

@jonahfang
Copy link
Author

@yunstanford , thank you very much. It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants