~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Jelmer Vernooij
  • Date: 2011-07-23 16:33:38 UTC
  • mto: This revision was merged to the branch mainline in revision 6045.
  • Revision ID: jelmer@samba.org-20110723163338-mjox55g52kt3u922
Add get_transport_from_url and get_transport_from_path functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3359
3359
        remote_branch_url = self.smart_server.get_url() + 'remote'
3360
3360
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3361
3361
        self.hpss_calls = []
3362
 
        local.repository.fetch(remote_branch.repository,
3363
 
                fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
 
3362
        local.repository.fetch(
 
3363
            remote_branch.repository,
 
3364
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
3364
3365
        self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
3365
3366
 
3366
3367
    def override_verb(self, verb_name, verb):
3381
3382
            """A version of the Repository.get_stream_1.19 verb patched to
3382
3383
            reject 'everything' searches the way 2.3 and earlier do.
3383
3384
            """
3384
 
            def recreate_search(self, repository, search_bytes, discard_excess=False):
 
3385
            def recreate_search(self, repository, search_bytes,
 
3386
                                discard_excess=False):
3385
3387
                verb_log.append(search_bytes.split('\n', 1)[0])
3386
3388
                if search_bytes == 'everything':
3387
 
                    return (None, request.FailedSmartServerResponse(('BadSearch',)))
 
3389
                    return (None,
 
3390
                            request.FailedSmartServerResponse(('BadSearch',)))
3388
3391
                return super(OldGetStreamVerb,
3389
3392
                        self).recreate_search(repository, search_bytes,
3390
3393
                            discard_excess=discard_excess)
3395
3398
        remote_branch_url = self.smart_server.get_url() + 'remote'
3396
3399
        remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3397
3400
        self.hpss_calls = []
3398
 
        local.repository.fetch(remote_branch.repository,
3399
 
                fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
 
3401
        local.repository.fetch(
 
3402
            remote_branch.repository,
 
3403
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
3400
3404
        # make sure the overridden verb was used
3401
3405
        self.assertLength(1, verb_log)
3402
3406
        # more than one HPSS call is needed, but because it's a VFS callback
3403
3407
        # its hard to predict exactly how many.
3404
3408
        self.assertTrue(len(self.hpss_calls) > 1)
3405
3409
 
 
3410
 
 
3411
class TestUpdateBoundBranchWithModifiedBoundLocation(
 
3412
    tests.TestCaseWithTransport):
 
3413
    """Ensure correct handling of bound_location modifications.
 
3414
 
 
3415
    This is tested against a smart server as http://pad.lv/786980 was about a
 
3416
    ReadOnlyError (write attempt during a read-only transaction) which can only
 
3417
    happen in this context.
 
3418
    """
 
3419
 
 
3420
    def setUp(self):
 
3421
        super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
 
3422
        self.transport_server = test_server.SmartTCPServer_for_testing
 
3423
 
 
3424
    def make_master_and_checkout(self, master_name, checkout_name):
 
3425
        # Create the master branch and its associated checkout
 
3426
        self.master = self.make_branch_and_tree(master_name)
 
3427
        self.checkout = self.master.branch.create_checkout(checkout_name)
 
3428
        # Modify the master branch so there is something to update
 
3429
        self.master.commit('add stuff')
 
3430
        self.last_revid = self.master.commit('even more stuff')
 
3431
        self.bound_location = self.checkout.branch.get_bound_location()
 
3432
 
 
3433
    def assertUpdateSucceeds(self, new_location):
 
3434
        self.checkout.branch.set_bound_location(new_location)
 
3435
        self.checkout.update()
 
3436
        self.assertEquals(self.last_revid, self.checkout.last_revision())
 
3437
 
 
3438
    def test_without_final_slash(self):
 
3439
        self.make_master_and_checkout('master', 'checkout')
 
3440
        # For unclear reasons some users have a bound_location without a final
 
3441
        # '/', simulate that by forcing such a value
 
3442
        self.assertEndsWith(self.bound_location, '/')
 
3443
        self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
 
3444
 
 
3445
    def test_plus_sign(self):
 
3446
        self.make_master_and_checkout('+master', 'checkout')
 
3447
        self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
 
3448
 
 
3449
    def test_tilda(self):
 
3450
        # Embed ~ in the middle of the path just to avoid any $HOME
 
3451
        # interpretation
 
3452
        self.make_master_and_checkout('mas~ter', 'checkout')
 
3453
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))