Example #1
0
    def test_render(self):
        """
        L{ResourceScriptDirectory.getChild} returns a resource which renders a
        response with the HTTP 200 status code and the content of the rpy's
        C{request} global.
        """
        tmp = FilePath(self.mktemp())
        tmp.makedirs()
        tmp.child("test.rpy").setContent(b"""
from twisted.web.resource import Resource
class TestResource(Resource):
    isLeaf = True
    def render_GET(self, request):
        return b'ok'
resource = TestResource()""")
        resource = ResourceScriptDirectory(tmp._asBytesPath())
        request = DummyRequest([b""])
        child = resource.getChild(b"test.rpy", request)
        d = _render(child, request)

        def cbRendered(ignored):
            self.assertEqual(b"".join(request.written), b"ok")

        d.addCallback(cbRendered)
        return d
Example #2
0
 def test_notFoundChild(self):
     """
     L{ResourceScriptDirectory.getChild} returns a resource which renders an
     response with the HTTP I{NOT FOUND} status code if the indicated child
     does not exist as an entry in the directory used to initialized the
     L{ResourceScriptDirectory}.
     """
     path = self.mktemp()
     os.makedirs(path)
     resource = ResourceScriptDirectory(path)
     request = DummyRequest(['foo'])
     child = resource.getChild("foo", request)
     d = _render(child, request)
     def cbRendered(ignored):
         self.assertEqual(request.responseCode, NOT_FOUND)
     d.addCallback(cbRendered)
     return d
Example #3
0
    def test_notFoundChild(self):
        """
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{ResourceScriptDirectory}.
        """
        path = self.mktemp()
        os.makedirs(path)
        resource = ResourceScriptDirectory(path)
        request = DummyRequest([b"foo"])
        child = resource.getChild("foo", request)
        d = _render(child, request)

        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)

        d.addCallback(cbRendered)
        return d
Example #4
0
    def test_renderNotFound(self):
        """
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        """
        resource = ResourceScriptDirectory(self.mktemp())
        request = DummyRequest([b""])
        d = _render(resource, request)

        def cbRendered(ignored):
            self.assertEqual(request.responseCode, NOT_FOUND)

        d.addCallback(cbRendered)
        return d
Example #5
0
    def test_render(self):
        """
        L{ResourceScriptDirectory.getChild} returns a resource which renders a
        response with the HTTP 200 status code and the content of the rpy's
        C{request} global.
        """
        tmp = FilePath(self.mktemp())
        tmp.makedirs()
        tmp.child("test.rpy").setContent(b"""
from twisted.web.resource import Resource
class TestResource(Resource):
    isLeaf = True
    def render_GET(self, request):
        return b'ok'
resource = TestResource()""")
        resource = ResourceScriptDirectory(tmp._asBytesPath())
        request = DummyRequest([b''])
        child = resource.getChild(b"test.rpy", request)
        d = _render(child, request)
        def cbRendered(ignored):
            self.assertEqual(b"".join(request.written), b"ok")
        d.addCallback(cbRendered)
        return d