mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 18:56:28 +00:00
add test_put and refactor a little
This commit is contained in:
parent
1af4593e16
commit
7738f9f4e3
@ -49,3 +49,26 @@ def test_upload_download(alice):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
assert data == FILE_CONTENTS
|
assert data == FILE_CONTENTS
|
||||||
|
|
||||||
|
|
||||||
|
def test_put(alice):
|
||||||
|
"""
|
||||||
|
use PUT to create a file
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time; time.sleep(10) # XXX wat
|
||||||
|
FILE_CONTENTS = "added via PUT"
|
||||||
|
|
||||||
|
import requests
|
||||||
|
resp = requests.put(
|
||||||
|
util.node_url(alice._node_dir, "uri"),
|
||||||
|
files={
|
||||||
|
"file": FILE_CONTENTS,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
print(resp)
|
||||||
|
print(resp.status_code)
|
||||||
|
print(resp.text)
|
||||||
|
print("\n\n\n\n\n\n\n")
|
||||||
|
assert resp.text.strip().startswith("URI:CHK:")
|
||||||
|
assert resp.text.strip().endswith(":2:4:153")
|
||||||
|
@ -360,15 +360,28 @@ def cli(request, reactor, node_dir, *argv):
|
|||||||
return proto.done
|
return proto.done
|
||||||
|
|
||||||
|
|
||||||
|
def node_url(node_dir, uri_fragment):
|
||||||
|
"""
|
||||||
|
Create a fully qualified URL by reading config from `node_dir` and
|
||||||
|
adding the `uri_fragment`
|
||||||
|
"""
|
||||||
|
with open(join(node_dir, "node.url"), "r") as f:
|
||||||
|
base = f.read().strip()
|
||||||
|
url = base + uri_fragment
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
def web_get(node_dir, uri_fragment, **kw):
|
def web_get(node_dir, uri_fragment, **kw):
|
||||||
"""
|
"""
|
||||||
Make a web-request to the webport of `node_dir`. This will look
|
Make a web-request to the webport of `node_dir`. This will look
|
||||||
like: `http://localhost:<webport>/<uri_fragment>`
|
like: `http://localhost:<webport>/<uri_fragment>`
|
||||||
"""
|
"""
|
||||||
with open(join(node_dir, "node.url"), "r") as f:
|
url = node_url(node_dir, uri_fragment)
|
||||||
base = f.read().strip()
|
|
||||||
url = base + uri_fragment
|
|
||||||
resp = requests.get(url, **kw)
|
resp = requests.get(url, **kw)
|
||||||
|
if resp.status_code < 200 or resp.status_code >= 300:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Expected a 200 code, got {}".format(resp.status_code)
|
||||||
|
)
|
||||||
return resp.content
|
return resp.content
|
||||||
|
|
||||||
|
|
||||||
@ -377,10 +390,7 @@ def web_post(node_dir, uri_fragment, **kw):
|
|||||||
Make a web-request to the webport of `node_dir`. This will look
|
Make a web-request to the webport of `node_dir`. This will look
|
||||||
like: `http://localhost:<webport>/<uri_fragment>`
|
like: `http://localhost:<webport>/<uri_fragment>`
|
||||||
"""
|
"""
|
||||||
# XXXX same as above except requests.post
|
url = node_url(node_dir, uri_fragment)
|
||||||
with open(join(node_dir, "node.url"), "r") as f:
|
|
||||||
base = f.read().strip()
|
|
||||||
url = base + uri_fragment
|
|
||||||
resp = requests.post(url, **kw)
|
resp = requests.post(url, **kw)
|
||||||
if resp.status_code < 200 or resp.status_code >= 300:
|
if resp.status_code < 200 or resp.status_code >= 300:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
@ -532,13 +532,14 @@ class CLI(CLITestMixin, unittest.TestCase):
|
|||||||
# it's safe to drop it on the floor.
|
# it's safe to drop it on the floor.
|
||||||
del d
|
del d
|
||||||
|
|
||||||
patcher = MonkeyPatcher((runner, 'parse_or_exit_with_explanation',
|
patcher = MonkeyPatcher(
|
||||||
call_parse_or_exit),
|
(runner, 'parse_or_exit_with_explanation', call_parse_or_exit),
|
||||||
(sys, 'argv', ["tahoe"]),
|
(runner, "_setup_coverage", lambda r: None),
|
||||||
(sys, 'exit', call_sys_exit),
|
(sys, 'argv', ["tahoe"]),
|
||||||
(sys, 'stderr', stderr),
|
(sys, 'exit', call_sys_exit),
|
||||||
(task, 'react', fake_react),
|
(sys, 'stderr', stderr),
|
||||||
)
|
(task, 'react', fake_react),
|
||||||
|
)
|
||||||
patcher.runWithPatches(runner.run)
|
patcher.runWithPatches(runner.run)
|
||||||
|
|
||||||
self.failUnless(ns.parse_called)
|
self.failUnless(ns.parse_called)
|
||||||
|
Loading…
Reference in New Issue
Block a user