~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
from bzrlib.smart.repository import (
70
70
    SmartServerRepositoryGetParentMap,
71
71
    SmartServerRepositoryGetStream_1_19,
 
72
    _stream_to_byte_stream,
72
73
    )
73
74
from bzrlib.symbol_versioning import deprecated_in
74
75
from bzrlib.tests import (
174
175
    def test_remote_branch_set_append_revisions_only(self):
175
176
        # Make a format 1.9 branch, which supports append_revisions_only
176
177
        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()
179
180
        self.assertEqual(
180
 
            'True', config.get_user_option('append_revisions_only'))
 
181
            True, config.get('append_revisions_only'))
181
182
        branch.set_append_revisions_only(False)
 
183
        config = branch.get_config_stack()
182
184
        self.assertEqual(
183
 
            'False', config.get_user_option('append_revisions_only'))
 
185
            False, config.get('append_revisions_only'))
184
186
 
185
187
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
186
188
        branch = self.make_branch('branch', format='knit')
187
 
        config = branch.get_config()
188
189
        self.assertRaises(
189
190
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
190
191
 
503
504
        self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
504
505
 
505
506
 
 
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
 
506
544
class TestBzrDirDestroyBranch(TestRemote):
507
545
 
508
546
    def test_destroy_default(self):
895
933
        # name.
896
934
        client.add_success_response_with_body(
897
935
            "Bazaar-NG meta directory, format 1\n", 'ok')
 
936
        client.add_success_response('stat', '0', '65535')
898
937
        client.add_success_response_with_body(
899
938
            reference_format.get_format_string(), 'ok')
900
939
        # PackRepository wants to do a stat
909
948
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
910
949
             ('call', 'BzrDir.find_repository', ('quack/',)),
911
950
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
 
951
             ('call', 'stat', ('/quack/.bzr',)),
912
952
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
913
953
             ('call', 'stat', ('/quack/.bzr/repository',)),
914
954
             ],
928
968
        # name.
929
969
        client.add_success_response_with_body(
930
970
            "Bazaar-NG meta directory, format 1\n", 'ok')
 
971
        client.add_success_response('stat', '0', '65535')
931
972
        client.add_success_response_with_body(
932
973
            reference_format.get_format_string(), 'ok')
933
974
        # PackRepository wants to do a stat
941
982
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
942
983
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
943
984
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
 
985
             ('call', 'stat', ('/quack/.bzr',)),
944
986
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
945
987
             ('call', 'stat', ('/quack/.bzr/repository',)),
946
988
             ],
1232
1274
        verb = 'Branch.set_parent_location'
1233
1275
        self.disable_verb(verb)
1234
1276
        branch.set_parent('http://foo/')
1235
 
        self.assertLength(12, self.hpss_calls)
 
1277
        self.assertLength(13, self.hpss_calls)
1236
1278
 
1237
1279
 
1238
1280
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1392
1434
 
1393
1435
    def test_backwards_compatible(self):
1394
1436
        branch = self.make_branch_with_tags()
1395
 
        c = branch.get_config()
1396
 
        c.set_user_option('branch.fetch_tags', 'True')
 
1437
        c = branch.get_config_stack()
 
1438
        c.set('branch.fetch_tags', True)
1397
1439
        self.addCleanup(branch.lock_read().unlock)
1398
1440
        # Disable the heads_to_fetch verb
1399
1441
        verb = 'Branch.heads_to_fetch'
1408
1450
 
1409
1451
    def test_backwards_compatible_no_tags(self):
1410
1452
        branch = self.make_branch_with_tags()
1411
 
        c = branch.get_config()
1412
 
        c.set_user_option('branch.fetch_tags', 'False')
 
1453
        c = branch.get_config_stack()
 
1454
        c.set('branch.fetch_tags', False)
1413
1455
        self.addCleanup(branch.lock_read().unlock)
1414
1456
        # Disable the heads_to_fetch verb
