~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp.py

[merge] sftp fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
# XXX: 20051124 jamesh
32
32
# The tests currently pop up a password prompt when an external ssh
33
33
# is used.  This forces the use of the paramiko implementation.
34
 
import bzrlib.transport.sftp
35
 
bzrlib.transport.sftp._ssh_vendor = 'none'
 
34
if paramiko_loaded:
 
35
    import bzrlib.transport.sftp
 
36
    bzrlib.transport.sftp._ssh_vendor = 'none'
36
37
 
37
38
 
38
39
STUB_SERVER_KEY = """
191
192
        from bzrlib.transport.sftp import SFTPTransport
192
193
        s = SFTPTransport('sftp://simple.example.com/%2fhome/source', clone_from=fake)
193
194
        self.assertEquals(s._host, 'simple.example.com')
194
 
        self.assertEquals(s._port, 22)
 
195
        self.assertEquals(s._port, None)
195
196
        self.assertEquals(s._path, '/home/source')
196
197
        self.failUnless(s._password is None)
197
198
 
216
217
        self.assertEquals(s._path, '/absolute/path')
217
218
 
218
219
        # Also, don't show the port if it is the default 22
219
 
        self.assertEquals(s.base, 'sftp://user@example.com/%2Fabsolute/path')
 
220
        self.assertEquals(s.base, 'sftp://user@example.com:22/%2Fabsolute/path')
 
221
 
 
222
    def test_relpath(self):
 
223
        from bzrlib.transport.sftp import SFTPTransport
 
224
        from bzrlib.errors import NonRelativePath
 
225
 
 
226
        s = SFTPTransport('sftp://user@host.com//abs/path', clone_from=fake)
 
227
        self.assertEquals(s.relpath('sftp://user@host.com//abs/path/sub'), 'sub')
 
228
        # Can't test this one, because we actually get an AssertionError
 
229
        # TODO: Consider raising an exception rather than an assert
 
230
        #self.assertRaises(NonRelativePath, s.relpath, 'http://user@host.com//abs/path/sub')
 
231
        self.assertRaises(NonRelativePath, s.relpath, 'sftp://user2@host.com//abs/path/sub')
 
232
        self.assertRaises(NonRelativePath, s.relpath, 'sftp://user@otherhost.com//abs/path/sub')
 
233
        self.assertRaises(NonRelativePath, s.relpath, 'sftp://user@host.com:33//abs/path/sub')
 
234
        self.assertRaises(NonRelativePath, s.relpath, 'sftp://user@host.com/abs/path/sub')
 
235
 
 
236
        # Make sure it works when we don't supply a username
 
237
        s = SFTPTransport('sftp://host.com//abs/path', clone_from=fake)
 
238
        self.assertEquals(s.relpath('sftp://host.com//abs/path/sub'), 'sub')
 
239
 
 
240
        # Make sure it works when parts of the path will be url encoded
 
241
        # TODO: These may be incorrect, we might need to urllib.urlencode() before
 
242
        # we pass the paths into the SFTPTransport constructor
 
243
        s = SFTPTransport('sftp://host.com/dev/,path', clone_from=fake)
 
244
        self.assertEquals(s.relpath('sftp://host.com/dev/,path/sub'), 'sub')
 
245
        s = SFTPTransport('sftp://host.com/dev/%path', clone_from=fake)
 
246
        self.assertEquals(s.relpath('sftp://host.com/dev/%path/sub'), 'sub')
220
247
 
221
248
    def test_parse_invalid_url(self):
222
249
        from bzrlib.transport.sftp import SFTPTransport, SFTPTransportError