def test_rewriting():
 html = "<a href='foo'>bar</a><a href='http://alpha.com'>baz</a>"
 assert_true(('<a href="/proxy/abc.com/80/sub/foo">bar</a>' in _rewrite_links(UrlLibFileWrapper(html, 'http://abc.com/sub/'))), msg='Relative links')
 assert_true(('<a href="/proxy/alpha.com/80/">baz</a>' in _rewrite_links(UrlLibFileWrapper(html, 'http://abc.com/sub/'))), msg='Absolute links')
 html = "<a href='http://alpha.com:1234/bar'>bar</a><a href='http://alpha.com:-1/baz'>baz</a>"
 assert_true(('<a href="/proxy/alpha.com/1234/bar">bar</a><a>baz</a>' in _rewrite_links(UrlLibFileWrapper(html, 'http://abc.com/sub/'))), msg='URL with invalid port')
 html = '\n  <img src="/static/hadoop-logo.jpg"/><br>\n  '
 rewritten = _rewrite_links(UrlLibFileWrapper(html, 'http://abc.com/sub/'))
 assert_true(('<img src="/proxy/abc.com/80/static/hadoop-logo.jpg">' in rewritten), msg='Rewrite images')

def test_rewriting ( ) : html = "<a href='foo'>bar</a><a href='http://alpha.com'>baz</a>" assert_true ( ( '<a href="/proxy/abc.com/80/sub/foo">bar</a>' in _rewrite_links ( UrlLibFileWrapper ( html , 'http://abc.com/sub/' ) ) ) , msg = 'Relative links' ) assert_true ( ( '<a href="/proxy/alpha.com/80/">baz</a>' in _rewrite_links ( UrlLibFileWrapper ( html , 'http://abc.com/sub/' ) ) ) , msg = 'Absolute links' ) html = "<a href='http://alpha.com:1234/bar'>bar</a><a href='http://alpha.com:-1/baz'>baz</a>" assert_true ( ( '<a href="/proxy/alpha.com/1234/bar">bar</a><a>baz</a>' in _rewrite_links ( UrlLibFileWrapper ( html , 'http://abc.com/sub/' ) ) ) , msg = 'URL with invalid port' ) html = '\n  <img src="/static/hadoop-logo.jpg"/><br>\n  ' rewritten = _rewrite_links ( UrlLibFileWrapper ( html , 'http://abc.com/sub/' ) ) assert_true ( ( '<img src="/proxy/abc.com/80/static/hadoop-logo.jpg">' in rewritten ) , msg = 'Rewrite images' )
tests that simple re-writing is working .