def get_json(r: requests.Response, public: str, status=checklib.status.Status.MUMBLE): try: data = r.json() except (UnicodeDecodeError, json.decoder.JSONDecodeError): utils.cquit(status, public, f'Invalid json on {r.url}') else: return data
def get_text(r: requests.Response, public: str, status=checklib.status.Status.MUMBLE) -> str: try: data = r.text except UnicodeDecodeError: utils.cquit(status, public, f'Unable to decode text from {r.url}') else: return data
def assert_in_list_dicts(lst, key, value, public: str, status=checklib.status.Status.MUMBLE): found = False for d in lst: if key in d and d.get(key) == value: found = True break if not found: utils.cquit(status, public, f'Could not find value ({key}, {value}) in list of dicts')
def assert_eq(a, b, public: str, status=checklib.status.Status.MUMBLE): if a != b: utils.cquit( status, public, f'Equality assertion failed: {a} ({type(a)}) != {b} ({type(b)})')
def assert_nin(what, where, public: str, status=checklib.status.Status.MUMBLE): if what in where: utils.cquit(status, public, f'Not contains assertion failed: {what} not in {where}')
def assert_gte(a, b, public: str, status=checklib.status.Status.MUMBLE): if not (a >= b): utils.cquit(status, public, f'Inequality assertion failed: {a} < {b}')
def check_response(r: requests.Response, public: str, status=checklib.status.Status.MUMBLE): if r.status_code >= 500: utils.cquit(checklib.status.Status.DOWN, public, f'Code {r.status_code} on {r.url}') if not r.ok: utils.cquit(status, public, f'Error on {r.url}: {r.status_code}')