mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 21:43:09 +00:00
re-use our other renderer
This commit is contained in:
parent
27c2fd80c8
commit
7d54af7928
@ -20,18 +20,16 @@ from bs4 import BeautifulSoup
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer
|
||||
|
||||
# We need to use `nevow.inevow.IRequest` for now for compatibility
|
||||
# with the code in web/common.py. Once nevow bits are gone from
|
||||
# web/common.py, we can use `twisted.web.iweb.IRequest` here.
|
||||
if PY2:
|
||||
from nevow.inevow import IRequest
|
||||
else:
|
||||
from twisted.web.iweb import IRequest
|
||||
|
||||
from zope.interface import implementer
|
||||
from twisted.web.server import Request
|
||||
from twisted.web.test.requesthelper import DummyChannel
|
||||
from twisted.web.template import flattenString
|
||||
from twisted.web.resource import (
|
||||
Resource,
|
||||
)
|
||||
from twisted.web.template import (
|
||||
renderElement,
|
||||
)
|
||||
|
||||
from allmydata import check_results, uri
|
||||
from allmydata import uri as tahoe_uri
|
||||
@ -41,6 +39,9 @@ from allmydata.interfaces import (
|
||||
ICheckAndRepairResults,
|
||||
)
|
||||
from allmydata.util import base32
|
||||
from allmydata.webish import (
|
||||
TahoeLAFSRequest,
|
||||
)
|
||||
from allmydata.web import check_results as web_check_results
|
||||
from allmydata.storage_client import StorageFarmBroker, NativeStorageServer
|
||||
from allmydata.storage.server import storage_index_to_dir
|
||||
@ -65,24 +66,6 @@ class FakeClient(object):
|
||||
def get_storage_broker(self):
|
||||
return self.storage_broker
|
||||
|
||||
@implementer(IRequest)
|
||||
class TestRequest(Request, object):
|
||||
"""
|
||||
A minimal Request class to use in tests.
|
||||
|
||||
XXX: We have to have this class because `common.get_arg()` expects
|
||||
a `nevow.inevow.IRequest`, which `twisted.web.server.Request`
|
||||
isn't. The request needs to have `args`, `fields`, `prepath`, and
|
||||
`postpath` properties so that `allmydata.web.common.get_arg()`
|
||||
won't complain.
|
||||
"""
|
||||
def __init__(self, args=None, fields=None):
|
||||
super(TestRequest, self).__init__(DummyChannel())
|
||||
self.args = args or {}
|
||||
self.fields = fields or {}
|
||||
self.prepath = [b""]
|
||||
self.postpath = [b""]
|
||||
|
||||
|
||||
@implementer(IServer)
|
||||
class FakeServer(object):
|
||||
@ -154,6 +137,15 @@ class FakeCheckAndRepairResults(object):
|
||||
return self._repair_success
|
||||
|
||||
|
||||
class ElementResource(Resource, object):
|
||||
def __init__(self, element):
|
||||
Resource.__init__(self)
|
||||
self.element = element
|
||||
|
||||
def render(self, request):
|
||||
return renderElement(request, self.element)
|
||||
|
||||
|
||||
class WebResultsRendering(unittest.TestCase):
|
||||
|
||||
@staticmethod
|
||||
@ -190,8 +182,9 @@ class WebResultsRendering(unittest.TestCase):
|
||||
return self.successResultOf(render(resource, {"output": ["json"]}))
|
||||
|
||||
def render_element(self, element, args=None):
|
||||
d = flattenString(TestRequest(args), element)
|
||||
return self.successResultOf(d)
|
||||
if args is None:
|
||||
args = {}
|
||||
return self.successResultOf(render(ElementResource(element), args))
|
||||
|
||||
def test_literal(self):
|
||||
lcr = web_check_results.LiteralCheckResultsRendererElement()
|
||||
|
Loading…
Reference in New Issue
Block a user