MCPcopy
hub / github.com/encode/starlette / test_build_environ

Function test_build_environ

tests/middleware/test_wsgi.py:107–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106
107def test_build_environ() -> None:
108 scope = {
109 "type": "http",
110 "http_version": "1.1",
111 "method": "GET",
112 "scheme": "https",
113 "path": "/sub/",
114 "root_path": "/sub",
115 "query_string": b"a=123&b=456",
116 "headers": [
117 (b"host", b"www.example.org"),
118 (b"content-type", b"application/json"),
119 (b"content-length", b"18"),
120 (b"accept", b"application/json"),
121 (b"accept", b"text/plain"),
122 ],
123 "client": ("134.56.78.4", 1453),
124 "server": ("www.example.org", 443),
125 }
126 body = b'{"example":"body"}'
127 environ = build_environ(scope, body)
128 stream = environ.pop("wsgi.input")
129 assert stream.read() == b'{"example":"body"}'
130 assert environ == {
131 "CONTENT_LENGTH": "18",
132 "CONTENT_TYPE": "application/json",
133 "HTTP_ACCEPT": "application/json,text/plain",
134 "HTTP_HOST": "www.example.org",
135 "PATH_INFO": "/",
136 "QUERY_STRING": "a=123&b=456",
137 "REMOTE_ADDR": "134.56.78.4",
138 "REQUEST_METHOD": "GET",
139 "SCRIPT_NAME": "/sub",
140 "SERVER_NAME": "www.example.org",
141 "SERVER_PORT": 443,
142 "SERVER_PROTOCOL": "HTTP/1.1",
143 "wsgi.errors": sys.stdout,
144 "wsgi.multiprocess": True,
145 "wsgi.multithread": True,
146 "wsgi.run_once": False,
147 "wsgi.url_scheme": "https",
148 "wsgi.version": (1, 0),
149 }
150
151
152def test_build_environ_encoding() -> None:

Callers

nothing calls this directly

Calls 3

build_environFunction · 0.90
readMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected