mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
some simple web integration tests
This commit is contained in:
parent
ba5f44354b
commit
1af4593e16
51
integration/test_web.py
Normal file
51
integration/test_web.py
Normal file
@ -0,0 +1,51 @@
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
from os import mkdir, unlink, utime
|
||||
from os.path import join, exists, getmtime
|
||||
|
||||
import util
|
||||
|
||||
import pytest_twisted
|
||||
|
||||
|
||||
def test_index(alice):
|
||||
"""
|
||||
we can download the index file
|
||||
"""
|
||||
util.web_get(alice._node_dir, "")
|
||||
|
||||
|
||||
def test_upload_download(alice):
|
||||
"""
|
||||
upload a file, then download it via readcap
|
||||
"""
|
||||
|
||||
# XXX FIXME why?
|
||||
print("waiting for ready..")
|
||||
time.sleep(10)
|
||||
|
||||
FILE_CONTENTS = "some contents"
|
||||
|
||||
readcap = util.web_post(
|
||||
alice._node_dir,
|
||||
"uri",
|
||||
data={
|
||||
"t": "upload",
|
||||
"format": "mdmf",
|
||||
},
|
||||
files={
|
||||
"file": FILE_CONTENTS,
|
||||
},
|
||||
)
|
||||
readcap = readcap.strip()
|
||||
print("readcap '{}'".format(readcap))
|
||||
|
||||
data = util.web_get(
|
||||
alice._node_dir, "uri",
|
||||
params={
|
||||
"uri": readcap,
|
||||
"filename": "boom",
|
||||
}
|
||||
)
|
||||
assert data == FILE_CONTENTS
|
@ -9,6 +9,8 @@ from twisted.internet.defer import Deferred, succeed
|
||||
from twisted.internet.protocol import ProcessProtocol
|
||||
from twisted.internet.error import ProcessExitedAlready, ProcessDone
|
||||
|
||||
import requests
|
||||
|
||||
from allmydata.util.configutil import (
|
||||
get_config,
|
||||
set_config,
|
||||
@ -357,5 +359,35 @@ def cli(request, reactor, node_dir, *argv):
|
||||
)
|
||||
return proto.done
|
||||
|
||||
|
||||
def web_get(node_dir, uri_fragment, **kw):
|
||||
"""
|
||||
Make a web-request to the webport of `node_dir`. This will look
|
||||
like: `http://localhost:<webport>/<uri_fragment>`
|
||||
"""
|
||||
with open(join(node_dir, "node.url"), "r") as f:
|
||||
base = f.read().strip()
|
||||
url = base + uri_fragment
|
||||
resp = requests.get(url, **kw)
|
||||
return resp.content
|
||||
|
||||
|
||||
def web_post(node_dir, uri_fragment, **kw):
|
||||
"""
|
||||
Make a web-request to the webport of `node_dir`. This will look
|
||||
like: `http://localhost:<webport>/<uri_fragment>`
|
||||
"""
|
||||
# XXXX same as above except requests.post
|
||||
with open(join(node_dir, "node.url"), "r") as f:
|
||||
base = f.read().strip()
|
||||
url = base + uri_fragment
|
||||
resp = requests.post(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
|
||||
|
||||
|
||||
def magic_folder_cli(request, reactor, node_dir, *argv):
|
||||
return cli(request, reactor, node_dir, "magic-folder", *argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user