def test_rewriting():
  """
  Tests that simple re-writing is working.
  """
  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")

  # Test url with port and invalid port
  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 = """
  <img src="/static/hadoop-logo.jpg"/><br>
  """
  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")
dataset/ETHPy150Open cloudera/hue/apps/proxy/src/proxy/proxy_test.py/test_rewriting/original