Exemple #1
0
 def testInsertBaseInSetResultUpdatesContentLength(self):
     # Make sure that the Content-Length header is updated to account
     # for an inserted <base> tag.
     response = BrowserResponse()
     response.setHeader('content-type', 'text/html')
     base = 'http://localhost/folder/'
     response.setBase(base)
     inserted_text = '\n<base href="%s" />\n' % base
     html_page = b"""<html>
         <head></head>
         <blah>
         </html>
         """
     response.setResult(html_page)
     self.assertEqual(int(response.getHeader('content-length')),
                      len(html_page) + len(inserted_text))
Exemple #2
0
 def testInsertBaseInSetResultUpdatesContentLength(self):
     # Make sure that the Content-Length header is updated to account
     # for an inserted <base> tag.
     response = BrowserResponse()
     response.setHeader('content-type', 'text/html')
     base = 'http://localhost/folder/'
     response.setBase(base)
     inserted_text = '\n<base href="%s" />\n' % base
     html_page = """<html>
         <head></head>
         <blah>
         </html>
         """
     response.setResult(html_page)
     self.assertEquals(
         int(response.getHeader('content-length')),
         len(html_page) + len(inserted_text))
Exemple #3
0
    def testInsertBase(self):
        response = BrowserResponse()
        response.setHeader('content-type', 'text/html')

        insertBase = response._BrowserResponse__insertBase

        # Make sure that bases are inserted
        response.setBase('http://localhost/folder/')
        self.assert_('<base href="http://localhost/folder/" />' in insertBase(
            '<html><head></head><body>Page</body></html>'))

        # Ensure that unicode bases work as well
        response.setBase(u'http://localhost/folder/')
        body = insertBase('<html><head></head><body>Page</body></html>')
        self.assert_(isinstance(body, str))
        self.assert_('<base href="http://localhost/folder/" />' in body)

        # Ensure that encoded bodies work, when a base is inserted.
        response.setBase('http://localhost/folder')
        result = insertBase(
            '<html><head></head><body>\xc3\x9bung</body></html>')
        self.assert_(isinstance(body, str))
        self.assert_('<base href="http://localhost/folder" />' in result)
Exemple #4
0
    def testInsertBase(self):
        response = BrowserResponse()
        response.setHeader('content-type', 'text/html')

        insertBase = response._BrowserResponse__insertBase

        # Make sure that bases are inserted
        response.setBase('http://localhost/folder/')
        self.assert_(
            '<base href="http://localhost/folder/" />' in
            insertBase('<html><head></head><body>Page</body></html>'))

        # Ensure that unicode bases work as well
        response.setBase(u'http://localhost/folder/')
        body = insertBase('<html><head></head><body>Page</body></html>')
        self.assert_(isinstance(body, str))
        self.assert_('<base href="http://localhost/folder/" />' in body)

        # Ensure that encoded bodies work, when a base is inserted.
        response.setBase('http://localhost/folder')
        result = insertBase(
            '<html><head></head><body>\xc3\x9bung</body></html>')
        self.assert_(isinstance(body, str))
        self.assert_('<base href="http://localhost/folder" />' in result)