~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp.py

Merge from mbp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib.tests import TestCaseInTempDir, TestCase
22
22
from bzrlib.tests.test_transport import TestTransportMixIn
 
23
import bzrlib.errors as errors
23
24
 
24
25
try:
25
26
    import paramiko
221
222
 
222
223
    def test_relpath(self):
223
224
        from bzrlib.transport.sftp import SFTPTransport
224
 
        from bzrlib.errors import NonRelativePath
 
225
        from bzrlib.errors import PathNotChild
225
226
 
226
227
        s = SFTPTransport('sftp://user@host.com//abs/path', clone_from=fake)
227
228
        self.assertEquals(s.relpath('sftp://user@host.com//abs/path/sub'), 'sub')
228
229
        # Can't test this one, because we actually get an AssertionError
229
230
        # 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')
 
231
        #self.assertRaises(PathNotChild, s.relpath, 'http://user@host.com//abs/path/sub')
 
232
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user2@host.com//abs/path/sub')
 
233
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@otherhost.com//abs/path/sub')
 
234
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com:33//abs/path/sub')
 
235
        self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com/abs/path/sub')
235
236
 
236
237
        # Make sure it works when we don't supply a username
237
238
        s = SFTPTransport('sftp://host.com//abs/path', clone_from=fake)
246
247
        self.assertEquals(s.relpath('sftp://host.com/dev/%path/sub'), 'sub')
247
248
 
248
249
    def test_parse_invalid_url(self):
249
 
        from bzrlib.transport.sftp import SFTPTransport, SFTPTransportError
 
250
        from bzrlib.transport.sftp import SFTPTransport, TransportError
250
251
        try:
251
252
            s = SFTPTransport('sftp://lilypond.org:~janneke/public_html/bzr/gub',
252
253
                              clone_from=fake)
253
254
            self.fail('expected exception not raised')
254
 
        except SFTPTransportError, e:
 
255
        except TransportError, e:
255
256
            self.assertEquals(str(e), 
256
257
                    '~janneke: invalid port number')
257
258
 
275
276
        b.unlock()
276
277
        self.failIf(os.path.lexists('.bzr/branch-lock.write-lock'))
277
278
 
 
279
    def test_no_working_tree(self):
 
280
        from bzrlib.branch import Branch
 
281
        self.delayed_setup()
 
282
        b = Branch.initialize(self._sftp_url)
 
283
        self.assertRaises(errors.NoWorkingTree, b.working_tree)
 
284
 
 
285
    def test_push_support(self):
 
286
        from bzrlib.branch import Branch
 
287
        self.delayed_setup()
 
288
 
 
289
        self.build_tree(['a/', 'a/foo'])
 
290
        b = Branch.initialize('a')
 
291
        t = b.working_tree()
 
292
        t.add('foo')
 
293
        t.commit('foo', rev_id='a1')
 
294
 
 
295
        os.mkdir('b')
 
296
        b2 = Branch.initialize(self._sftp_url + 'b')
 
297
        b2.pull(b)
 
298
 
 
299
        self.assertEquals(b2.revision_history(), ['a1'])
 
300
 
278
301
 
279
302
if not paramiko_loaded:
280
303
    # TODO: Skip these