summaryrefslogtreecommitdiff
path: root/subplot/http.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-10-14 09:19:06 +0300
committerLars Wirzenius <liw@liw.fi>2020-10-14 09:19:27 +0300
commite34beeecfc807bd3afb9d5b6c2c764fd71027cde (patch)
tree935ab83af70bea67103576b8536d6c7cf59e274a /subplot/http.py
parent64a17b4927c4579d25692d15a8f0669adcf82fd2 (diff)
downloadewww-e34beeecfc807bd3afb9d5b6c2c764fd71027cde.tar.gz
refactor: move subplot files to subplot/
The root of the source tree was getting a little crowded.
Diffstat (limited to 'subplot/http.py')
-rw-r--r--subplot/http.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/subplot/http.py b/subplot/http.py
new file mode 100644
index 0000000..5cff887
--- /dev/null
+++ b/subplot/http.py
@@ -0,0 +1,47 @@
+#############################################################################
+# Some helpers to make HTTP requests and examine responses
+
+import json
+import logging
+import os
+import random
+import re
+import shutil
+import signal
+import subprocess
+import time
+import urllib.parse
+
+import yaml
+
+
+# Make an HTTP request.
+def http_request(ctx, host=None, method=None, url=None):
+ logging.debug(f"Make HTTP request: {method} {url}")
+ runcmd(ctx, ["curl", "-ksv", "-X", method, f"-HHost: {host}", url])
+ exit_code_is(ctx, 0)
+
+
+# Check status code of latest HTTP request.
+def http_status_code_is(ctx, code=None):
+ logging.debug(f"Verifying status code of previous HTTP request is {code}")
+ logging.debug(f" stderr={ctx['stderr']}")
+ pattern = f"\n< HTTP/2 {code} "
+ assert_eq(pattern in ctx["stderr"], True)
+
+
+# Check a HTTP response header for latest request has a given value.
+def http_header_is(ctx, header=None, value=None):
+ logging.debug(f"Verifying response has header {header}: {value}")
+ s = ctx["stderr"]
+ pattern = f"\n< {header}: {value}"
+ assert_eq(pattern in s, True)
+
+
+# Check a HTTP body response for latest request has a given value.
+def http_body_is(ctx, body=None):
+ logging.debug(f"Verifying response body is {body!r}")
+ logging.debug(f" actual body={ctx['stdout']!r}")
+ s = ctx["stdout"]
+ body = body.encode("UTF8").decode("unicode-escape")
+ assert_eq(body, s)