mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 04:57:54 +00:00
consistent naming for client fixtures / helpers
This commit is contained in:
parent
5e15470f55
commit
5ca3a3a1ab
@ -13,15 +13,16 @@ import util
|
||||
import requests
|
||||
import pytest_twisted
|
||||
import html5lib
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def test_index(alice):
|
||||
"""
|
||||
we can download the index file
|
||||
"""
|
||||
util.web_get(alice.node_dir, u"")
|
||||
util.web_get(alice, u"")
|
||||
# ...and json mode is valid json
|
||||
json.loads(util.web_get(alice.node_dir, u"?t=json"))
|
||||
json.loads(util.web_get(alice, u"", params={u"t": u"json"}))
|
||||
|
||||
|
||||
def test_upload_download(alice):
|
||||
@ -32,8 +33,7 @@ def test_upload_download(alice):
|
||||
FILE_CONTENTS = "some contents"
|
||||
|
||||
readcap = util.web_post(
|
||||
alice.node_dir,
|
||||
u"uri",
|
||||
alice, u"uri",
|
||||
data={
|
||||
u"t": u"upload",
|
||||
u"format": u"mdmf",
|
||||
@ -45,7 +45,7 @@ def test_upload_download(alice):
|
||||
readcap = readcap.strip()
|
||||
|
||||
data = util.web_get(
|
||||
alice.node_dir, u"uri",
|
||||
alice, u"uri",
|
||||
params={
|
||||
u"uri": readcap,
|
||||
u"filename": u"boom",
|
||||
@ -82,6 +82,9 @@ def test_helper_status(storage_nodes):
|
||||
url = util.node_url(storage_nodes[0].node_dir, "helper_status")
|
||||
resp = requests.get(url)
|
||||
assert resp.status_code >= 200 and resp.status_code < 300
|
||||
# XXX put in util.parse_html(resp) ...?
|
||||
dom = BeautifulSoup(resp.content, "html5lib")
|
||||
assert unicode(dom.h1.string) == u"Helper Status"
|
||||
|
||||
|
||||
def test_deep_stats(alice):
|
||||
@ -447,7 +450,7 @@ def test_mkdir_with_children(alice):
|
||||
|
||||
# create a new directory with one file and one sub-dir (all-at-once)
|
||||
resp = util.web_post(
|
||||
alice.node_dir, u"uri",
|
||||
alice, u"uri",
|
||||
params={u"t": "mkdir-with-children"},
|
||||
data=json.dumps(meta),
|
||||
)
|
||||
|
@ -164,6 +164,9 @@ class TahoeProcess(object):
|
||||
def node_dir(self):
|
||||
return self._node_dir
|
||||
|
||||
def __str__(self):
|
||||
return "<TahoeProcess in '{}'>".format(self._node_dir)
|
||||
|
||||
|
||||
def _run_node(reactor, node_dir, request, magic_text):
|
||||
"""
|
||||
@ -407,35 +410,39 @@ def _check_status(response):
|
||||
)
|
||||
|
||||
|
||||
def web_get(node_dir, uri_fragment, **kwargs):
|
||||
def web_get(tahoe, uri_fragment, **kwargs):
|
||||
"""
|
||||
Make a GET request to the webport of `node_dir`. This will look
|
||||
like: `http://localhost:<webport>/<uri_fragment>`. All `kwargs`
|
||||
are passed on to `requests.get`
|
||||
Make a GET request to the webport of `tahoe` (a `TahoeProcess`,
|
||||
usually from a fixture (e.g. `alice`). This will look like:
|
||||
`http://localhost:<webport>/<uri_fragment>`. All `kwargs` are
|
||||
passed on to `requests.get`
|
||||
"""
|
||||
url = node_url(node_dir, uri_fragment)
|
||||
url = node_url(tahoe.node_dir, uri_fragment)
|
||||
resp = requests.get(url, **kwargs)
|
||||
_check_status(resp)
|
||||
return resp.content
|
||||
|
||||
|
||||
def web_post(node_dir, uri_fragment, **kwargs):
|
||||
def web_post(tahoe, uri_fragment, **kwargs):
|
||||
"""
|
||||
Make a POST request to the webport of `node_dir`. This will look
|
||||
like: `http://localhost:<webport>/<uri_fragment>`. All `kwargs`
|
||||
are passed on to `requests.post`
|
||||
Make a POST request to the webport of `node` (a `TahoeProcess,
|
||||
usually from a fixture e.g. `alice`). This will look like:
|
||||
`http://localhost:<webport>/<uri_fragment>`. All `kwargs` are
|
||||
passed on to `requests.post`
|
||||
"""
|
||||
url = node_url(node_dir, uri_fragment)
|
||||
url = node_url(tahoe.node_dir, uri_fragment)
|
||||
resp = requests.post(url, **kwargs)
|
||||
_check_status(resp)
|
||||
return resp.content
|
||||
|
||||
|
||||
def await_client_ready(process, timeout=10, liveness=60*2):
|
||||
def await_client_ready(tahoe, timeout=10, liveness=60*2):
|
||||
"""
|
||||
Uses the status API to wait for a client-type node to be
|
||||
Uses the status API to wait for a client-type node (in `tahoe`, a
|
||||
`TahoeProcess` instance usually from a fixture e.g. `alice`) to be
|
||||
'ready'. A client is deemed ready if:
|
||||
- it answers http://<node_url>/statistics/?t=json/
|
||||
|
||||
- it answers `http://<node_url>/statistics/?t=json/`
|
||||
- there is at least one storage-server connected
|
||||
- every storage-server has a "last_received_data" and it is
|
||||
within the last `liveness` seconds
|
||||
@ -446,7 +453,7 @@ def await_client_ready(process, timeout=10, liveness=60*2):
|
||||
start = time.time()
|
||||
while (time.time() - start) < float(timeout):
|
||||
try:
|
||||
data = web_get(process.node_dir, u"", params={u"t": u"json"})
|
||||
data = web_get(tahoe, u"", params={u"t": u"json"})
|
||||
js = json.loads(data)
|
||||
except Exception as e:
|
||||
print("waiting because '{}'".format(e))
|
||||
@ -481,7 +488,7 @@ def await_client_ready(process, timeout=10, liveness=60*2):
|
||||
raise RuntimeError(
|
||||
"Waited {} seconds for {} to be 'ready' but it never was".format(
|
||||
timeout,
|
||||
process.node_dir,
|
||||
tahoe,
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user