~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    branch,
31
31
    bzrdir,
32
32
    config,
33
 
    controldir,
34
33
    errors,
35
34
    graph,
36
35
    inventory,
37
36
    inventory_delta,
 
37
    pack,
38
38
    remote,
39
39
    repository,
40
40
    tests,
41
 
    transport,
42
41
    treebuilder,
 
42
    urlutils,
43
43
    versionedfile,
44
44
    )
45
45
from bzrlib.branch import Branch
46
 
from bzrlib.bzrdir import (
47
 
    BzrDir,
48
 
    BzrDirFormat,
49
 
    RemoteBzrProber,
50
 
    )
 
46
from bzrlib.bzrdir import BzrDir, BzrDirFormat
51
47
from bzrlib.remote import (
52
48
    RemoteBranch,
53
49
    RemoteBranchFormat,
54
50
    RemoteBzrDir,
 
51
    RemoteBzrDirFormat,
55
52
    RemoteRepository,
56
53
    RemoteRepositoryFormat,
57
54
    )
66
63
    multiply_tests,
67
64
    test_server,
68
65
    )
 
66
from bzrlib.transport import get_transport
69
67
from bzrlib.transport.memory import MemoryTransport
70
68
from bzrlib.transport.remote import (
71
69
    RemoteTransport,
91
89
        self.transport = self.get_transport()
92
90
        # make a branch that can be opened over the smart transport
93
91
        self.local_wt = BzrDir.create_standalone_workingtree('.')
94
 
        self.addCleanup(self.transport.disconnect)
 
92
 
 
93
    def tearDown(self):
 
94
        self.transport.disconnect()
 
95
        tests.TestCaseWithTransport.tearDown(self)
95
96
 
96
97
    def test_create_remote_bzrdir(self):
97
98
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
121
122
    def test_find_correct_format(self):
122
123
        """Should open a RemoteBzrDir over a RemoteTransport"""
123
124
        fmt = BzrDirFormat.find_format(self.transport)
124
 
        self.assertTrue(bzrdir.RemoteBzrProber
125
 
                        in controldir.ControlDirFormat._server_probers)
 
125
        self.assertTrue(RemoteBzrDirFormat
 
126
                        in BzrDirFormat._control_server_formats)
126
127
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
127
128
 
128
129
    def test_open_detected_smart_format(self):
358
359
        a given client_base and transport_base.
359
360
        """
360
361
        client_medium = medium.SmartClientMedium(client_base)
361
 
        t = transport.get_transport(transport_base)
362
 
        result = client_medium.remote_path_from_transport(t)
 
362
        transport = get_transport(transport_base)
 
363
        result = client_medium.remote_path_from_transport(transport)
363
364
        self.assertEqual(expected, result)
364
365
 
365
366
    def test_remote_path_from_transport(self):
376
377
        a given transport_base and relpath of that transport.  (Note that
377
378
        HttpTransportBase is a subclass of SmartClientMedium)
378
379
        """
379
 
        base_transport = transport.get_transport(transport_base)
 
380
        base_transport = get_transport(transport_base)
380
381
        client_medium = base_transport.get_smart_medium()
381
382
        cloned_transport = base_transport.clone(relpath)
382
383
        result = client_medium.remote_path_from_transport(cloned_transport)
417
418
        # Calling _remember_remote_is_before again with a lower value works.
418
419
        client_medium._remember_remote_is_before((1, 5))
419
420
        self.assertTrue(client_medium._is_remote_before((1, 5)))
420
 
        # If you call _remember_remote_is_before with a higher value it logs a
421
 
        # warning, and continues to remember the lower value.
422
 
        self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
423
 
        client_medium._remember_remote_is_before((1, 9))
424
 
        self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
425
 
        self.assertTrue(client_medium._is_remote_before((1, 5)))
 
421
        # You cannot call _remember_remote_is_before with a larger value.
 
422
        self.assertRaises(
 
423
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
426
424
 
427
425
 
428
426
class TestBzrDirCloningMetaDir(TestRemote):
530
528
        self.assertIsInstance(bd, RemoteBzrDir)
531
529
        self.assertFinished(client)
532
530
 
533
 
    def test_backwards_compat_hpss_v2(self):
534
 
        client, transport = self.make_fake_client_and_transport()
535
 
        # Monkey-patch fake client to simulate real-world behaviour with v2
536
 
        # server: upon first RPC call detect the protocol version, and because
537
 
        # the version is 2 also do _remember_remote_is_before((1, 6)) before
538
 
        # continuing with the RPC.
539
 
        orig_check_call = client._check_call
540
 
        def check_call(method, args):
541
 
            client._medium._protocol_version = 2
542
 
            client._medium._remember_remote_is_before((1, 6))
543
 
            client._check_call = orig_check_call
544
 
            client._check_call(method, args)
545
 
        client._check_call = check_call
546
 
        client.add_expected_call(
547
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
548
 
        client.add_expected_call(
549
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
550
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
551
 
            _client=client, _force_probe=True)
552
 
        self.assertIsInstance(bd, RemoteBzrDir)
553
 
        self.assertFinished(client)
554
 
 
555
531
 
556
532
class TestBzrDirOpenBranch(TestRemote):
557
533
 
608
584
        # _get_tree_branch is a form of open_branch, but it should only ask for
609
585
        # branch opening, not any other network requests.
610
586
        calls = []
611
 
        def open_branch(name=None):
 
587
        def open_branch():
612
588
            calls.append("Called")
613
589
            return "a-branch"
614
590
        transport = MemoryTransport()
685
661
        old.
686
662
        """
687
663
        self.assertRaises(errors.NotBranchError,
688
 
            RemoteBzrProber.probe_transport, OldServerTransport())
 
664
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
689
665
 
690
666
 
691
667
class TestBzrDirCreateBranch(TestRemote):
1247
1223
            len(branch.repository._real_repository._fallback_repositories))
1248
1224
 
1249
1225
    def test_get_stacked_on_real_branch(self):
1250
 
        base_branch = self.make_branch('base')
1251
 
        stacked_branch = self.make_branch('stacked')
 
1226
        base_branch = self.make_branch('base', format='1.6')
 
1227
        stacked_branch = self.make_branch('stacked', format='1.6')
1252
1228
        stacked_branch.set_stacked_on_url('../base')
1253
1229
        reference_format = self.get_repo_format()
1254
1230
        network_name = reference_format.network_name()
1259
1235
            'success', ('branch', branch_network_name))
1260
1236
        client.add_expected_call(
1261
1237
            'BzrDir.find_repositoryV3', ('stacked/',),
1262
 
            'success', ('ok', '', 'yes', 'no', 'yes', network_name))
 
1238
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
1263
1239
        # called twice, once from constructor and then again by us
1264
1240
        client.add_expected_call(
1265
1241
            'Branch.get_stacked_on_url', ('stacked/',),
1617
1593
    def test_get_multi_line_branch_conf(self):
1618
1594
        # Make sure that multiple-line branch.conf files are supported
1619
1595
        #
1620
 
        # https://bugs.launchpad.net/bzr/+bug/354075
 
1596
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
1621
1597
        client = FakeClient()
1622
1598
        client.add_expected_call(
1623
1599
            'Branch.get_stacked_on_url', ('memory:///',),
1651
1627
        branch.unlock()
1652
1628
        self.assertFinished(client)
1653
1629
 
1654
 
    def test_set_option_with_dict(self):
1655
 
        client = FakeClient()
1656
 
        client.add_expected_call(
1657
 
            'Branch.get_stacked_on_url', ('memory:///',),
1658
 
            'error', ('NotStacked',),)
1659
 
        client.add_expected_call(
1660
 
            'Branch.lock_write', ('memory:///', '', ''),
1661
 
            'success', ('ok', 'branch token', 'repo token'))
1662
 
        encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1663
 
        client.add_expected_call(
1664
 
            'Branch.set_config_option_dict', ('memory:///', 'branch token',
1665
 
            'repo token', encoded_dict_value, 'foo', ''),
1666
 
            'success', ())
1667
 
        client.add_expected_call(
1668
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1669
 
            'success', ('ok',))
1670
 
        transport = MemoryTransport()
1671
 
        branch = self.make_remote_branch(transport, client)
1672
 
        branch.lock_write()
1673
 
        config = branch._get_config()
1674
 
        config.set_option(
1675
 
            {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1676
 
            'foo')
1677
 
        branch.unlock()
1678
 
        self.assertFinished(client)
1679
 
 
1680
1630
    def test_backwards_compat_set_option(self):
1681
1631
        self.setup_smart_server_with_call_log()
1682
1632
        branch = self.make_branch('.')
1689
1639
        self.assertLength(10, self.hpss_calls)
1690
1640
        self.assertEqual('value', branch._get_config().get_option('name'))
1691
1641
 
1692
 
    def test_backwards_compat_set_option_with_dict(self):
1693
 
        self.setup_smart_server_with_call_log()
1694
 
        branch = self.make_branch('.')
1695
 
        verb = 'Branch.set_config_option_dict'
1696
 
        self.disable_verb(verb)
1697
 
        branch.lock_write()
1698
 
        self.addCleanup(branch.unlock)
1699
 
        self.reset_smart_call_log()
1700
 
        config = branch._get_config()
1701
 
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1702
 
        config.set_option(value_dict, 'name')
1703
 
        self.assertLength(10, self.hpss_calls)
1704
 
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
1705
 
 
1706
1642
 
1707
1643
class TestBranchLockWrite(RemoteBranchTestCase):
1708
1644
 
2255
2191
        """
2256
2192
        # Make a repo with a fallback repo, both using a FakeClient.
2257
2193
        format = remote.response_tuple_to_repo_format(
2258
 
            ('yes', 'no', 'yes', self.get_repo_format().network_name()))
 
2194
            ('yes', 'no', 'yes', 'fake-network-name'))
2259
2195
        repo, client = self.setup_fake_client_and_repository('quack')
2260
2196
        repo._format = format
2261
2197
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2262
2198
            'fallback')
2263
2199
        fallback_repo._client = client
2264
 
        fallback_repo._format = format
2265
2200
        repo.add_fallback_repository(fallback_repo)
2266
2201
        # First the client should ask the primary repo
2267
2202
        client.add_expected_call(
2296
2231
        self.setup_smart_server_with_call_log()
2297
2232
        tree = self.make_branch_and_memory_tree('.')
2298
2233
        tree.lock_write()
2299
 
        tree.add('')
2300
2234
        rev1 = tree.commit('First')
2301
2235
        rev2 = tree.commit('Second')
2302
2236
        tree.unlock()
2341
2275
        transport_path = 'quack'
2342
2276
        repo, client = self.setup_fake_client_and_repository(transport_path)
2343
2277
        client.add_success_response('ok', 'a token')
2344
 
        token = repo.lock_write().repository_token
 
2278
        result = repo.lock_write()
2345
2279
        self.assertEqual(
2346
2280
            [('call', 'Repository.lock_write', ('quack/', ''))],
2347
2281
            client._calls)
2348
 
        self.assertEqual('a token', token)
 
2282
        self.assertEqual('a token', result)
2349
2283
 
2350
2284
    def test_lock_write_already_locked(self):
2351
2285
        transport_path = 'quack'