예제 #1
0
    def test_partDisplayerScrubbedContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        to the length of the content after it has been transformed by
        the scrubber.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        body = u'<div><script>haha</script>this is ok</div>'
        part = PartItem(store=s,
                        contentType=u'text/html',
                        bodyLength=len(body),
                        body=body)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)

        def checkLength(renderedBody):
            self.assertEqual(int(req.headers.get('content-length')),
                             len(renderedBody))

        D.addCallback(checkLength)
        return D
예제 #2
0
    def _testPartDisplayerScrubbing(self, input, scrub=True):
        """
        Set up a store, a PartItem with a body of C{input},
        pass it to the PartDisplayer, render it, and return
        a deferred that'll fire with the string result of
        the rendering.

        @param scrub: if False, the noscrub URL arg will
                      be added to the PartDisplayer request
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)

        part = PartItem(store=s,
                        contentType=u'text/html',
                        body=input)

        pd = PartDisplayer(None)
        pd.item = part

        req = makeRequest()
        if not scrub:
            req.args = {'noscrub': True}

        return deferredRender(pd, req)
예제 #3
0
    def test_partDisplayerContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        on the request.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        part = PartItem(
            store=s, contentType=u'text/plain', bodyLength=31, body=u'x' * 31)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)
        def checkLength(ign):
            self.assertEqual(int(req.headers.get('content-length')), 31)
        D.addCallback(checkLength)
        return D
예제 #4
0
    def test_partDisplayerScrubbedContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        to the length of the content after it has been transformed by
        the scrubber.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        body = u'<div><script>haha</script>this is ok</div>'
        part = PartItem(
            store=s, contentType=u'text/html', bodyLength=len(body), body=body)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)
        def checkLength(renderedBody):
            self.assertEqual(int(req.headers.get('content-length')),
                             len(renderedBody))
        D.addCallback(checkLength)
        return D
예제 #5
0
    def test_partDisplayerContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        on the request.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        part = PartItem(store=s,
                        contentType=u'text/plain',
                        bodyLength=31,
                        body=u'x' * 31)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)

        def checkLength(ign):
            self.assertEqual(int(req.headers.get('content-length')), 31)

        D.addCallback(checkLength)
        return D
예제 #6
0
    def _testPartDisplayerScrubbing(self, input, scrub=True):
        """
        Set up a store, a PartItem with a body of C{input},
        pass it to the PartDisplayer, render it, and return
        a deferred that'll fire with the string result of
        the rendering.

        @param scrub: if False, the noscrub URL arg will
                      be added to the PartDisplayer request
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)

        part = PartItem(store=s, contentType=u'text/html', body=input)

        pd = PartDisplayer(None)
        pd.item = part

        req = makeRequest()
        if not scrub:
            req.args = {'noscrub': True}

        return deferredRender(pd, req)