def test_linkify_a_too_long_domain(self): link = escape.linkify( "Hello my friends! Please visit www.my-super-duper-awesome-domain-example.ltd/when/you/have/long/urls/what/to/do/you/will/be/shocked?you=will&xyz=1&you=will¬=dream&today!", shorten=True) self.assertEqual( 'Hello my friends! Please visit <a href="http://www.my-super-duper-awesome-domain-example.ltd/when/you/have/long/urls/what/to/do/you/will/be/shocked?you=will&xyz=1&you=will&not=dream&today" title="http://www.my-super-duper-awesome-domain-example.ltd/when/you/have/long/urls/what/to/do/you/will/be/shocked?you=will&xyz=1&you=will&not=dream&today">www.my-super-duper-awesome-dom...</a>!', link )
def test_linkify_a_too_long_domain_with_amp(self): link = escape.linkify( "Hello my friends! Please visit www.the-big-super-duper-ultra&awesome-domain-example.ltd/when/you/have/long/urls?you=will&freakout!", shorten=True) self.assertEqual( 'Hello my friends! Please visit <a href="http://www.the-big-super-duper-ultra&awesome-domain-example.ltd/when/you/have/long/urls?you=will&freakout" title="http://www.the-big-super-duper-ultra&awesome-domain-example.ltd/when/you/have/long/urls?you=will&freakout">www.the-big-super-duper-ultra...</a>!', link )
def test_linkify_protolen_zero(self): link = escape.linkify( "Hello www.example.ltd/when/you/have/long/urls/what/to/do!", shorten=True) self.assertEqual( 'Hello <a href="http://www.example.ltd/when/you/have/long/urls/what/to/do" title="http://www.example.ltd/when/you/have/long/urls/what/to/do">www.example.ltd/when...</a>!', link )
def test_linkify(self): """ Rough tests just to ensure we don't have exceptions. """ urls = [ "http://testing.com/a/long/url/right/here", ] for u in urls: link = linkify(u, shorten=True) self.assertTrue( link.startswith("<a "), link ) linkify("spdy://testing.com/a/long/url/right/here", shorten=True) linkify( "spdy://testing.com/a/long/url/right/here", shorten=True, extra_params="x=y" ) linkify( "http://testing.com/alongurlrighthere" "alongurlrighthere" "alongurlrighthere" "alongurlrighthere" "/a/long/url/right/here", shorten=True, require_protocol=True, extra_params=lambda x: "x=y")
def test_linkify_no_proto(self): self.assertEqual( 'Hello <a href="http://www.example.ltd">www.example.ltd</a>!', escape.linkify("Hello www.example.ltd!") )
def test_linkify_required_proto(self): self.assertEqual( "Hello www.example.ltd!", escape.linkify("Hello www.example.ltd!", require_protocol=True) )