Exemplo n.º 1
0
    def test_pathRedirect(self):
        root = BaseTestResource()
        redirect = resource.RedirectResource(path="/other")
        root.putChild("r", redirect)

        ds = []
        for url1, url2 in (
            ("http://host/r", "http://host/other"),
            ("http://host/r/foo", "http://host/other"),
        ):
            ds.append(self.assertResponse(
                (resource.RedirectResource(path="/other"), url1),
                (301, {"location": url2}, self.html(url2))
            ))
        return defer.DeferredList(ds, fireOnOneErrback=True)
Exemplo n.º 2
0
 def test_noRedirect(self):
     # This is useless, since it's a loop, but hey
     ds = []
     for url in ("http://host/", "http://host/foo"):
         ds.append(self.assertResponse(
             (resource.RedirectResource(), url),
             (301, {"location": url}, self.html(url))
         ))
     return defer.DeferredList(ds, fireOnOneErrback=True)
Exemplo n.º 3
0
    def test_redirectResource(self):
        redirectResource = resource.RedirectResource(scheme='https',
                                                     host='localhost',
                                                     port=443,
                                                     path='/foo',
                                                     querystring='bar=baz')

        return self.assertResponse(
            (redirectResource, 'http://localhost/'),
            (301, {'location': 'https://localhost/foo?bar=baz'}, None))
Exemplo n.º 4
0
 def test_hostRedirect(self):
     ds = []
     for url1, url2 in (
         ("http://host/", "http://other/"),
         ("http://host/foo", "http://other/foo"),
     ):
         ds.append(self.assertResponse(
             (resource.RedirectResource(host="other"), url1),
             (301, {"location": url2}, self.html(url2))
         ))
     return defer.DeferredList(ds, fireOnOneErrback=True)
def make_redirect(parent, name, location_relative_ref):
    redirect = resource.RedirectResource(path=location_relative_ref)
    setattr(parent, "child_" + name, redirect)
    return redirect