~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
 
152
152
    def test_parse_url(self):
153
153
        from bzrlib.transport.sftp import SFTPTransport
154
 
        s = SFTPTransport('sftp://simple.example.com/%2fhome/source', clone_from=fake)
 
154
        s = SFTPTransport('sftp://simple.example.com/home/source', clone_from=fake)
155
155
        self.assertEquals(s._host, 'simple.example.com')
156
156
        self.assertEquals(s._port, None)
157
157
        self.assertEquals(s._path, '/home/source')
158
158
        self.failUnless(s._password is None)
159
159
 
160
 
        self.assertEquals(s.base, 'sftp://simple.example.com/%2Fhome/source/')
161
 
        
162
 
        s = SFTPTransport('sftp://ro%62ey:h%40t@example.com:2222/relative', clone_from=fake)
 
160
        self.assertEquals(s.base, 'sftp://simple.example.com/home/source/')
 
161
 
 
162
        s = SFTPTransport('sftp://ro%62ey:h%40t@example.com:2222/~/relative', clone_from=fake)
163
163
        self.assertEquals(s._host, 'example.com')
164
164
        self.assertEquals(s._port, 2222)
165
165
        self.assertEquals(s._username, 'robey')
167
167
        self.assertEquals(s._path, 'relative')
168
168
 
169
169
        # Base should not keep track of the password
170
 
        self.assertEquals(s.base, 'sftp://robey@example.com:2222/relative/')
171
 
 
172
 
        # Double slash should be accepted instead of using %2F
173
 
        s = SFTPTransport('sftp://user@example.com:22//absolute/path/', clone_from=fake)
174
 
        self.assertEquals(s._host, 'example.com')
175
 
        self.assertEquals(s._port, 22)
176
 
        self.assertEquals(s._username, 'user')
177
 
        self.assertEquals(s._password, None)
178
 
        self.assertEquals(s._path, '/absolute/path/')
179
 
 
180
 
        # Also, don't show the port if it is the default 22
181
 
        self.assertEquals(s.base, 'sftp://user@example.com:22/%2Fabsolute/path/')
 
170
        self.assertEquals(s.base, 'sftp://robey@example.com:2222/~/relative/')
182
171
 
183
172
    def test_relpath(self):
184
173
        from bzrlib.transport.sftp import SFTPTransport
185
174
        from bzrlib.errors import PathNotChild
186
175
 
187
 
        s = SFTPTransport('sftp://user@host.com//abs/path', clone_from=fake)
188
 
        self.assertEquals(s.relpath('sftp://user@host.com//abs/path/sub'), 'sub')
 
176
        s = SFTPTransport('sftp://user@host.com/abs/path', clone_from=fake)
 
177
        self.assertEquals(s.relpath('sftp://user@host.com/abs/path/sub'), 'sub')
189
178
        # Can't test this one, because we actually get an AssertionError
190
179
        # TODO: Consider raising an exception rather than an assert
191
 
        #self.assertRaises(PathNotChild, s.relpath, 'http://user@host.com//abs/path/sub')
192
 
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user2@host.com//abs/path/sub')
193
 
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@otherhost.com//abs/path/sub')
194
 
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com:33//abs/path/sub')
195
 
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com/abs/path/sub')
 
180
        #self.assertRaises(PathNotChild, s.relpath, 'http://user@host.com/abs/path/sub')
 
181
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user2@host.com/abs/path/sub')
 
182
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@otherhost.com/abs/path/sub')
 
183
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com:33/abs/path/sub')
 
184
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com/~/rel/path/sub')
196
185
 
197
186
        # Make sure it works when we don't supply a username
198
 
        s = SFTPTransport('sftp://host.com//abs/path', clone_from=fake)
199
 
        self.assertEquals(s.relpath('sftp://host.com//abs/path/sub'), 'sub')
 
187
        s = SFTPTransport('sftp://host.com/abs/path', clone_from=fake)
 
188
        self.assertEquals(s.relpath('sftp://host.com/abs/path/sub'), 'sub')
200
189
 
201
190
        # Make sure it works when parts of the path will be url encoded
202
191
        # TODO: These may be incorrect, we might need to urllib.urlencode() before