~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
        b2 = bzrdir.BzrDir.create_branch_and_repo(self.get_url('/b'))
200
200
        b2.pull(b)
201
201
 
202
 
        self.assertEquals(b2.revision_history(), ['a1'])
 
202
        self.assertEquals(b2.last_revision(), 'a1')
203
203
 
204
204
        open('a/foo', 'wt').write('something new in foo\n')
205
205
        t.commit('new', rev_id='a2')
206
206
        b2.pull(b)
207
207
 
208
 
        self.assertEquals(b2.revision_history(), ['a1', 'a2'])
 
208
        self.assertEquals(b2.last_revision(), 'a2')
209
209
 
210
210
 
211
211
class SSHVendorConnection(TestCaseWithSFTPServer):
279
279
        self.addCleanup(s.close)
280
280
        self.bogus_url = 'sftp://%s:%s/' % s.getsockname()
281
281
 
282
 
    def set_vendor(self, vendor):
 
282
    def set_vendor(self, vendor, subprocess_stderr=None):
283
283
        from bzrlib.transport import ssh
284
284
        self.overrideAttr(ssh._ssh_vendor_manager, '_cached_ssh_vendor', vendor)
 
285
        if subprocess_stderr is not None:
 
286
            self.overrideAttr(ssh.SubprocessVendor, "_stderr_target",
 
287
                subprocess_stderr)
285
288
 
286
289
    def test_bad_connection_paramiko(self):
287
290
        """Test that a real connection attempt raises the right error"""
292
295
 
293
296
    def test_bad_connection_ssh(self):
294
297
        """None => auto-detect vendor"""
295
 
        self.set_vendor(None)
296
 
        # This is how I would normally test the connection code
297
 
        # it makes it very clear what we are testing.
298
 
        # However, 'ssh' will create stipple on the output, so instead
299
 
        # I'm using run_bzr_subprocess, and parsing the output
300
 
        # try:
301
 
        #     t = _mod_transport.get_transport(self.bogus_url)
302
 
        # except errors.ConnectionError:
303
 
        #     # Correct error
304
 
        #     pass
305
 
        # except errors.NameError, e:
306
 
        #     if 'SSHException' in str(e):
307
 
        #         raise TestSkipped('Known NameError bug in paramiko 1.6.1')
308
 
        #     raise
309
 
        # else:
310
 
        #     self.fail('Excepted ConnectionError to be raised')
311
 
 
312
 
        out, err = self.run_bzr_subprocess(['log', self.bogus_url], retcode=3)
313
 
        self.assertEqual('', out)
314
 
        if "NameError: global name 'SSHException'" in err:
315
 
            # We aren't fixing this bug, because it is a bug in
316
 
            # paramiko, but we know about it, so we don't have to
317
 
            # fail the test
318
 
            raise TestSkipped('Known NameError bug with paramiko-1.6.1')
319
 
        self.assertContainsRe(err, r'bzr: ERROR: Unable to connect to SSH host'
320
 
                                   r' 127\.0\.0\.1:\d+; ')
 
298
        f = file(os.devnull, "wb")
 
299
        self.addCleanup(f.close)
 
300
        self.set_vendor(None, f)
 
301
        t = _mod_transport.get_transport_from_url(self.bogus_url)
 
302
        try:
 
303
            self.assertRaises(errors.ConnectionError, t.get, 'foobar')
 
304
        except NameError, e:
 
305
            if "global name 'SSHException'" in str(e):
 
306
                self.knownFailure('Known NameError bug in paramiko 1.6.1')
 
307
            raise
321
308
 
322
309
 
323
310
class SFTPLatencyKnob(TestCaseWithSFTPServer):