~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Vincent Ladeuil
  • Date: 2011-12-08 09:24:06 UTC
  • mto: This revision was merged to the branch mainline in revision 6351.
  • Revision ID: v.ladeuil+lp@free.fr-20111208092406-ueqyyoftzwk22bq4
Open 2.5b5 for bug fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
28
import zlib
29
29
 
30
30
from bzrlib import (
31
 
    bencode,
32
31
    branch,
33
32
    bzrdir,
34
33
    config,
35
34
    controldir,
36
35
    errors,
 
36
    graph as _mod_graph,
37
37
    inventory,
38
38
    inventory_delta,
39
39
    remote,
69
69
from bzrlib.smart.repository import (
70
70
    SmartServerRepositoryGetParentMap,
71
71
    SmartServerRepositoryGetStream_1_19,
72
 
    _stream_to_byte_stream,
73
72
    )
74
73
from bzrlib.symbol_versioning import deprecated_in
75
74
from bzrlib.tests import (
175
174
    def test_remote_branch_set_append_revisions_only(self):
176
175
        # Make a format 1.9 branch, which supports append_revisions_only
177
176
        branch = self.make_branch('branch', format='1.9')
 
177
        config = branch.get_config()
178
178
        branch.set_append_revisions_only(True)
179
 
        config = branch.get_config_stack()
180
179
        self.assertEqual(
181
 
            True, config.get('append_revisions_only'))
 
180
            'True', config.get_user_option('append_revisions_only'))
182
181
        branch.set_append_revisions_only(False)
183
 
        config = branch.get_config_stack()
184
182
        self.assertEqual(
185
 
            False, config.get('append_revisions_only'))
 
183
            'False', config.get_user_option('append_revisions_only'))
186
184
 
187
185
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
188
186
        branch = self.make_branch('branch', format='knit')
 
187
        config = branch.get_config()
189
188
        self.assertRaises(
190
189
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
191
190
 
504
503
        self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
505
504
 
506
505
 
507
 
class TestBzrDirCheckoutMetaDir(TestRemote):
508
 
 
509
 
    def test__get_checkout_format(self):
510
 
        transport = MemoryTransport()
511
 
        client = FakeClient(transport.base)
512
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
513
 
        control_name = reference_bzrdir_format.network_name()
514
 
        client.add_expected_call(
515
 
            'BzrDir.checkout_metadir', ('quack/', ),
516
 
            'success', (control_name, '', ''))
517
 
        transport.mkdir('quack')
518
 
        transport = transport.clone('quack')
519
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
520
 
            _client=client)
521
 
        result = a_bzrdir.checkout_metadir()
522
 
        # We should have got a reference control dir with default branch and
523
 
        # repository formats.
524
 
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
525
 
        self.assertEqual(None, result._repository_format)
526
 
        self.assertEqual(None, result._branch_format)
527
 
        self.assertFinished(client)
528
 
 
529
 
    def test_unknown_format(self):
530
 
        transport = MemoryTransport()
531
 
        client = FakeClient(transport.base)
532
 
        client.add_expected_call(
533
 
            'BzrDir.checkout_metadir', ('quack/',),
534
 
            'success', ('dontknow', '', ''))
535
 
        transport.mkdir('quack')
536
 
        transport = transport.clone('quack')
537
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
538
 
            _client=client)
539
 
        self.assertRaises(errors.UnknownFormatError,
540
 
            a_bzrdir.checkout_metadir)
541
 
        self.assertFinished(client)
542
 
 
543
 
 
544
 
class TestBzrDirGetBranches(TestRemote):
545
 
 
546
 
    def test_get_branches(self):
547
 
        transport = MemoryTransport()
548
 
        client = FakeClient(transport.base)
549
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
550
 
        branch_name = reference_bzrdir_format.get_branch_format().network_name()
551
 
        client.add_success_response_with_body(
552
 
            bencode.bencode({
553
 
                "foo": ("branch", branch_name),
554
 
                "": ("branch", branch_name)}), "success")
