MCPcopy
hub / github.com/benoitc/gunicorn / test_endpoint

Function test_endpoint

examples/dirty_example/test_integration.py:25–42  ·  view source on GitHub ↗

Test an endpoint and check for expected key in response.

(base, path, expected_key=None)

Source from the content-addressed store, hash-verified

23
24
25def test_endpoint(base, path, expected_key=None):
26 """Test an endpoint and check for expected key in response."""
27 url = base + path
28 print(f"Testing: {url}")
29 try:
30 with urllib.request.urlopen(url, timeout=10) as resp:
31 data = json.loads(resp.read())
32 print(f" Response: {str(data)[:200]}")
33 if expected_key and expected_key not in data:
34 print(f" ERROR: Expected key '{expected_key}' not found!")
35 return False
36 return True
37 except urllib.error.HTTPError as e:
38 print(f" HTTP ERROR {e.code}: {e.reason}")
39 return False
40 except Exception as e:
41 print(f" ERROR: {e}")
42 return False
43
44
45def main():

Callers 1

mainFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected