~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-20 08:37:32 UTC
  • mfrom: (4299 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4300.
  • Revision ID: tanner@real-time.com-20090420083732-bzx919oo7wpmqc2u
[merge] 1.14rc2 back into bzr.dev (Bob Tanner)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import bz2
27
27
from cStringIO import StringIO
 
28
import getpass
28
29
 
29
30
from bzrlib import (
30
31
    bzrdir,
769
770
        return OldSmartClient()
770
771
 
771
772
 
772
 
class RemoteBranchTestCase(TestRemote):
 
773
class RemoteBzrDirTestCase(TestRemote):
 
774
 
 
775
    def make_remote_bzrdir(self, transport, client):
 
776
        """Make a RemotebzrDir using 'client' as the _client."""
 
777
        return RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
778
            _client=client)
 
779
 
 
780
 
 
781
class RemoteBranchTestCase(RemoteBzrDirTestCase):
773
782
 
774
783
    def make_remote_branch(self, transport, client):
775
784
        """Make a RemoteBranch using 'client' as its _SmartClient.
780
789
        # we do not want bzrdir to make any remote calls, so use False as its
781
790
        # _client.  If it tries to make a remote call, this will fail
782
791
        # immediately.
783
 
        bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
784
 
            _client=False)
 
792
        bzrdir = self.make_remote_bzrdir(transport, False)
785
793
        repo = RemoteRepository(bzrdir, None, _client=client)
786
794
        branch_format = self.get_branch_format()
787
795
        format = RemoteBranchFormat(network_name=branch_format.network_name())
836
844
        branch = self.make_remote_branch(transport, client)
837
845
        result = branch.get_parent()
838
846
        self.assertEqual('http://foo/', result)
 
847
        client.finished_test()
 
848
 
 
849
 
 
850
class TestBranchSetParentLocation(RemoteBranchTestCase):
 
851
 
 
852
    def test_no_parent(self):
 
853
        # We call the verb when setting parent to None
 
854
        transport = MemoryTransport()
 
855
        client = FakeClient(transport.base)
 
856
        client.add_expected_call(
 
857
            'Branch.get_stacked_on_url', ('quack/',),
 
858
            'error', ('NotStacked',))
 
859
        client.add_expected_call(
 
860
            'Branch.set_parent_location', ('quack/', 'b', 'r', ''),
 
861
            'success', ())
 
862
        transport.mkdir('quack')
 
863
        transport = transport.clone('quack')
 
864
        branch = self.make_remote_branch(transport, client)
 
865
        branch._lock_token = 'b'
 
866
        branch._repo_lock_token = 'r'
 
867
        branch._set_parent_location(None)
 
868
        client.finished_test()
 
869
 
 
870
    def test_parent(self):
 
871
        transport = MemoryTransport()
 
872
        client = FakeClient(transport.base)
 
873
        client.add_expected_call(
 
874
            'Branch.get_stacked_on_url', ('kwaak/',),
 
875
            'error', ('NotStacked',))
 
876
        client.add_expected_call(
 
877
            'Branch.set_parent_location', ('kwaak/', 'b', 'r', 'foo'),
 
878
            'success', ())
 
879
        transport.mkdir('kwaak')
 
880
        transport = transport.clone('kwaak')
 
881
        branch = self.make_remote_branch(transport, client)
 
882
        branch._lock_token = 'b'
 
883
        branch._repo_lock_token = 'r'
 
884
        branch._set_parent_location('foo')
 
885
        client.finished_test()
 
886
 
 
887
    def test_backwards_compat(self):
 
888
        self.setup_smart_server_with_call_log()
 
889
        branch = self.make_branch('.')
 
890
        self.reset_smart_call_log()
 
891
        verb = 'Branch.set_parent_location'
 
892
        self.disable_verb(verb)
 
893
        branch.set_parent('http://foo/')
 
894
        self.assertLength(12, self.hpss_calls)
839
895
 
840
896
 
841
897
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1418
1474
        client.finished_test()
1419
1475
 
1420
1476
 
 
1477
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
 
1478
 
 
1479
    def test__get_config(self):
 
1480
        client = FakeClient()
 
1481
        client.add_success_response_with_body('default_stack_on = /\n', 'ok')
 
1482
        transport = MemoryTransport()
 
1483
        bzrdir = self.make_remote_bzrdir(transport, client)
 
1484
        config = bzrdir.get_config()
 
1485
        self.assertEqual('/', config.get_default_stack_on())
 
1486
        self.assertEqual(
 
1487
            [('call_expecting_body', 'BzrDir.get_config_file', ('memory:///',))],
 
1488
            client._calls)
 
1489
 
 
1490
    def test_set_option_uses_vfs(self):
 
1491
        self.setup_smart_server_with_call_log()
 
1492
        bzrdir = self.make_bzrdir('.')
 
1493
        self.reset_smart_call_log()
 
1494
        config = bzrdir.get_config()
 
1495
        config.set_default_stack_on('/')
 
1496
        self.assertLength(3, self.hpss_calls)
 
1497
 
 
1498
    def test_backwards_compat_get_option(self):
 
1499
        self.setup_smart_server_with_call_log()
 
1500
        bzrdir = self.make_bzrdir('.')
 
1501
        verb = 'BzrDir.get_config_file'
 
1502
        self.disable_verb(verb)
 
1503
        self.reset_smart_call_log()
 
1504
        self.assertEqual(None,
 
1505
            bzrdir._get_config().get_option('default_stack_on'))
 
1506
        self.assertLength(3, self.hpss_calls)
 
1507
 
 
1508
 
1421
1509
class TestTransportIsReadonly(tests.TestCase):
1422
1510
 
1423
1511
    def test_true(self):
1472
1560
 
1473
1561
class TestRemoteSSHTransportAuthentication(tests.TestCaseInTempDir):
1474
1562
 
1475
 
    def test_defaults_to_none(self):
 
1563
    def test_defaults_to_getuser(self):
1476
1564
        t = RemoteSSHTransport('bzr+ssh://example.com')
1477
 
        self.assertIs(None, t._get_credentials()[0])
 
1565
        self.assertIs(getpass.getuser(), t._get_credentials()[0])
1478
1566
 
1479
1567
    def test_uses_authentication_config(self):
1480
1568
        conf = config.AuthenticationConfig()
2409
2497
        try:
2410
2498
            # it should have an appropriate fallback repository, which should also
2411
2499
            # be a RemoteRepository
2412
 
            self.assertEquals(len(remote_repo._fallback_repositories), 1)
 
2500
            self.assertLength(1, remote_repo._fallback_repositories)
2413
2501
            self.assertIsInstance(remote_repo._fallback_repositories[0],
2414
2502
                RemoteRepository)
2415
2503
            # and it has the revision committed to the underlying repository;