summaryrefslogtreecommitdiff
path: root/subplot.py
blob: b015c42d087a294c90043dd100f4564a002e2889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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"]