From 27a03510c5830a1b646e7d0f6642cdefcbf4ace1 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 24 Apr 2021 03:35:58 +0200 Subject: [PATCH] quick upload test too --- tests/test_httpcli.py | 36 +++++++++++++++++++++++------------- tests/util.py | 11 +++++++++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/test_httpcli.py b/tests/test_httpcli.py index f8e953dd..91b3058c 100644 --- a/tests/test_httpcli.py +++ b/tests/test_httpcli.py @@ -103,7 +103,7 @@ class TestHttpCli(unittest.TestCase): durl = furl.rsplit("/", 1)[0] if "/" in furl else "" # file download - ret = self.curl(furl) + h, ret = self.curl(furl) res = "ok " + fp in ret print("[{}] {} {} = {}".format(fp, rok, wok, res)) if rok != res: @@ -111,7 +111,7 @@ class TestHttpCli(unittest.TestCase): self.fail() # file browser: html - ret = self.curl(durl) + h, ret = self.curl(durl) res = "'{}'".format(self.fn) in ret print(res) if rok != res: @@ -120,7 +120,7 @@ class TestHttpCli(unittest.TestCase): # file browser: json url = durl + "?ls" - ret = self.curl(url) + h, ret = self.curl(url) res = '"{}"'.format(self.fn) in ret print(res) if rok != res: @@ -142,15 +142,18 @@ class TestHttpCli(unittest.TestCase): tar_ng = [x[0] for x in tar if not x[1]] self.assertEqual([], tar_ng) - if durl.split("/")[-1] not in self.can_read: - continue + if durl.split("/")[-1] in self.can_read: + ref = [x for x in vfiles if self.in_dive(top + "/" + durl, x)] + for f in ref: + print("{}: {}".format("ok" if f in tar_ok else "NG", f)) + ref.sort() + tar_ok.sort() + self.assertEqual(ref, tar_ok) - ref = [x for x in vfiles if self.in_dive(top + "/" + durl, x)] - for f in ref: - print("{}: {}".format("ok" if f in tar_ok else "NG", f)) - ref.sort() - tar_ok.sort() - self.assertEqual(ref, tar_ok) + # stash + h, ret = self.put(url) + res = h.startswith("HTTP/1.1 200 ") + self.assertEqual(res, wok) def can_rw(self, fp): # lowest non-neutral folder declares permissions @@ -178,14 +181,21 @@ class TestHttpCli(unittest.TestCase): return True + def put(self, url): + buf = "PUT /{0} HTTP/1.1\r\nCookie: cppwd=o\r\nConnection: close\r\nContent-Length: {1}\r\n\r\nok {0}\n" + buf = buf.format(url, len(url) + 4).encode("utf-8") + conn = tu.VHttpConn(self.args, self.auth, self.log, buf) + HttpCli(conn).run() + return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1) + def curl(self, url, binary=False): conn = tu.VHttpConn(self.args, self.auth, self.log, hdr(url)) HttpCli(conn).run() if binary: h, b = conn.s._reply.split(b"\r\n\r\n", 1) - return h, b + return [h.decode("utf-8"), b] - return conn.s._reply.decode("utf-8") + return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1) def log(self, src, msg, c=0): # print(repr(msg)) diff --git a/tests/util.py b/tests/util.py index 0bc0cf2b..2f79aec1 100644 --- a/tests/util.py +++ b/tests/util.py @@ -53,6 +53,11 @@ def get_ramdisk(): return ret +class NullBroker(object): + def put(*args): + pass + + class VSock(object): def __init__(self, buf): self._query = buf @@ -71,6 +76,8 @@ class VSock(object): class VHttpSrv(object): def __init__(self): + self.broker = NullBroker() + aliases = ["splash", "browser", "browser2", "msg", "md", "mde"] self.j2 = {x: J2_FILES for x in aliases} @@ -86,5 +93,5 @@ class VHttpConn(object): self.log_src = "a" self.hsrv = VHttpSrv() self.nbyte = 0 - self.t0 = time.time() - + self.workload = 0 + self.t0 = time.time() \ No newline at end of file