import logging import requests import urllib3 urllib3.disable_warnings() def nop(ctx): ctx["base"] = "https://web" def get(ctx, path=None): r = requests.get(f"{ctx['base']}{path}", verify=False) ctx["http.status"] = r.status_code ctx["http.headers"] = dict(r.headers) ctx["http.body"] = r.text logging.debug(f"status: {r.status_code}") logging.debug(f"headers: {r.headers}") logging.debug(f"body: {r.text}") def status_code(ctx, code=None): assert int(ctx["http.status"]) == int(code) def has_header(ctx, header=None, value=None): logging.debug(f"wanted header: {header!r}") logging.debug(f"wanted value: {value}") assert header in ctx["http.headers"] assert ctx["http.headers"][header] == value def body_matches_file(ctx, filename=None): with open(filename) as f: data = f.read() assert data == ctx["http.body"]