555
 
        client.add_success_response(
556
 
            'ok', '', 'no', 'no', 'no',
557
 
                reference_bzrdir_format.repository_format.network_name())
558
 
        client.add_error_response('NotStacked')
559
 
        client.add_success_response(
560
 
            'ok', '', 'no', 'no', 'no',
561
 
                reference_bzrdir_format.repository_format.network_name())
562
 
        client.add_error_response('NotStacked')
563
 
        transport.mkdir('quack')
564
 
        transport = transport.clone('quack')
565
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
566
 
            _client=client)
567
 
        result = a_bzrdir.get_branches()
568
 
        self.assertEquals(set(["", "foo"]), set(result.keys()))
569
 
        self.assertEqual(
570
 
            [('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
571
 
             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
572
 
             ('call', 'Branch.get_stacked_on_url', ('quack/', )),
573
 
             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
574
 
             ('call', 'Branch.get_stacked_on_url', ('quack/', ))],
575
 
            client._calls)
576
 
 
577
 
 
578
506
class TestBzrDirDestroyBranch(TestRemote):
579
507
 
580
508
    def test_destroy_default(self):
589
517
        a_bzrdir.destroy_branch()
590
518
        self.assertFinished(client)
591
519
 
 
520
    def test_destroy_named(self):
 
521
        transport = self.get_transport('quack')
 
522
        referenced = self.make_branch('referenced')
 
523
        client = FakeClient(transport.base)
 
524
        client.add_expected_call(
 
525
            'BzrDir.destroy_branch', ('quack/', "foo"),
 
526
            'success', ('ok',)),
 
527
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
 
528
            _client=client)
 
529
        a_bzrdir.destroy_branch("foo")
 
530
        self.assertFinished(client)
 
531
 
592
532
 
593
533
class TestBzrDirHasWorkingTree(TestRemote):
594
534
 
955
895
        # name.
956
896
        client.add_success_response_with_body(
957
897
            "Bazaar-NG meta directory, format 1\n", 'ok')
958
 
        client.add_success_response('stat', '0', '65535')
959
898
        client.add_success_response_with_body(
960
899
            reference_format.get_format_string(), 'ok')
961
900
        # PackRepository wants to do a stat
970
909
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
971
910
             ('call', 'BzrDir.find_repository', ('quack/',)),
972
911
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
973
 
             ('call', 'stat', ('/quack/.bzr',)),
974
912
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
975
913
             ('call', 'stat', ('/quack/.bzr/repository',)),
976
914
             ],
990
928
        # name.
991
929
        client.add_success_response_with_body(
992
930
            "Bazaar-NG meta directory, format 1\n", 'ok')
993
 
        client.add_success_response('stat', '0', '65535')
994
931
        client.add_success_response_with_body(
995
932
            reference_format.get_format_string(), 'ok')
996
933
        # PackRepository wants to do a stat
1004
941
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
1005
942
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
1006
943
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
1007
 
             ('call', 'stat', ('/quack/.bzr',)),
1008
944
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
1009
945
             ('call', 'stat', ('/quack/.bzr/repository',)),
1010
946
             ],
1296
1232
        verb = 'Branch.set_parent_location'
1297
1233
        self.disable_verb(verb)
1298
1234
        branch.set_parent('http://foo/')
1299
 
        self.assertLength(14, self.hpss_calls)
 
1235
        self.assertLength(12, self.hpss_calls)
1300
1236
 
1301
1237
 
1302
1238
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1455
1391
        return branch
1456
1392
 
1457
1393
    def test_backwards_compatible(self):
1458
 
        br = self.make_branch_with_tags()
1459
 
        br.get_config_stack().set('branch.fetch_tags', True)
1460
 
        self.addCleanup(br.lock_read().unlock)
 
1394
        branch = self.make_branch_with_tags()
 
