~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-08 10:50:51 UTC
  • mfrom: (5050.17.31 2.2.2-dev)
  • mto: This revision was merged to the branch mainline in revision 5474.
  • Revision ID: v.ladeuil+lp@free.fr-20101008105051-xd4knkrohzclffic
Merge 2.2 into trunk including fixes for bug #651706 and bug #646133

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    branch,
31
31
    bzrdir,
32
32
    config,
 
33
    controldir,
33
34
    errors,
34
35
    graph,
35
36
    inventory,
36
37
    inventory_delta,
37
 
    pack,
38
38
    remote,
39
39
    repository,
40
40
    tests,
 
41
    transport,
41
42
    treebuilder,
42
 
    urlutils,
43
43
    versionedfile,
44
44
    )
45
45
from bzrlib.branch import Branch
46
 
from bzrlib.bzrdir import BzrDir, BzrDirFormat
 
46
from bzrlib.bzrdir import (
 
47
    BzrDir,
 
48
    BzrDirFormat,
 
49
    RemoteBzrProber,
 
50
    )
47
51
from bzrlib.remote import (
48
52
    RemoteBranch,
49
53
    RemoteBranchFormat,
50
54
    RemoteBzrDir,
51
 
    RemoteBzrDirFormat,
52
55
    RemoteRepository,
53
56
    RemoteRepositoryFormat,
54
57
    )
63
66
    multiply_tests,
64
67
    test_server,
65
68
    )
66
 
from bzrlib.transport import get_transport
67
69
from bzrlib.transport.memory import MemoryTransport
68
70
from bzrlib.transport.remote import (
69
71
    RemoteTransport,
89
91
        self.transport = self.get_transport()
90
92
        # make a branch that can be opened over the smart transport
91
93
        self.local_wt = BzrDir.create_standalone_workingtree('.')
92
 
 
93
 
    def tearDown(self):
94
 
        self.transport.disconnect()
95
 
        tests.TestCaseWithTransport.tearDown(self)
 
94
        self.addCleanup(self.transport.disconnect)
96
95
 
97
96
    def test_create_remote_bzrdir(self):
98
97
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
122
121
    def test_find_correct_format(self):
123
122
        """Should open a RemoteBzrDir over a RemoteTransport"""
124
123
        fmt = BzrDirFormat.find_format(self.transport)
125
 
        self.assertTrue(RemoteBzrDirFormat
126
 
                        in BzrDirFormat._control_server_formats)
 
124
        self.assertTrue(bzrdir.RemoteBzrProber
 
125
                        in controldir.ControlDirFormat._server_probers)
127
126
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
128
127
 
129
128
    def test_open_detected_smart_format(self):
359
358
        a given client_base and transport_base.
360
359
        """
361
360
        client_medium = medium.SmartClientMedium(client_base)
362
 
        transport = get_transport(transport_base)
363
 
        result = client_medium.remote_path_from_transport(transport)
 
361
        t = transport.get_transport(transport_base)
 
362
        result = client_medium.remote_path_from_transport(t)
364
363
        self.assertEqual(expected, result)
365
364
 
366
365
    def test_remote_path_from_transport(self):
377
376
        a given transport_base and relpath of that transport.  (Note that
378
377
        HttpTransportBase is a subclass of SmartClientMedium)
379
378
        """
380
 
        base_transport = get_transport(transport_base)
 
379
        base_transport = transport.get_transport(transport_base)
381
380
        client_medium = base_transport.get_smart_medium()
382
381
        cloned_transport = base_transport.clone(relpath)
383
382
        result = client_medium.remote_path_from_transport(cloned_transport)
609
608
        # _get_tree_branch is a form of open_branch, but it should only ask for
610
609
        # branch opening, not any other network requests.
611
610
        calls = []
612
 
        def open_branch():
 
611
        def open_branch(name=None):
613
612
            calls.append("Called")
614
613
            return "a-branch"
615
614
        transport = MemoryTransport()
686
685
        old.
687
686
        """
688
687
        self.assertRaises(errors.NotBranchError,
689
 
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
 
688
            RemoteBzrProber.probe_transport, OldServerTransport())
690
689
 
691
690
 
692
691
class TestBzrDirCreateBranch(TestRemote):
1618
1617
    def test_get_multi_line_branch_conf(self):
1619
1618
        # Make sure that multiple-line branch.conf files are supported
1620
1619
        #
1621
 
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
 
1620
        # https://bugs.launchpad.net/bzr/+bug/354075
1622
1621
        client = FakeClient()
1623
1622
        client.add_expected_call(
1624
1623
            'Branch.get_stacked_on_url', ('memory:///',),
1652
1651
        branch.unlock()
1653
1652
        self.assertFinished(client)
1654
1653
 
 
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
 
1655
1680
    def test_backwards_compat_set_option(self):
1656
1681
        self.setup_smart_server_with_call_log()
1657
1682
        branch = self.make_branch('.')
1664
1689
        self.assertLength(10, self.hpss_calls)
1665
1690
        self.assertEqual('value', branch._get_config().get_option('name'))
1666
1691
 
 
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
 
1667
1706
 
1668
1707
class TestBranchLockWrite(RemoteBranchTestCase):
1669
1708
 
2257
2296
        self.setup_smart_server_with_call_log()
2258
2297
        tree = self.make_branch_and_memory_tree('.')
2259
2298
        tree.lock_write()
 
2299
        tree.add('')
2260
2300
        rev1 = tree.commit('First')
2261
2301
        rev2 = tree.commit('Second')
2262
2302
        tree.unlock()
2301
2341
        transport_path = 'quack'
2302
2342
        repo, client = self.setup_fake_client_and_repository(transport_path)
2303
2343
        client.add_success_response('ok', 'a token')
2304
 
        result = repo.lock_write()
 
2344
        token = repo.lock_write().repository_token
2305
2345
        self.assertEqual(
2306
2346
            [('call', 'Repository.lock_write', ('quack/', ''))],
2307
2347
            client._calls)
2308
 
        self.assertEqual('a token', result)
 
2348
        self.assertEqual('a token', token)
2309
2349
 
2310
2350
    def test_lock_write_already_locked(self):
2311
2351
        transport_path = 'quack'