コード例 #1
0
ファイル: test_message.py プロジェクト: pombredanne/quotient
    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)
コード例 #2
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
コード例 #3
0
ファイル: test_message.py プロジェクト: pombredanne/quotient
    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
class PartDisplayerTestCase(TestCase):
    """
    Tests for L{xquotient.exmess.PartDisplayer}
    """
    def setUp(self):
        self.partDisplayer = PartDisplayer(None)


    def test_scrubbingInvalidDocument(self):
        """
        Pass a completely malformed document to L{PartDisplayer.scrubbedHTML}
        and assert that it returns C{None} instead of raising an exception.
        """
        self.assertIdentical(None, self.partDisplayer.scrubbedHTML(''))


    def test_scrubbingSimpleDocument(self):
        """
        Pass a trivial document to L{PartDisplayer.scrubbedHMTL} and make sure
        it comes out the other side in-tact.
        """
        self.assertEquals('<div></div>', self.partDisplayer.scrubbedHTML('<div></div>'))


    def test_renderablePartReplacesInvalidCharsinHTML(self):
        """
        Test that L{xquotient.exmess.PartDisplayer.renderablePart} replaces
        XML-illegal characters in the body of the text/html part it is passed
        """
        part = MockPart(u'<div>\x00 hi \x01</div>', 'text/html')
        tag = self.partDisplayer.renderablePart(part)
        self.assertEquals(tag.content, '<div>0x0 hi 0x1</div>')

    def test_renderablePartDoesntReplaceInvalidCharsElsewhere(self):
        """
        Test that L{xquotient.exmess.PartDisplayer.renderablePart} doesn't
        replace XML-illegal characters if the content-type of the part isn't
        text/html
        """
        part = MockPart(u'\x00', 'text/plain')
        tag = self.partDisplayer.renderablePart(part)
        self.assertEquals(tag.content, '\x00')
コード例 #5
0
ファイル: test_message.py プロジェクト: pombredanne/quotient
    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
コード例 #6
0
class PartDisplayerTestCase(TestCase):
    """
    Tests for L{xquotient.exmess.PartDisplayer}
    """
    def setUp(self):
        self.partDisplayer = PartDisplayer(None)

    def test_scrubbingInvalidDocument(self):
        """
        Pass a completely malformed document to L{PartDisplayer.scrubbedHTML}
        and assert that it returns C{None} instead of raising an exception.
        """
        self.assertIdentical(None, self.partDisplayer.scrubbedHTML(''))

    def test_scrubbingSimpleDocument(self):
        """
        Pass a trivial document to L{PartDisplayer.scrubbedHMTL} and make sure
        it comes out the other side in-tact.
        """
        self.assertEquals('<div></div>',
                          self.partDisplayer.scrubbedHTML('<div></div>'))

    def test_renderablePartReplacesInvalidCharsinHTML(self):
        """
        Test that L{xquotient.exmess.PartDisplayer.renderablePart} replaces
        XML-illegal characters in the body of the text/html part it is passed
        """
        part = MockPart(u'<div>\x00 hi \x01</div>', 'text/html')
        tag = self.partDisplayer.renderablePart(part)
        self.assertEquals(tag.content, '<div>0x0 hi 0x1</div>')

    def test_renderablePartDoesntReplaceInvalidCharsElsewhere(self):
        """
        Test that L{xquotient.exmess.PartDisplayer.renderablePart} doesn't
        replace XML-illegal characters if the content-type of the part isn't
        text/html
        """
        part = MockPart(u'\x00', 'text/plain')
        tag = self.partDisplayer.renderablePart(part)
        self.assertEquals(tag.content, '\x00')
コード例 #7
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
コード例 #8
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)
コード例 #9
0
 def setUp(self):
     self.partDisplayer = PartDisplayer(None)
コード例 #10
0
 def setUp(self):
     self.partDisplayer = PartDisplayer(None)