import typing from bs4 import BeautifulSoup from flask import render_template from flask import url_for from werkzeug.datastructures import MultiDict from werkzeug.http import parse_cookie from werkzeug.test import TestResponse from atlas_um.helpers.ordering import QueryOrdering from atlas_um.pgdb import DNAAccount, Application def get_default_users_list_ordering(query, order=""): return QueryOrdering( query, [ DNAAccount.id, DNAAccount.given_name, DNAAccount.family_name, DNAAccount.email, ], order, default_is_desc=True, ) def get_default_applications_list_ordering(query, order=""): return QueryOrdering( query, [ Application.dna_account_id, Application.name, Application.client_id, Application.resource_group_id, Application.audience, ], order, ) 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 class RenderSOUPMixin: TEMPLATE = "" def render_soup(self, *args, **kwargs): rt = render_template(self.TEMPLATE, **kwargs) return BeautifulSoup(rt, "html.parser")