File: test_routing.py

package info (click to toggle)
quart 0.20.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,892 kB
  • sloc: python: 8,644; makefile: 42; sh: 17; sql: 6
file content (40 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

import warnings

import pytest
from hypercorn.typing import HTTPScope
from werkzeug.datastructures import Headers

from quart.routing import QuartMap
from quart.testing import no_op_push
from quart.wrappers.request import Request


@pytest.mark.parametrize(
    "server_name, warns",
    [("localhost", False), ("quart.com", True)],
)
async def test_bind_warning(
    server_name: str, warns: bool, http_scope: HTTPScope
) -> None:
    map_ = QuartMap(host_matching=False)
    request = Request(
        "GET",
        "http",
        "/",
        b"",
        Headers([("host", "Localhost")]),
        "",
        "1.1",
        http_scope,
        send_push_promise=no_op_push,
    )

    if warns:
        with pytest.warns(UserWarning):
            map_.bind_to_request(request, subdomain=None, server_name=server_name)
    else:
        with warnings.catch_warnings():
            warnings.simplefilter("error")
            map_.bind_to_request(request, subdomain=None, server_name=server_name)