mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 23:42:38 +00:00
web.test_introducer: replace getPage with treq
This commit is contained in:
parent
8be5072fca
commit
486fca0d5c
@ -2,10 +2,10 @@ import os.path
|
|||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from foolscap.api import fireEventually, flushEventualQueue
|
from foolscap.api import fireEventually, flushEventualQueue
|
||||||
from allmydata.util import fileutil
|
from allmydata.util import fileutil
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer
|
||||||
from allmydata.introducer import IntroducerNode
|
from allmydata.introducer import IntroducerNode
|
||||||
from .common import FAVICON_MARKUP
|
from .common import FAVICON_MARKUP
|
||||||
from ..common_web import HTTPClientGETFactory
|
from ..common_web import do_http
|
||||||
|
|
||||||
class IntroducerWeb(unittest.TestCase):
|
class IntroducerWeb(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -18,6 +18,7 @@ class IntroducerWeb(unittest.TestCase):
|
|||||||
d.addCallback(flushEventualQueue)
|
d.addCallback(flushEventualQueue)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def test_welcome(self):
|
def test_welcome(self):
|
||||||
basedir = "web.IntroducerWeb.test_welcome"
|
basedir = "web.IntroducerWeb.test_welcome"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
@ -29,31 +30,12 @@ class IntroducerWeb(unittest.TestCase):
|
|||||||
self.node = IntroducerNode(basedir)
|
self.node = IntroducerNode(basedir)
|
||||||
self.ws = self.node.getServiceNamed("webish")
|
self.ws = self.node.getServiceNamed("webish")
|
||||||
|
|
||||||
d = fireEventually(None)
|
yield fireEventually(None)
|
||||||
d.addCallback(lambda ign: self.node.startService())
|
self.node.startService()
|
||||||
|
|
||||||
d.addCallback(lambda ign: self.GET("/"))
|
|
||||||
def _check(res):
|
|
||||||
self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
|
|
||||||
self.failUnlessIn(FAVICON_MARKUP, res)
|
|
||||||
self.failUnlessIn('Page rendered at', res)
|
|
||||||
self.failUnlessIn('Tahoe-LAFS code imported from:', res)
|
|
||||||
d.addCallback(_check)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def GET(self, urlpath, followRedirect=False, return_response=False,
|
|
||||||
**kwargs):
|
|
||||||
# if return_response=True, this fires with (data, statuscode,
|
|
||||||
# respheaders) instead of just data.
|
|
||||||
assert not isinstance(urlpath, unicode)
|
|
||||||
url = self.ws.getURL().rstrip('/') + urlpath
|
|
||||||
factory = HTTPClientGETFactory(url, method="GET",
|
|
||||||
followRedirect=followRedirect, **kwargs)
|
|
||||||
reactor.connectTCP("localhost", self.ws.getPortnum(), factory)
|
|
||||||
d = factory.deferred
|
|
||||||
def _got_data(data):
|
|
||||||
return (data, factory.status, factory.response_headers)
|
|
||||||
if return_response:
|
|
||||||
d.addCallback(_got_data)
|
|
||||||
return factory.deferred
|
|
||||||
|
|
||||||
|
url = "http://localhost:%d/" % self.ws.getPortnum()
|
||||||
|
res = yield do_http("get", url)
|
||||||
|
self.failUnlessIn('Welcome to the Tahoe-LAFS Introducer', res)
|
||||||
|
self.failUnlessIn(FAVICON_MARKUP, res)
|
||||||
|
self.failUnlessIn('Page rendered at', res)
|
||||||
|
self.failUnlessIn('Tahoe-LAFS code imported from:', res)
|
||||||
|
Loading…
Reference in New Issue
Block a user