From 68e408118b8f9f5cfac41f33a4f91b6343cb82e4 Mon Sep 17 00:00:00 2001 From: meejah Date: Sat, 10 Aug 2019 12:09:34 -0600 Subject: [PATCH] WIP: test the status pages (download is weird still; requests problem?) --- integration/test_web.py | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/integration/test_web.py b/integration/test_web.py index 4553d3614..e137ad35b 100644 --- a/integration/test_web.py +++ b/integration/test_web.py @@ -157,3 +157,68 @@ def test_deep_stats(alice): else: print("{} != {}; waiting".format(d['size-literal-files'], len(FILE_CONTENTS))) time.sleep(.5) + + +def test_status(alice): + """ + confirm we get something sensible from /status and the various sub-types + """ + # upload a file + # (because of the nature of the integration-tests, we can only + # assert things about "our" file because we don't know what other + # operations may have happened in the grid before our test runs). + FILE_CONTENTS = b"all the Important Data of alice\n" * 1000 + resp = requests.put( + util.node_url(alice.node_dir, u"uri"), + files={ + u"file": FILE_CONTENTS, + }, + ) + cap = resp.text.strip() + print("Uploaded data, cap={}".format(cap)) + resp = requests.get( + util.node_url(alice.node_dir, u"uri/{}".format(urllib2.quote(cap))), + ) + print("Downloaded {} bytes of data".format(len(resp.content))) + + print(dir(resp)) + print(resp.content[:120]) + assert resp.content == FILE_CONTENTS + + # find our upload and download status pages + from twisted.web import microdom + from collections import defaultdict + from twisted.web import microdom + from collections import defaultdict + + resp = requests.get( + util.node_url(alice.node_dir, "status"), + ) + dom = microdom.parseString(resp.content) + + # so, we *could* descend the DOM "more properly" .. or just look + # at the URIs + hrefs = set() + for td in dom.getElementsByTagName('td'): + for link in dom.getElementsByTagName('a'): + hrefs.add(link.getAttribute('href')) + + found_our_status = False + for href in hrefs: + if href.startswith("/") or not href: + continue + resp = requests.get( + util.node_url(alice.node_dir, u"status/{}".format(href)), + ) + if href.startswith('up'): + assert "File Upload Status" in resp.content + if "Total Size: 32140" in resp.content: + found_our_status = True + elif href.startswith('down'): + print(href) + assert "File Download Status" in resp.content + if "Total Size: 32140" in resp.content: + print("FOUND IT\n\n\n") + found_our_status = True + + assert found_our_status, "Failed to find the file we uploaded in the status-page"