File: test_urls.py

package info (click to toggle)
python-textile 1%3A2.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 444 kB
  • ctags: 233
  • sloc: python: 2,320; makefile: 4
file content (53 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
from textile import Textile
import re

def test_urls():
    t = Textile()
    assert t.relURL("http://www.google.com/") == 'http://www.google.com/'

    result = t.links('fooobar "Google":http://google.com/foobar/ and hello world "flickr":http://flickr.com/photos/jsamsa/ ')
    expect = 'fooobar {0}2:shelve and hello world {0}4:shelve '.format(t.uid)
    assert result == expect

    result = t.links('""Open the door, HAL!"":https://xkcd.com/375/')
    expect = '{0}6:shelve'.format(t.uid)
    assert result == expect

    result = t.links('"$":http://domain.tld/test_[brackets]')
    expect = '{0}8:shelve'.format(t.uid)
    assert result == expect

    result = t.links('<em>"$":http://domain.tld/test_</em>')
    expect = '<em>{0}10:shelve</em>'.format(t.uid)
    assert result == expect

    expect = '"":test'
    result = t.links(expect)
    assert result == expect

    expect = '"$":htt://domain.tld'
    result = t.links(expect)
    assert result == expect

    result = t.shelveURL('')
    expect = ''
    assert result == expect

    result = t.retrieveURLs('{0}2:url'.format(t.uid))
    expect = ''
    assert result == expect

    result = t.encode_url('http://domain.tld/übermensch')
    expect = 'http://domain.tld/%C3%BCbermensch'
    assert result == expect

    result = t.parse('A link that starts with an h is "handled":/test/ incorrectly.')
    expect = '\t<p>A link that starts with an h is <a href="/test/">handled</a> incorrectly.</p>'
    assert result == expect

def test_rel_attribute():
    t = Textile(rel='nofollow')
    result = t.parse('"$":http://domain.tld')
    expect = '\t<p><a href="http://domain.tld" rel="nofollow">domain.tld</a></p>'
    assert result == expect