/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Andrew Bennetts
  • Date: 2011-01-06 06:26:23 UTC
  • mto: This revision was merged to the branch mainline in revision 5612.
  • Revision ID: andrew.bennetts@canonical.com-20110106062623-43tda58mqroybjui
Start of a developer doc describing how fetch works.

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
    )
55
58
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
59
from bzrlib.revision import NULL_REVISION
57
 
from bzrlib.smart import medium
 
60
from bzrlib.smart import medium, request
58
61
from bzrlib.smart.client import _SmartClient
59
 
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
 
62
from bzrlib.smart.repository import (
 
63
    SmartServerRepositoryGetParentMap,
 
64
    SmartServerRepositoryGetStream_1_19,
 
65
    )
60
66
from bzrlib.tests import (
61
67
    condition_isinstance,
62
 
    split_suite_by_condition,
63
68
    multiply_tests,
64
69
    test_server,
65
70
    )
66
 
from bzrlib.transport import get_transport
 
71
from bzrlib.tests.scenarios import load_tests_apply_scenarios
67
72
from bzrlib.transport.memory import MemoryTransport
68
73
from bzrlib.transport.remote import (
69
74
    RemoteTransport,
71
76
    RemoteTCPTransport,
72
77
)
73
78
 
74
 
def load_tests(standard_tests, module, loader):
75
 
    to_adapt, result = split_suite_by_condition(
76
 
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
77
 
    smart_server_version_scenarios = [
 
79
 
 
80
load_tests = load_tests_apply_scenarios
 
81
 
 
82
 
 
83
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
 
84
 
 
85
    scenarios = [
78
86
        ('HPSS-v2',
79
 
         {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
 
87
            {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
80
88
        ('HPSS-v3',
81
 
         {'transport_server': test_server.SmartTCPServer_for_testing})]
82
 
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
83
 
 
84
 
 
85
 
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
 
89
            {'transport_server': test_server.SmartTCPServer_for_testing})]
 
90
 
86
91
 
87
92
    def setUp(self):
88
93
        super(BasicRemoteObjectTests, self).setUp()
89
94
        self.transport = self.get_transport()
90
95
        # make a branch that can be opened over the smart transport
91
96
        self.local_wt = BzrDir.create_standalone_workingtree('.')
92
 
 
93
 
    def tearDown(self):
94
 
        self.transport.disconnect()
95
 
        tests.TestCaseWithTransport.tearDown(self)
 
97
        self.addCleanup(self.transport.disconnect)
96
98
 
97
99
    def test_create_remote_bzrdir(self):
98
100
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
122
124
    def test_find_correct_format(self):
123
125
        """Should open a RemoteBzrDir over a RemoteTransport"""
124
126
        fmt = BzrDirFormat.find_format(self.transport)
125
 
        self.assertTrue(RemoteBzrDirFormat
126
 
                        in BzrDirFormat._control_server_formats)
 
127
        self.assertTrue(bzrdir.RemoteBzrProber
 
128
                        in controldir.ControlDirFormat._server_probers)
127
129
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
128
130
 
129
131
    def test_open_detected_smart_format(self):
359
361
        a given client_base and transport_base.
360
362
        """
361
363
        client_medium = medium.SmartClientMedium(client_base)
362
 
        transport = get_transport(transport_base)
363
 
        result = client_medium.remote_path_from_transport(transport)
 
364
        t = transport.get_transport(transport_base)
 
365
        result = client_medium.remote_path_from_transport(t)
364
366
        self.assertEqual(expected, result)
365
367
 
366
368
    def test_remote_path_from_transport(self):
377
379
        a given transport_base and relpath of that transport.  (Note that
378
380
        HttpTransportBase is a subclass of SmartClientMedium)
379
381
        """
380
 
        base_transport = get_transport(transport_base)
 
382
        base_transport = transport.get_transport(transport_base)
381
383
        client_medium = base_transport.get_smart_medium()
382
384
        cloned_transport = base_transport.clone(relpath)
383
385
        result = client_medium.remote_path_from_transport(cloned_transport)
686
688
        old.
687
689
        """
688
690
        self.assertRaises(errors.NotBranchError,
689
 
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
 
691
            RemoteBzrProber.probe_transport, OldServerTransport())
690
692
 
691
693
 
692
694
class TestBzrDirCreateBranch(TestRemote):
1618
1620
    def test_get_multi_line_branch_conf(self):
1619
1621
        # Make sure that multiple-line branch.conf files are supported
1620
1622
        #
1621
 
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
 
1623
        # https://bugs.launchpad.net/bzr/+bug/354075
1622
1624
        client = FakeClient()
1623
1625
        client.add_expected_call(
1624
1626
            'Branch.get_stacked_on_url', ('memory:///',),
1652
1654
        branch.unlock()
1653
1655
        self.assertFinished(client)
1654
1656
 
 
1657
    def test_set_option_with_dict(self):
 
1658
        client = FakeClient()
 
1659
        client.add_expected_call(
 
1660
            'Branch.get_stacked_on_url', ('memory:///',),
 
1661
            'error', ('NotStacked',),)
 
1662
        client.add_expected_call(
 
1663
            'Branch.lock_write', ('memory:///', '', ''),
 
1664
            'success', ('ok', 'branch token', 'repo token'))
 
1665
        encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
 
1666
        client.add_expected_call(
 
1667
            'Branch.set_config_option_dict', ('memory:///', 'branch token',
 
1668
            'repo token', encoded_dict_value, 'foo', ''),
 
1669
            'success', ())
 
1670
        client.add_expected_call(
 
1671
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
 
1672
            'success', ('ok',))
 
1673
        transport = MemoryTransport()
 
1674
        branch = self.make_remote_branch(transport, client)
 
1675
        branch.lock_write()
 
1676
        config = branch._get_config()
 
1677
        config.set_option(
 
1678
            {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
 
1679
            'foo')
 
1680
        branch.unlock()
 
1681
        self.assertFinished(client)
 
1682
 
1655
1683
    def test_backwards_compat_set_option(self):
1656
1684
        self.setup_smart_server_with_call_log()
1657
1685
        branch = self.make_branch('.')
1664
1692
        self.assertLength(10, self.hpss_calls)
1665
1693
        self.assertEqual('value', branch._get_config().get_option('name'))
1666
1694
 
 
1695
    def test_backwards_compat_set_option_with_dict(self):
 
1696
        self.setup_smart_server_with_call_log()
 
1697
        branch = self.make_branch('.')
 
1698
        verb = 'Branch.set_config_option_dict'
 
1699
        self.disable_verb(verb)
 
1700
        branch.lock_write()
 
1701
        self.addCleanup(branch.unlock)
 
1702
        self.reset_smart_call_log()
 
1703
        config = branch._get_config()
 
1704
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
 
1705
        config.set_option(value_dict, 'name')
 
1706
        self.assertLength(10, self.hpss_calls)
 
1707
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
 
1708
 
1667
1709
 
1668
1710
class TestBranchLockWrite(RemoteBranchTestCase):
1669
1711
 
1828
1870
class TestRepositoryFormat(TestRemoteRepository):
1829
1871
 
1830
1872
    def test_fast_delta(self):
1831
 
        true_name = groupcompress_repo.RepositoryFormatCHK1().network_name()
 
1873
        true_name = groupcompress_repo.RepositoryFormat2a().network_name()
1832
1874
        true_format = RemoteRepositoryFormat()
1833
1875
        true_format._network_name = true_name
1834
1876
        self.assertEqual(True, true_format.fast_deltas)
2257
2299
        self.setup_smart_server_with_call_log()
2258
2300
        tree = self.make_branch_and_memory_tree('.')
2259
2301
        tree.lock_write()
 
2302
        tree.add('')
2260
2303
        rev1 = tree.commit('First')
2261
2304
        rev2 = tree.commit('Second')
2262
2305
        tree.unlock()
3142
3185
 
3143
3186
    def test_copy_content_into_avoids_revision_history(self):
3144
3187
        local = self.make_branch('local')
3145
 
        remote_backing_tree = self.make_branch_and_tree('remote')
3146
 
        remote_backing_tree.commit("Commit.")
 
3188
        builder = self.make_branch_builder('remote')
 
3189
        builder.build_commit(message="Commit.")
3147
3190
        remote_branch_url = self.smart_server.get_url() + 'remote'
3148
3191
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3149
3192
        local.repository.fetch(remote_branch.repository)
3150
3193
        self.hpss_calls = []
3151
3194
        remote_branch.copy_content_into(local)
3152
3195
        self.assertFalse('Branch.revision_history' in self.hpss_calls)
 
3196
 
 
3197
    def test_fetch_everything_needs_just_one_call(self):
 
3198
        local = self.make_branch('local')
 
3199
        builder = self.make_branch_builder('remote')
 
3200
        builder.build_commit(message="Commit.")
 
3201
        remote_branch_url = self.smart_server.get_url() + 'remote'
 
3202
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
 
3203
        self.hpss_calls = []
 
3204
        local.repository.fetch(remote_branch.repository,
 
3205
                fetch_spec=graph.EverythingResult(remote_branch.repository))
 
3206
        self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
 
3207
 
 
3208
    def override_verb(self, verb_name, verb):
 
3209
        request_handlers = request.request_handlers
 
3210
        orig_verb = request_handlers.get(verb_name)
 
3211
        request_handlers.register(verb_name, verb, override_existing=True)
 
3212
        self.addCleanup(request_handlers.register, verb_name, orig_verb,
 
3213
                override_existing=True)
 
3214
 
 
3215
    def test_fetch_everything_backwards_compat(self):
 
3216
        """Can fetch with EverythingResult even with pre 2.3 servers.
 
3217
        
 
3218
        Pre-2.3 do not support 'everything' searches with the
 
3219
        Repository.get_stream_1.19 verb.
 
3220
        """
 
3221
        verb_log = []
 
3222
        class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
 
3223
            """A version of the Repository.get_stream_1.19 verb patched to
 
3224
            reject 'everything' searches the way 2.2 and earlier do.
 
3225
            """
 
3226
            def recreate_search(self, repository, search_bytes, discard_excess=False):
 
3227
                verb_log.append(search_bytes.split('\n', 1)[0])
 
3228
                if search_bytes == 'everything':
 
3229
                    return (None, request.FailedSmartServerResponse(('BadSearch',)))
 
3230
                return super(OldGetStreamVerb,
 
3231
                        self).recreate_search(repository, search_bytes,
 
3232
                            discard_excess=discard_excess)
 
3233
        self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
 
3234
        local = self.make_branch('local')
 
3235
        builder = self.make_branch_builder('remote')
 
3236
        builder.build_commit(message="Commit.")
 
3237
        remote_branch_url = self.smart_server.get_url() + 'remote'
 
3238
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
 
3239
        self.hpss_calls = []
 
3240
        local.repository.fetch(remote_branch.repository,
 
3241
                fetch_spec=graph.EverythingResult(remote_branch.repository))
 
3242
        # make sure the overridden verb was used
 
3243
        self.assertLength(1, verb_log)
 
3244
        # more than one HPSS call is needed, but because it's a VFS callback
 
3245
        # its hard to predict exactly how many.
 
3246
        self.assertTrue(len(self.hpss_calls) > 1)
 
3247