import typing from flask import url_for from werkzeug.datastructures import MultiDict from werkzeug.http import parse_cookie from werkzeug.test import TestResponse def get_cookie( resp: TestResponse, name: str ) -> typing.Optional["MultiDict[str, str]"]: cookies = resp.headers.getlist("Set-Cookie") cookie = next((cookie for cookie in cookies if name in cookie), None) if cookie is None: return cookie_attrs = parse_cookie(cookie) return cookie_attrs class UrlForThisMixin: ENDPOINT = None def url_for_this(self, app, **kwargs): if "endpoint" not in kwargs: kwargs["endpoint"] = self.ENDPOINT with app.app_context(): url = url_for(**kwargs) return url