1415
1457
        verb = 'Branch.heads_to_fetch'
1960
2002
        self.addCleanup(branch.unlock)
1961
2003
        self.reset_smart_call_log()
1962
2004
        branch._get_config().set_option('value', 'name')
1963
 
        self.assertLength(10, self.hpss_calls)
 
2005
        self.assertLength(11, self.hpss_calls)
1964
2006
        self.assertEqual('value', branch._get_config().get_option('name'))
1965
2007
 
1966
2008
    def test_backwards_compat_set_option_with_dict(self):
1974
2016
        config = branch._get_config()
1975
2017
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1976
2018
        config.set_option(value_dict, 'name')
1977
 
        self.assertLength(10, self.hpss_calls)
 
2019
        self.assertLength(11, self.hpss_calls)
1978
2020
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
1979
2021
 
1980
2022
 
2100
2142
        self.reset_smart_call_log()
2101
2143
        self.assertEquals((0, ),
2102
2144
            branch.revision_id_to_dotted_revno('null:'))
2103
 
        self.assertLength(7, self.hpss_calls)
 
2145
        self.assertLength(8, self.hpss_calls)
2104
2146
 
2105
2147
 
2106
2148
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2122
2164
        self.reset_smart_call_log()
2123
2165
        config = bzrdir.get_config()
2124
2166
        config.set_default_stack_on('/')
2125
 
        self.assertLength(3, self.hpss_calls)
 
2167
        self.assertLength(4, self.hpss_calls)
2126
2168
 
2127
2169
    def test_backwards_compat_get_option(self):
2128
2170
        self.setup_smart_server_with_call_log()
2132
2174
        self.reset_smart_call_log()
2133
2175
        self.assertEqual(None,
2134
2176
            bzrdir._get_config().get_option('default_stack_on'))
2135
 
        self.assertLength(3, self.hpss_calls)
 
2177
        self.assertLength(4, self.hpss_calls)
2136
2178
 
2137
2179
 
2138
2180
class TestTransportIsReadonly(tests.TestCase):
4196
4238
            'Repository.unlock', ('quack/', 'token', 'False'),
4197
4239
            'success', ('ok', ))
4198
4240
        repo.pack(['hinta', 'hintb'])
 
4241
 
 
4242
 
 
4243
class TestRepositoryIterInventories(TestRemoteRepository):
 
4244
    """Test Repository.iter_inventories."""
 
4245
 
 
4246
    def _serialize_inv_delta(self, old_name, new_name, delta):
 
4247
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
 
4248
        return "".join(serializer.delta_to_lines(old_name, new_name, delta))
 
4249
 
 
4250
    def test_single_empty(self):
 
4251
        transport_path = 'quack'
 
4252
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
4253
        fmt = bzrdir.format_registry.get('2a')().repository_format
 
4254
        repo._format = fmt
 
4255
        stream = [('inventory-deltas', [
 
4256
            versionedfile.FulltextContentFactory('somerevid', None, None,
 
4257
                self._serialize_inv_delta('null:', 'somerevid', []))])]
 
4258
        client.add_expected_call(
 
4259
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
 
4260
            'success', ('ok', ),
 
4261
            _stream_to_byte_stream(stream, fmt))
 
4262
        ret = list(repo.iter_inventories(["somerevid"]))
 
4263
        self.assertLength(1, ret)
 
4264
        inv = ret[0]
 
4265
        self.assertEquals("somerevid", inv.revision_id)
 
4266
 
 
4267
    def test_empty(self):
 
4268
        transport_path = 'quack'
 
4269
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
4270
        ret = list(repo.iter_inventories([]))
 
4271
        self.assertEquals(ret, [])
 
4272
 
 
4273
    def test_missing(self):
 
4274
        transport_path = 'quack'
 
4275
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
4276
        client.add_expected_call(
 
4277
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
 
4278
            'success', ('ok', ), iter([]))
 
4279
        self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(
 
4280
            ["somerevid"]))