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))
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))
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)
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)