1395
        c = branch.get_config()
 
1396
        c.set_user_option('branch.fetch_tags', 'True')
 
1397
        self.addCleanup(branch.lock_read().unlock)
1461
1398
        # Disable the heads_to_fetch verb
1462
1399
        verb = 'Branch.heads_to_fetch'
1463
1400
        self.disable_verb(verb)
1464
1401
        self.reset_smart_call_log()
1465
 
        result = br.heads_to_fetch()
 
1402
        result = branch.heads_to_fetch()
1466
1403
        self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1467
1404
        self.assertEqual(
1468
 
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
 
1405
            ['Branch.last_revision_info', 'Branch.get_config_file',
 
1406
             'Branch.get_tags_bytes'],
1469
1407
            [call.call.method for call in self.hpss_calls])
1470
1408
 
1471
1409
    def test_backwards_compatible_no_tags(self):
1472
 
        br = self.make_branch_with_tags()
1473
 
        br.get_config_stack().set('branch.fetch_tags', False)
1474
 
        self.addCleanup(br.lock_read().unlock)
 
1410
        branch = self.make_branch_with_tags()
 
1411
        c = branch.get_config()
 
1412
        c.set_user_option('branch.fetch_tags', 'False')
 
1413
        self.addCleanup(branch.lock_read().unlock)
1475
1414
        # Disable the heads_to_fetch verb
1476
1415
        verb = 'Branch.heads_to_fetch'
1477
1416
        self.disable_verb(verb)
1478
1417
        self.reset_smart_call_log()
1479
 
        result = br.heads_to_fetch()
 
1418
        result = branch.heads_to_fetch()
1480
1419
        self.assertEqual((set(['tip']), set()), result)
1481
1420
        self.assertEqual(
1482
 
            ['Branch.last_revision_info'],
 
1421
            ['Branch.last_revision_info', 'Branch.get_config_file'],
1483
1422
            [call.call.method for call in self.hpss_calls])
1484
1423
 
1485
1424
 
2021
1960
        self.addCleanup(branch.unlock)
2022
1961
        self.reset_smart_call_log()
2023
1962
        branch._get_config().set_option('value', 'name')
2024
 
        self.assertLength(11, self.hpss_calls)
 
1963
        self.assertLength(10, self.hpss_calls)
2025
1964
        self.assertEqual('value', branch._get_config().get_option('name'))
2026
1965
 
2027
1966
    def test_backwards_compat_set_option_with_dict(self):
2035
1974
        config = branch._get_config()
2036
1975
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2037
1976
        config.set_option(value_dict, 'name')
2038
 
        self.assertLength(11, self.hpss_calls)
 
1977
        self.assertLength(10, self.hpss_calls)
2039
1978
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
2040
1979
 
2041
1980
 
2070
2009
            'Branch.get_config_file', ('memory:///', ),
2071
2010
            'success', ('ok', ), "# line 1\n")
2072
2011
        client.add_expected_call(
2073
 
            'Branch.get_config_file', ('memory:///', ),
2074
 
            'success', ('ok', ), "# line 1\n")
2075
 
        client.add_expected_call(
2076
2012
            'Branch.put_config_file', ('memory:///', 'branch token',
2077
2013
            'repo token'),
2078
2014
            'success', ('ok',))
2090
2026
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2091
2027
             ('call', 'Branch.lock_write', ('memory:///', '', '')),
2092
2028
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2093
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2094
2029
             ('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2095
2030
                 ('memory:///', 'branch token', 'repo token'),
2096
2031
                 '# line 1\nemail = The Dude <lebowski@example.com>\n'),
2165
2100
        self.reset_smart_call_log()
2166
2101
        self.assertEquals((0, ),
2167
2102
            branch.revision_id_to_dotted_revno('null:'))
2168
 
        self.assertLength(8, self.hpss_calls)
 
2103
        self.assertLength(7, self.hpss_calls)
