~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-08-12 09:49:24 UTC
  • mfrom: (6015.9.10 2.4)
  • mto: This revision was merged to the branch mainline in revision 6066.
  • Revision ID: v.ladeuil+lp@free.fr-20110812094924-knc5s0g7vs31a2f1
Merge 2.4 into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1183
1183
        client.add_expected_call(
1184
1184
            'Branch.last_revision_info', ('quack/',),
1185
1185
            'success', ('ok', '1', 'rev-tip'))
 
1186
        client.add_expected_call(
 
1187
            'Branch.get_config_file', ('quack/',),
 
1188
            'success', ('ok',), '')
 
1189
        transport.mkdir('quack')
 
1190
        transport = transport.clone('quack')
 
1191
        branch = self.make_remote_branch(transport, client)
 
1192
        result = branch.heads_to_fetch()
 
1193
        self.assertFinished(client)
 
1194
        self.assertEqual((set(['rev-tip']), set()), result)
 
1195
 
 
1196
    def test_uses_last_revision_info_and_tags_when_set(self):
 
1197
        transport = MemoryTransport()
 
1198
        client = FakeClient(transport.base)
 
1199
        client.add_expected_call(
 
1200
            'Branch.get_stacked_on_url', ('quack/',),
 
1201
            'error', ('NotStacked',))
 
1202
        client.add_expected_call(
 
1203
            'Branch.last_revision_info', ('quack/',),
 
1204
            'success', ('ok', '1', 'rev-tip'))
 
1205
        client.add_expected_call(
 
1206
            'Branch.get_config_file', ('quack/',),
 
1207
            'success', ('ok',), 'branch.fetch_tags = True')
1186
1208
        # XXX: this will break if the default format's serialization of tags
1187
1209
        # changes, or if the RPC for fetching tags changes from get_tags_bytes.
1188
1210
        client.add_expected_call(
1213
1235
        self.assertFinished(client)
1214
1236
        self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1215
1237
 
1216
 
    def test_backwards_compatible(self):
 
1238
    def make_branch_with_tags(self):
1217
1239
        self.setup_smart_server_with_call_log()
1218
1240
        # Make a branch with a single revision.
1219
1241
        builder = self.make_branch_builder('foo')
1225
1247
        # Add two tags to that branch
1226
1248
        branch.tags.set_tag('tag-1', 'rev-1')
1227
1249
        branch.tags.set_tag('tag-2', 'rev-2')
 
1250
        return branch
 
1251
 
 
1252
    def test_backwards_compatible(self):
 
1253
        branch = self.make_branch_with_tags()
 
1254
        c = branch.get_config()
 
1255
        c.set_user_option('branch.fetch_tags', 'True')
1228
1256
        self.addCleanup(branch.lock_read().unlock)
1229
1257
        # Disable the heads_to_fetch verb
1230
1258
        verb = 'Branch.heads_to_fetch'
1233
1261
        result = branch.heads_to_fetch()
1234
1262
        self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1235
1263
        self.assertEqual(
1236
 
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
 
1264
            ['Branch.last_revision_info', 'Branch.get_config_file',
 
1265
             'Branch.get_tags_bytes'],
 
1266
            [call.call.method for call in self.hpss_calls])
 
1267
 
 
1268
    def test_backwards_compatible_no_tags(self):
 
1269
        branch = self.make_branch_with_tags()
 
1270
        c = branch.get_config()
 
1271
        c.set_user_option('branch.fetch_tags', 'False')
 
1272
        self.addCleanup(branch.lock_read().unlock)
 
1273
        # Disable the heads_to_fetch verb
 
1274
        verb = 'Branch.heads_to_fetch'
 
1275
        self.disable_verb(verb)
 
1276
        self.reset_smart_call_log()
 
1277
        result = branch.heads_to_fetch()
 
1278
        self.assertEqual((set(['tip']), set()), result)
 
1279
        self.assertEqual(
 
1280
            ['Branch.last_revision_info', 'Branch.get_config_file'],
1237
1281
            [call.call.method for call in self.hpss_calls])
1238
1282
 
1239
1283
 
3408
3452
        self.assertTrue(len(self.hpss_calls) > 1)
3409
3453
 
3410
3454
 
3411
 
class TestUpdateBoundBranch(tests.TestCaseWithTransport):
3412
 
 
3413
 
    def test_bug_786980(self):
 
3455
class TestUpdateBoundBranchWithModifiedBoundLocation(
 
3456
    tests.TestCaseWithTransport):
 
3457
    """Ensure correct handling of bound_location modifications.
 
3458
 
 
3459
    This is tested against a smart server as http://pad.lv/786980 was about a
 
3460
    ReadOnlyError (write attempt during a read-only transaction) which can only
 
3461
    happen in this context.
 
3462
    """
 
3463
 
 
3464
    def setUp(self):
 
3465
        super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
3414
3466
        self.transport_server = test_server.SmartTCPServer_for_testing
3415
 
        wt = self.make_branch_and_tree('master')
3416
 
        checkout = wt.branch.create_checkout('checkout')
3417
 
        wt.commit('add stuff')
3418
 
        last_revid = wt.commit('even more stuff')
3419
 
        bound_location = checkout.branch.get_bound_location()
 
3467
 
 
3468
    def make_master_and_checkout(self, master_name, checkout_name):
 
3469
        # Create the master branch and its associated checkout
 
3470
        self.master = self.make_branch_and_tree(master_name)
 
3471
        self.checkout = self.master.branch.create_checkout(checkout_name)
 
3472
        # Modify the master branch so there is something to update
 
3473
        self.master.commit('add stuff')
 
3474
        self.last_revid = self.master.commit('even more stuff')
 
3475
        self.bound_location = self.checkout.branch.get_bound_location()
 
3476
 
 
3477
    def assertUpdateSucceeds(self, new_location):
 
3478
        self.checkout.branch.set_bound_location(new_location)
 
3479
        self.checkout.update()
 
3480
        self.assertEquals(self.last_revid, self.checkout.last_revision())
 
3481
 
 
3482
    def test_without_final_slash(self):
 
3483
        self.make_master_and_checkout('master', 'checkout')
3420
3484
        # For unclear reasons some users have a bound_location without a final
3421
3485
        # '/', simulate that by forcing such a value
3422
 
        self.assertEndsWith(bound_location, '/')
3423
 
        new_location = bound_location.rstrip('/')
3424
 
        checkout.branch.set_bound_location(new_location)
3425
 
        # bug 786980 was raising ReadOnlyError: A write attempt was made in a
3426
 
        # read only transaction during the update()
3427
 
        checkout.update()
3428
 
        self.assertEquals(last_revid, checkout.last_revision())
 
3486
        self.assertEndsWith(self.bound_location, '/')
 
3487
        self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
 
3488
 
 
3489
    def test_plus_sign(self):
 
3490
        self.make_master_and_checkout('+master', 'checkout')
 
3491
        self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
 
3492
 
 
3493
    def test_tilda(self):
 
3494
        # Embed ~ in the middle of the path just to avoid any $HOME
 
3495
        # interpretation
 
3496
        self.make_master_and_checkout('mas~ter', 'checkout')
 
3497
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))