From 90bb4cf58706a147ba5bbddcc5c5afa618fb4ad0 Mon Sep 17 00:00:00 2001 From: meejah Date: Wed, 24 Jul 2019 01:33:15 -0600 Subject: [PATCH 01/58] test index json --- integration/test_web.py | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 integration/test_web.py diff --git a/integration/test_web.py b/integration/test_web.py new file mode 100644 index 000000000..36c1290b1 --- /dev/null +++ b/integration/test_web.py @@ -0,0 +1,53 @@ +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, "") + # ...and json mode is valid json + json.loads(util.web_get(alice._node_dir, "?t=json")) + + +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 From 47e177be684e7b574a167ec00a39d61a72e542a5 Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 30 Jul 2019 15:01:06 -0600 Subject: [PATCH 02/58] import --- integration/test_web.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration/test_web.py b/integration/test_web.py index 36c1290b1..4b0639000 100644 --- a/integration/test_web.py +++ b/integration/test_web.py @@ -1,6 +1,7 @@ import sys import time import shutil +import json from os import mkdir, unlink, utime from os.path import join, exists, getmtime From 32a0841c0bd863709423cdafedeca75cc482d0eb Mon Sep 17 00:00:00 2001 From: meejah Date: Tue, 30 Jul 2019 15:01:57 -0600 Subject: [PATCH 03/58] a basic unit-test for rendering (root page) --- src/allmydata/test/web/test_root.py | 303 ++++++++++++++++++++++++++++ 1 file changed, 303 insertions(+) diff --git a/src/allmydata/test/web/test_root.py b/src/allmydata/test/web/test_root.py index 1e324c398..1558fe413 100644 --- a/src/allmydata/test/web/test_root.py +++ b/src/allmydata/test/web/test_root.py @@ -1,8 +1,18 @@ +# encoding: utf-8 + +from mock import Mock + from twisted.trial import unittest +from twisted.internet.task import Clock +from twisted.internet.defer import inlineCallbacks + +from nevow.testutil import FakeRequest, FakeSession, renderPage +from nevow.context import WebContext from ...storage_client import NativeStorageServer from ...web.root import Root from ...util.connection_status import ConnectionStatus +from allmydata.client import SecretHolder class FakeRoot(Root): def __init__(self): @@ -36,3 +46,296 @@ class RenderServiceRow(unittest.TestCase): self.assertIdentical(res, ctx) self.assertEqual(ctx.slots["version"], "") self.assertEqual(ctx.slots["nickname"], "") + + +class FakeUploader(object): + """ + """ + def get_helper_info(self): + return ("furl", False) + + +class FakeHelper(object): + def get_stats(self): + return { + "chk_upload_helper.active_uploads": 0, + } + + +class FakeStorageBroker(object): + def get_connected_servers(self): + return {} + + def get_all_serverids(self): + return () + + def get_known_servers(self): + return () + + +# XXX there are several 'fake client' instance throughout the code +# .. probably should be a single one that works better and covers all +# the cases etc. +class FakeClient(object): + """ + just enough to let the node acquire a downloader (which it won't + use), and to get default encoding parameters + """ + nickname = "fake_nickname" + stats_provider = None + uploader = FakeUploader() + helper = FakeHelper() + storage_broker = FakeStorageBroker() + + _secret_holder = SecretHolder("lease secret", "convergence secret") + _magic_folders = None + + def get_long_nodeid(self): + return "v0-nodeid" + + def get_long_tubid(self): + return "v0-tubid" + + def introducer_connection_statuses(self): + return {} + + def get_auth_token(self): + return "x" + + def getServiceNamed(self, name): + return { + "uploader": self.uploader, + "helper": self.helper, + }[name] + + def get_encoding_parameters(self): + return {"k": 3, "n": 10} + + def get_storage_broker(self): + return self.storage_broker + + def get_history(self): + return None + + + +class RenderRoot(unittest.TestCase): + + def setUp(self): + self.root = FakeRoot() + self.context = WebContext() + self.clock = Clock() + self.client = FakeClient() + + def _test_root_template(self): + page = Root(self.client, self.clock, now_fn=self.clock.seconds) + page.addSlash = False + request = FakeRequest() + print(dir(page)) + print(page.renderer) + d = page.renderHTTP(request) + print(d) + + @inlineCallbacks + def test_root_template(self): + page = Root(self.client, self.clock, now_fn=self.clock.seconds) + page.addSlash = False # XXX hack around what looks like nevow testutils bug + request = FakeRequest() + + page_data = yield renderPage(page) + + # we chop up to the line with "