~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-06 14:26:08 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070606142608-i9ufaqewadslf1cn
Finish sftp refactoring. Test suite passing.

* bzrlib/transport/sftp.py:
(clear_connection_cache): Deprecated.
(_sftp_connect, _sftp_connect_uncached): Deleted.
(SFTPTransport.__init__): Simplified.
(SFTPTransport._create_connection): New method. Copied from
_sftp_connect_uncached
(SFTPTransport._get_sftp): New method. Ensures that the connection
is established.
(SFTPTransport.clone): Deleted.
(SFTPTransport.has, SFTPTransport.get, SFTPTransport.readv,
SFTPTransport._put,
SFTPTransport._put_non_atomic_helper._open_and_write_file,
SFTPTransport._mkdir, SFTPTransport.append_file,
SFTPTransport.rename, SFTPTransport._rename_and_overwrite,
SFTPTransport.delete, SFTPTransport.rmdir, SFTPTransport.stat):
Use _get_sftp.

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_connection_error): Simplified now that sftp
does not connection on construction.

* bzrlib/tests/test_sftp_transport.py:
(SFTPLockTests.test_sftp_locks): Delete test_multiple_connections.
(FakeSFTPTransport): Deleted.
(SFTPNonServerTest.test_parse_url_with_home_dir,
SFTPNonServerTest.test_relpath,
SSHVendorBadConnection.test_bad_connection_paramiko): Delete the
from_transport parameter as it's not needed anymore.
(SFTPLatencyKnob.test_latency_knob_slows_transport,
SFTPLatencyKnob.test_default): Force connection by issuing a
request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        l.unlock()
105
105
        l2.unlock()
106
106
 
107
 
    def test_multiple_connections(self):
108
 
        t = self.get_transport()
109
 
        self.assertTrue('sftpserver - new connection' in self.get_server().logs)
110
 
        self.get_server().logs = []
111
 
        # The second request should reuse the first connection
112
 
        # SingleListener only allows for a single connection,
113
 
        # So the next line fails unless the connection is reused
114
 
        t2 = self.get_transport()
115
 
        self.assertEquals(self.get_server().logs, [])
116
 
 
117
107
 
118
108
class SFTPTransportTestRelative(TestCaseWithSFTPServer):
119
109
    """Test the SFTP transport with homedir based relative paths."""
155
145
        self.assertEqual('a', t._remote_path('a'))
156
146
 
157
147
 
158
 
class FakeSFTPTransport (object):
159
 
    _sftp = object()
160
 
    _password = None
161
 
 
162
 
    def get_connection(self):
163
 
        return None
164
 
 
165
 
 
166
 
avoid_sftp_connection = FakeSFTPTransport()
167
 
 
168
 
 
169
148
class SFTPNonServerTest(TestCase):
170
149
    def setUp(self):
171
150
        TestCase.setUp(self)
173
152
            raise TestSkipped('you must have paramiko to run this test')
174
153
 
175
154
    def test_parse_url_with_home_dir(self):
176
 
        s = SFTPTransport('sftp://ro%62ey:h%40t@example.com:2222/~/relative',
177
 
                          from_transport=avoid_sftp_connection)
 
155
        s = SFTPTransport('sftp://ro%62ey:h%40t@example.com:2222/~/relative')
178
156
        self.assertEquals(s._host, 'example.com')
179
157
        self.assertEquals(s._port, 2222)
180
158
        self.assertEquals(s._user, 'robey')
181
 
        # FIXME: sftp should just not connect at init time !!!
182
 
        #self.assertEquals(s._password, 'h@t')
 
159
        self.assertEquals(s._password, 'h@t')
183
160
        self.assertEquals(s._path, '/~/relative/')
184
161
 
185
162
    def test_relpath(self):
186
 
        s = SFTPTransport('sftp://user@host.com/abs/path',
187
 
                          from_transport=avoid_sftp_connection)
 
163
        s = SFTPTransport('sftp://user@host.com/abs/path')
188
164
        self.assertRaises(errors.PathNotChild, s.relpath,
189
165
                          'sftp://user@host.com/~/rel/path/sub')
190
166
 
339
315
        """Test that a real connection attempt raises the right error"""
340
316
        from bzrlib.transport import ssh
341
317
        self.set_vendor(ssh.ParamikoVendor())
342
 
        self.assertRaises(errors.ConnectionError,
343
 
                          bzrlib.transport.get_transport, self.bogus_url)
 
318
        t = bzrlib.transport.get_transport(self.bogus_url)
 
319
        self.assertRaises(errors.ConnectionError, t.get, 'foobar')
344
320
 
345
321
    def test_bad_connection_ssh(self):
346
322
        """None => auto-detect vendor"""
381
357
        start_time = time.time()
382
358
        self.get_server().add_latency = 0.5
383
359
        transport = self.get_transport()
 
360
        transport.has('not me') # Force connection by issuing a request
384
361
        with_latency_knob_time = time.time() - start_time
385
362
        self.assertTrue(with_latency_knob_time > 0.4)
386
363
 
389
366
        # it could fail, but that is quite unlikely
390
367
        start_time = time.time()
391
368
        transport = self.get_transport()
 
369
        transport.has('not me') # Force connection by issuing a request
392
370
        regular_time = time.time() - start_time
393
371
        self.assertTrue(regular_time < 0.5)
394
372