Exemple #1
0
async def test_url_for_scheme(app: Quart) -> None:
    async with app.test_request_context("/"):
        with pytest.raises(ValueError):
            url_for("index", _scheme="https")
        assert url_for("index", _scheme="https",
                       _external=True) == "https://localhost/"
        assert (url_for("resource", id=5, _scheme="https",
                        _external=True) == "https://localhost/resource/5")
Exemple #2
0
async def test_url_for_scheme(app: Quart) -> None:
    async with app.test_request_context('GET', '/'):
        with pytest.raises(ValueError):
            url_for('index', _scheme='https')
        assert url_for('index', _scheme='https', _external=True) == 'https://localhost/'
        assert url_for(
            'resource', id=5, _scheme='https', _external=True,
        ) == 'https://localhost/resource/5'
Exemple #3
0
async def test_url_for_blueprint_relative(app: Quart) -> None:
    blueprint = Blueprint("blueprint", __name__)

    @blueprint.route("/")
    def index() -> str:
        return ""

    app.register_blueprint(blueprint, url_prefix="/blue")

    async with app.test_request_context("/blue/"):
        assert url_for(".index") == "/blue/"
        assert url_for("index") == "/"
Exemple #4
0
async def test_url_for_blueprint_relative(app: Quart) -> None:
    blueprint = Blueprint('blueprint', __name__)

    @blueprint.route('/')
    def index() -> str:
        return ''

    app.register_blueprint(blueprint, url_prefix='/blue')

    async with app.test_request_context('/blue/'):
        assert url_for('.index') == '/blue/'
        assert url_for('index') == '/'
Exemple #5
0
async def test_url_for_external(app: Quart) -> None:
    async with app.test_request_context("/"):
        assert url_for("index") == "/"
        assert url_for("index", _external=True) == "http://localhost/"
        assert url_for("resource", id=5, _external=True) == "http://localhost/resource/5"
        assert url_for("resource", id=5, _external=False) == "/resource/5"

    async with app.app_context():
        assert url_for("index") == "http://localhost/"
        assert url_for("index", _external=False) == "/"
Exemple #6
0
async def test_url_for_external(app: Quart) -> None:
    async with app.test_request_context('/'):
        assert url_for('index') == '/'
        assert url_for('index', _external=True) == 'http://localhost/'
        assert url_for('resource', id=5,
                       _external=True) == 'http://localhost/resource/5'
        assert url_for('resource', id=5, _external=False) == '/resource/5'

    async with app.app_context():
        assert url_for('index') == 'http://localhost/'
        assert url_for('index', _external=False) == '/'
Exemple #7
0
async def test_url_for_host_matching(host_matched_app: Quart) -> None:
    async with host_matched_app.app_context():
        assert url_for("index", _external=True) == "http:///"
        assert url_for("host", _external=True) == "http://quart.com/"
Exemple #8
0
async def test_url_for(app: Quart) -> None:
    async with app.test_request_context("/"):
        assert url_for("index") == "/"
        assert url_for("index_post", _method="POST") == "/post"
        assert url_for("resource", id=5) == "/resource/5"
Exemple #9
0
async def test_url_for_anchor(app: Quart) -> None:
    async with app.test_request_context("/"):
        assert url_for("index", _anchor="&foo") == "/#%26foo"
        assert url_for("resource", id=5,
                       _anchor="&foo") == "/resource/5#%26foo"
Exemple #10
0
async def test_url_for_host_matching(host_matched_app: Quart) -> None:
    async with host_matched_app.app_context():
        assert url_for('index') == 'http://localhost/'
        assert url_for('host') == 'http://quart.com/'
Exemple #11
0
async def test_url_for(app: Quart) -> None:
    async with app.test_request_context('/'):
        assert url_for('index') == '/'
        assert url_for('index_post', _method='POST') == '/post'
        assert url_for('resource', id=5) == '/resource/5'
Exemple #12
0
async def test_url_for_anchor(app: Quart) -> None:
    async with app.test_request_context('/'):
        assert url_for('index', _anchor='&foo') == '/#%26foo'
        assert url_for('resource', id=5,
                       _anchor='&foo') == '/resource/5#%26foo'
Exemple #13
0
async def test_url_for_host_matching(host_matched_app: Quart) -> None:
    async with host_matched_app.app_context():
        assert url_for("index") == "http://localhost/"
        assert url_for("host") == "http://quart.com/"
Exemple #14
0
def test_url_for_anchor(app: Quart) -> None:
    with app.app_context():
        assert url_for('index', _anchor='&foo') == '/#%26foo'
        assert url_for('resource', id=5,
                       _anchor='&foo') == '/resource/5#%26foo'
Exemple #15
0
def test_url_for_external(app: Quart) -> None:
    with app.app_context():
        assert url_for('index', _external=True) == 'http://localhost/'
        assert url_for('resource', id=5,
                       _external=True) == 'http://localhost/resource/5'
Exemple #16
0
def test_url_for(app: Quart) -> None:
    with app.app_context():
        assert url_for('index') == '/'
        assert url_for('index_post', _method='POST') == '/post'
        assert url_for('resource', id=5) == '/resource/5'