~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-05-10 19:43:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060510194334-0c20aad23237d047
Working on getting normalize_url working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        self.assertEqual('foo', basename('path/../foo'))
61
61
        self.assertEqual('foo', basename('../path/foo'))
62
62
 
63
 
    def test_normalize_url(self):
64
 
        pass
 
63
    def test_normalize_url_files(self):
 
64
        # Test that local paths are properly normalized
 
65
        normalize_url = urlutils.normalize_url
 
66
 
 
67
        def norm_file(expected, path):
 
68
            url = normalize_url(path)
 
69
            self.assertStartsWith(url, 'file:///')
 
70
            if sys.platform == 'win32':
 
71
                url = url[len('file:///C:'):]
 
72
            else:
 
73
                url = url[len('file://'):]
 
74
 
 
75
            self.assertEndsWith(path, expected)
 
76
 
 
77
        norm_file('path/to/foo', 'path/to/foo')
 
78
        norm_file('/path/to/foo', '/path/to/foo')
 
79
        norm_file('path/to/foo', '../path/to/foo')
 
80
 
 
81
        # Local paths are assumed to *not* be escaped at all
 
82
        norm_file('uni/%C2%B5', u'uni/\xb5')
 
83
        norm_file('uni/%25C2%25B5', u'uni/%C2%B5')
 
84
        norm_file('uni/%20b', u'uni/ b')
 
85
        # All the crazy characters get escaped in local paths => file:/// urls
 
86
        norm_file('%27%3B/%3F%3A%40%26%3D%2B%24%2C%23%20', "';/?:@&=+$,#")
 
87
 
 
88
    def test_normalize_url_hybrid(self):
 
89
        # Anything with a scheme:// should be treated as a hybrid url
 
90
        # which changes what characters get escaped.
 
91
        normalize_url = urlutils.normalize_url
 
92
 
 
93
        eq = self.assertEqual
 
94
        eq('file:///foo/', normalize_url(u'file:///foo/'))
 
95
        eq('file:///foo/%20', normalize_url(u'file:///foo/ '))
 
96
        eq('file:///foo/%20', normalize_url(u'file:///foo/%20'))
 
97
        # Don't escape reserved characters
 
98
        eq('file:///ab_c.d-e/%f:?g&h=i+j;k,L#M$',
 
99
            normalize_url('file:///ab_c.d-e/%f:?g&h=i+j;k,L#M$'))
 
100
        eq('http://ab_c.d-e/%f:?g&h=i+j;k,L#M$',
 
101
            normalize_url('http://ab_c.d-e/%f:?g&h=i+j;k,L#M$'))
 
102
 
 
103
        # Escape unicode characters, but not already escaped chars
 
104
        eq('http://host/ab/%C2%B5/%C2%B5',
 
105
            normalize_url(u'http://host/ab/%C2%B5/\xb5'))
 
106
 
 
107
        # Normalize verifies URLs when they are not unicode
 
108
        # (indicating they did not come from the user)
 
109
        self.assertRaises(InvalidURL, normalize_url, 'http://host/\xb5')
 
110
        self.assertRaises(InvalidURL, normalize_url, 'http://host/ ')
65
111
 
66
112
    def test_url_scheme_re(self):
67
113
        # Test paths that may be URLs