2169
2104
 
2170
2105
 
2171
2106
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2187
2122
        self.reset_smart_call_log()
2188
2123
        config = bzrdir.get_config()
2189
2124
        config.set_default_stack_on('/')
2190
 
        self.assertLength(4, self.hpss_calls)
 
2125
        self.assertLength(3, self.hpss_calls)
2191
2126
 
2192
2127
    def test_backwards_compat_get_option(self):
2193
2128
        self.setup_smart_server_with_call_log()
2197
2132
        self.reset_smart_call_log()
2198
2133
        self.assertEqual(None,
2199
2134
            bzrdir._get_config().get_option('default_stack_on'))
2200
 
        self.assertLength(4, self.hpss_calls)
 
2135
        self.assertLength(3, self.hpss_calls)
2201
2136
 
2202
2137
 
2203
2138
class TestTransportIsReadonly(tests.TestCase):
2438
2373
            client._calls)
2439
2374
 
2440
2375
 
2441
 
class TestRepositoryReconcile(TestRemoteRepository):
2442
 
 
2443
 
    def test_reconcile(self):
2444
 
        transport_path = 'hill'
2445
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2446
 
        body = ("garbage_inventories: 2\n"
2447
 
                "inconsistent_parents: 3\n")
2448
 
        client.add_expected_call(
2449
 
            'Repository.lock_write', ('hill/', ''),
2450
 
            'success', ('ok', 'a token'))
2451
 
        client.add_success_response_with_body(body, 'ok')
2452
 
        reconciler = repo.reconcile()
2453
 
        self.assertEqual(
2454
 
            [('call', 'Repository.lock_write', ('hill/', '')),
2455
 
             ('call_expecting_body', 'Repository.reconcile',
2456
 
                ('hill/', 'a token'))],
2457
 
            client._calls)
2458
 
        self.assertEquals(2, reconciler.garbage_inventories)
2459
 
        self.assertEquals(3, reconciler.inconsistent_parents)
2460
 
 
2461
 
 
2462
2376
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2463
2377
 
2464
2378
    def test_text(self):
4261
4175
            'Repository.unlock', ('quack/', 'token', 'False'),
4262
4176
            'success', ('ok', ))
4263
4177
        repo.pack(['hinta', 'hintb'])
4264
 
 
4265
 
 
4266
 
class TestRepositoryIterInventories(TestRemoteRepository):
4267
 
    """Test Repository.iter_inventories."""
4268
 
 
4269
 
    def _serialize_inv_delta(self, old_name, new_name, delta):
4270
 
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4271
 
        return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4272
 
 
4273
 
    def test_single_empty(self):
4274
 
        transport_path = 'quack'
4275
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4276
 
        fmt = bzrdir.format_registry.get('2a')().repository_format
4277
 
        repo._format = fmt
4278
 
        stream = [('inventory-deltas', [
4279
 
            versionedfile.FulltextContentFactory('somerevid', None, None,
4280
 
                self._serialize_inv_delta('null:', 'somerevid', []))])]
4281
 
        client.add_expected_call(
4282
 
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4283
 
            'success', ('ok', ),
4284
 
            _stream_to_byte_stream(stream, fmt))
4285
 
        ret = list(repo.iter_inventories(["somerevid"]))
4286
 
        self.assertLength(1, ret)
4287
 
        inv = ret[0]
4288
 
        self.assertEquals("somerevid", inv.revision_id)
4289
 
 
4290
 
    def test_empty(self):
4291
 
        transport_path = 'quack'
4292
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4293
 
        ret = list(repo.iter_inventories([]))
4294
 
        self.assertEquals(ret, [])
4295
 
 
4296
 
    def test_missing(self):
4297
 
        transport_path = 'quack'
4298
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4299
 
        client.add_expected_call(
4300
 
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4301
 
            'success', ('ok', ), iter([]))
4302
 
        self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(
4303
 
            ["somerevid"]))