MCPcopy
hub / github.com/pallets/werkzeug / test_base_response

Function test_base_response

tests/test_wrappers.py:237–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

235
236
237def test_base_response():
238 response = wrappers.Response("öäü")
239 assert response.get_data() == "öäü".encode()
240
241 # writing
242 response = wrappers.Response("foo")
243 response.stream.write("bar")
244 assert response.get_data() == b"foobar"
245
246 # set cookie
247 response = wrappers.Response()
248 response.set_cookie(
249 "foo",
250 value="bar",
251 max_age=60,
252 expires=0,
253 path="/blub",
254 domain="example.org",
255 samesite="Strict",
256 )
257 assert response.headers.to_wsgi_list() == [
258 ("Content-Type", "text/plain; charset=utf-8"),
259 (
260 "Set-Cookie",
261 "foo=bar; Domain=example.org;"
262 " Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=60;"
263 " Path=/blub; SameSite=Strict",
264 ),
265 ]
266
267 # delete cookie
268 response = wrappers.Response()
269 response.delete_cookie("foo")
270 assert response.headers.to_wsgi_list() == [
271 ("Content-Type", "text/plain; charset=utf-8"),
272 (
273 "Set-Cookie",
274 "foo=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/",
275 ),
276 ]
277
278 # close call forwarding
279 closed = []
280
281 class Iterable:
282 def __next__(self):
283 raise StopIteration()
284
285 def __iter__(self):
286 return self
287
288 def close(self):
289 closed.append(True)
290
291 response = wrappers.Response(Iterable())
292 response.call_on_close(lambda: closed.append(True))
293 app_iter, status, headers = run_wsgi_app(response, create_environ(), buffered=True)
294 assert status == "200 OK"

Callers

nothing calls this directly

Calls 10

get_dataMethod · 0.95
set_cookieMethod · 0.95
delete_cookieMethod · 0.95
call_on_closeMethod · 0.95
run_wsgi_appFunction · 0.90
create_environFunction · 0.90
to_wsgi_listMethod · 0.80
appendMethod · 0.80
IterableClass · 0.70
writeMethod · 0.45

Tested by

no test coverage detected