Fixes #2737 - Moves webhook-related tests to run nightly, to speed up CI runs and avoid the periodic failures we've been getting lately. - Also ensures all try/except blocks that have time.sleep in the 'try' also have a time.sleep in 'except' to avoid fast-looping retries --------- Co-authored-by: Ilya Kreymer <ikreymer@gmail.com>
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
A web server to record POST requests and return them on a GET request
|
|
"""
|
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
import json
|
|
|
|
BIND_HOST = "0.0.0.0"
|
|
PORT = 18080
|
|
|
|
post_bodies = []
|
|
|
|
|
|
class EchoServerHTTPRequestHandler(BaseHTTPRequestHandler):
|
|
def do_GET(self):
|
|
self.send_response(200)
|
|
self.end_headers()
|
|
self.wfile.write(json.dumps({"post_bodies": post_bodies}).encode("utf-8"))
|
|
|
|
def do_POST(self):
|
|
content_length = int(self.headers.get("content-length", 0))
|
|
body = self.rfile.read(content_length)
|
|
self.send_response(200)
|
|
if self.path.endswith("/portalUrl"):
|
|
self.send_header("Content-Type", "application/json")
|
|
self.end_headers()
|
|
self.wfile.write(
|
|
json.dumps({"portalUrl": "https://portal.example.com/path/"}).encode(
|
|
"utf-8"
|
|
)
|
|
)
|
|
else:
|
|
self.end_headers()
|
|
|
|
post_bodies.append(json.loads(body.decode("utf-8").replace("'", '"')))
|
|
|
|
|
|
httpd = HTTPServer((BIND_HOST, PORT), EchoServerHTTPRequestHandler)
|
|
httpd.serve_forever()
|