Make the headers and path with defaults for testing. Arguments: app: The application to test against. path: The path to request. If the query_string argument is not defined this argument will be partitioned on a '?' with the following part being considere
(
app: Quart,
path: str,
headers: dict | Headers | None = None,
query_string: dict | None = None,
auth: Authorization | tuple[str, str] | None = None,
subdomain: str | None = None,
)
| 33 | |
| 34 | |
| 35 | def make_test_headers_path_and_query_string( |
| 36 | app: Quart, |
| 37 | path: str, |
| 38 | headers: dict | Headers | None = None, |
| 39 | query_string: dict | None = None, |
| 40 | auth: Authorization | tuple[str, str] | None = None, |
| 41 | subdomain: str | None = None, |
| 42 | ) -> tuple[Headers, str, bytes]: |
| 43 | """Make the headers and path with defaults for testing. |
| 44 | |
| 45 | Arguments: |
| 46 | app: The application to test against. |
| 47 | path: The path to request. If the query_string argument is not |
| 48 | defined this argument will be partitioned on a '?' with |
| 49 | the following part being considered the query_string. |
| 50 | headers: Initial headers to send. |
| 51 | query_string: To send as a dictionary, alternatively the |
| 52 | query_string can be determined from the path. |
| 53 | """ |
| 54 | if headers is None: |
| 55 | headers = Headers() |
| 56 | elif isinstance(headers, Headers): |
| 57 | headers = headers |
| 58 | elif headers is not None: |
| 59 | headers = Headers(headers) |
| 60 | |
| 61 | if auth is not None: |
| 62 | if isinstance(auth, tuple): |
| 63 | auth = Authorization("basic", {"username": auth[0], "password": auth[1]}) |
| 64 | headers.setdefault("Authorization", auth.to_header()) |
| 65 | |
| 66 | headers.setdefault("User-Agent", "Quart") |
| 67 | host = app.config["SERVER_NAME"] or "localhost" |
| 68 | if subdomain is not None: |
| 69 | host = f"{subdomain}.{host}" |
| 70 | headers.setdefault("host", host) |
| 71 | if "?" in path and query_string is not None: |
| 72 | raise ValueError("Query string is defined in the path and as an argument") |
| 73 | if query_string is None: |
| 74 | path, _, query_string_raw = path.partition("?") |
| 75 | else: |
| 76 | query_string_raw = urlencode(query_string, doseq=True) |
| 77 | query_string_bytes = query_string_raw.encode("ascii") |
| 78 | return headers, unquote(path), query_string_bytes |
| 79 | |
| 80 | |
| 81 | def make_test_body_with_headers( |
no outgoing calls
searching dependent graphs…