diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2020-05-31 18:29:03 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2020-05-31 18:29:03 -0400 |
commit | 6cc104634ef64be3be88c1fccbe98208d95d8a1a (patch) | |
tree | 9001e5333e808808125978a52669a8bff3639438 /tests/endpoints.py | |
parent | 82fde07cef0e41b700b9a30137562eb05f2f2c6d (diff) | |
parent | c2f1e1096f602b1cbd4531352f3e1ea6d656a186 (diff) |
Merge branch 'dfsg_clean'
Diffstat (limited to 'tests/endpoints.py')
-rwxr-xr-x | tests/endpoints.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/endpoints.py b/tests/endpoints.py new file mode 100755 index 00000000..8dc5abef --- /dev/null +++ b/tests/endpoints.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +import sys +import json +import time +import subprocess +import urllib.request +import urllib.parse +import os + +def main(): + prefix = 'http://localhost:8080/' + + with open('/tmp/endpoints.json') as json_data: + data = json.load(json_data) + endpoints = data['endpoints'] + for ep in endpoints: + path = ep['url'] + src = urllib.parse.urljoin(prefix, path) + if ep['method'] == 'GET': + contents = urllib.request.urlopen(src).read() + # it's okay that we can retrieve it, enough for us right now + else: + # TODO: add support for parameters? + post_fields = {'Nam': 'X', 'Msg': 'message', 'Sameday': 'on'} # Set POST fields here + request = urllib.request.Request(src, urllib.parse.urlencode(post_fields).encode()) + contents = urllib.request.urlopen(request).read().decode() + +if __name__ == '__main__': + main() |