~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pull.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-04 14:48:21 UTC
  • mto: (4349.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4350.
  • Revision ID: v.ladeuil+lp@free.fr-20090504144821-39dvqkikmd3zqkdg
Handle servers proposing several authentication schemes.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Several schemes can be
proposed by the server, try to match each one in turn.
(BasicAuthHandler.auth_match): Delete dead code.

* bzrlib/tests/test_http.py:
(load_tests): Separate proxy and http authentication tests as they
require different server setups.
(TestAuth.create_transport_readonly_server): Simplified by using
parameter provided by load_tests.
(TestAuth.test_changing_nonce): Adapt to new parametrization.
(TestProxyAuth.create_transport_readonly_server): Deleted.

* bzrlib/tests/http_utils.py:
(DigestAndBasicAuthRequestHandler, HTTPBasicAndDigestAuthServer,
ProxyBasicAndDigestAuthServer): Add a test server proposing both
basic and digest auth schemes but accepting only digest as valid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
20
20
import os
21
21
import sys
22
22
 
23
 
from bzrlib import (
24
 
    debug,
25
 
    remote,
26
 
    urlutils,
27
 
    )
28
 
 
29
23
from bzrlib.branch import Branch
30
24
from bzrlib.directory_service import directories
31
25
from bzrlib.osutils import pathjoin
32
 
from bzrlib.tests import (
33
 
    fixtures,
34
 
    TestCaseWithTransport,
35
 
    )
 
26
from bzrlib.tests.blackbox import ExternalBase
36
27
from bzrlib.uncommit import uncommit
37
28
from bzrlib.workingtree import WorkingTree
38
 
 
39
 
 
40
 
class TestPull(TestCaseWithTransport):
 
29
from bzrlib import urlutils
 
30
 
 
31
 
 
32
class TestPull(ExternalBase):
41
33
 
42
34
    def example_branch(self, path='.'):
43
35
        tree = self.make_branch_and_tree(path)
145
137
        self.run_bzr('pull -r 4')
146
138
        self.assertEqual(a.revision_history(), b.revision_history())
147
139
 
148
 
    def test_pull_tags(self):
149
 
        """Tags are updated by pull, and revisions named in those tags are
150
 
        fetched.
151
 
        """
152
 
        # Make a source, sprout a target off it
153
 
        builder = self.make_branch_builder('source')
154
 
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
155
 
        target_bzrdir = source.bzrdir.sprout('target')
156
 
        source.tags.set_tag('tag-a', 'rev-2')
157
 
        # Pull from source
158
 
        self.run_bzr('pull -d target source')
159
 
        target = target_bzrdir.open_branch()
160
 
        # The tag is present, and so is its revision.
161
 
        self.assertEqual('rev-2', target.tags.lookup_tag('tag-a'))
162
 
        target.repository.get_revision('rev-2')
163
140
 
164
141
    def test_overwrite_uptodate(self):
165
142
        # Make sure pull --overwrite overwrites
262
239
        out = self.run_bzr('pull ../branch_a', retcode=3)
263
240
        self.assertEqual(out,
264
241
                ('','bzr: ERROR: These branches have diverged.'
265
 
                    ' Use the missing command to see how.\n'
266
 
                    'Use the merge command to reconcile them.\n'))
 
242
                    ' Use the merge command to reconcile them.\n'))
267
243
        self.assertEqual(branch_b.get_parent(), parent)
268
244
        # test implicit --remember after resolving previous failure
269
245
        uncommit(branch=branch_b, tree=tree_b)
361
337
            def look_up(self, name, url):
362
338
                return 'source'
363
339
        directories.register('foo:', FooService, 'Testing directory service')
364
 
        self.addCleanup(directories.remove, 'foo:')
 
340
        self.addCleanup(lambda: directories.remove('foo:'))
365
341
        self.run_bzr('pull foo:bar -d target')
366
342
        self.assertEqual(source_last, target.last_revision())
367
343
 
382
358
        self.assertContainsRe(out, r'\n {4}1 .*\n {6}setup\n')
383
359
        self.assertNotContainsRe(
384
360
            out, r'revno: 1\ncommitter: .*\nbranch nick: source')
385
 
 
386
 
    def test_pull_smart_stacked_streaming_acceptance(self):
387
 
        """'bzr pull -r 123' works on stacked, smart branches, even when the
388
 
        revision specified by the revno is only present in the fallback
389
 
        repository.
390
 
 
391
 
        See <https://launchpad.net/bugs/380314>
392
 
        """
393
 
        self.setup_smart_server_with_call_log()
394
 
        # Make a stacked-on branch with two commits so that the
395
 
        # revision-history can't be determined just by looking at the parent
396
 
        # field in the revision in the stacked repo.
397
 
        parent = self.make_branch_and_tree('parent', format='1.9')
398
 
        parent.commit(message='first commit')
399
 
        parent.commit(message='second commit')
400
 
        local = parent.bzrdir.sprout('local').open_workingtree()
401
 
        local.commit(message='local commit')
402
 
        local.branch.create_clone_on_transport(
403
 
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
404
 
        empty = self.make_branch_and_tree('empty', format='1.9')
405
 
        self.reset_smart_call_log()
406
 
        self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
407
 
            working_dir='empty')
408
 
        # This figure represent the amount of work to perform this use case. It
409
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
410
 
        # being too low. If rpc_count increases, more network roundtrips have
411
 
        # become necessary for this use case. Please do not adjust this number
412
 
        # upwards without agreement from bzr's network support maintainers.
413
 
        self.assertLength(18, self.hpss_calls)
414
 
        remote = Branch.open('stacked')
415
 
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
416
 
    
417
 
    def test_pull_cross_format_warning(self):
418
 
        """You get a warning for probably slow cross-format pulls.
419
 
        """
420
 
        # this is assumed to be going through InterDifferingSerializer
421
 
        from_tree = self.make_branch_and_tree('from', format='2a')
422
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
423
 
        from_tree.commit(message='first commit')
424
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
425
 
        self.assertContainsRe(err,
426
 
            "(?m)Doing on-the-fly conversion")
427
 
 
428
 
    def test_pull_cross_format_warning_no_IDS(self):
429
 
        """You get a warning for probably slow cross-format pulls.
430
 
        """
431
 
        # this simulates what would happen across the network, where
432
 
        # interdifferingserializer is not active
433
 
 
434
 
        debug.debug_flags.add('IDS_never')
435
 
        # TestCase take care of restoring them
436
 
 
437
 
        from_tree = self.make_branch_and_tree('from', format='2a')
438
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
439
 
        from_tree.commit(message='first commit')
440
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
441
 
        self.assertContainsRe(err,
442
 
            "(?m)Doing on-the-fly conversion")
443
 
 
444
 
    def test_pull_cross_format_from_network(self):
445
 
        self.setup_smart_server_with_call_log()
446
 
        from_tree = self.make_branch_and_tree('from', format='2a')
447
 
        to_tree = self.make_branch_and_tree('to', format='1.14-rich-root')
448
 
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
449
 
        from_tree.commit(message='first commit')
450
 
        out, err = self.run_bzr(['pull', '-d', 'to',
451
 
            from_tree.branch.bzrdir.root_transport.base])
452
 
        self.assertContainsRe(err,
453
 
            "(?m)Doing on-the-fly conversion")
454
 
 
455
 
    def test_pull_to_experimental_format_warning(self):
456
 
        """You get a warning for pulling into experimental formats.
457
 
        """
458
 
        from_tree = self.make_branch_and_tree('from', format='development-subtree')
459
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
460
 
        from_tree.commit(message='first commit')
461
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
462
 
        self.assertContainsRe(err,
463
 
            "(?m)Fetching into experimental format")
464
 
 
465
 
    def test_pull_cross_to_experimental_format_warning(self):
466
 
        """You get a warning for pulling into experimental formats.
467
 
        """
468
 
        from_tree = self.make_branch_and_tree('from', format='2a')
469
 
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
470
 
        from_tree.commit(message='first commit')
471
 
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
472
 
        self.assertContainsRe(err,
473
 
            "(?m)Fetching into experimental format")
474
 
 
475
 
    def test_pull_show_base(self):
476
 
        """bzr pull supports --show-base
477
 
 
478
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
479
 
        # create two trees with conflicts, setup conflict, check that
480
 
        # conflicted file looks correct
481
 
        a_tree = self.example_branch('a')
482
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
483
 
 
484
 
        f = open(pathjoin('a', 'hello'),'wt')
485
 
        f.write('fee')
486
 
        f.close()
487
 
        a_tree.commit('fee')
488
 
 
489
 
        f = open(pathjoin('b', 'hello'),'wt')
490
 
        f.write('fie')
491
 
        f.close()
492
 
 
493
 
        out,err=self.run_bzr(['pull','-d','b','a','--show-base'])
494
 
 
495
 
        # check for message here
496
 
        self.assertEqual(err,
497
 
                         ' M  hello\nText conflict in hello\n1 conflicts encountered.\n')
498
 
 
499
 
        self.assertEqualDiff('<<<<<<< TREE\n'
500
 
                             'fie||||||| BASE-REVISION\n'
501
 
                             'foo=======\n'
502
 
                             'fee>>>>>>> MERGE-SOURCE\n',
503
 
                             open(pathjoin('b', 'hello')).read())
504
 
 
505
 
    def test_pull_show_base_working_tree_only(self):
506
 
        """--show-base only allowed if there's a working tree
507
 
 
508
 
        see https://bugs.launchpad.net/bzr/+bug/202374"""
509
 
        # create a branch, see that --show-base fails
510
 
        self.make_branch('from')
511
 
        self.make_branch('to')
512
 
        out=self.run_bzr(['pull','-d','to','from','--show-base'],retcode=3)
513
 
        self.assertEqual(out,
514
 
                         ('','bzr: ERROR: Need working tree for --show-base.\n'))
515
 
 
516
 
    def test_pull_tag_conflicts(self):
517
 
        """pulling tags with conflicts will change the exit code"""
518
 
        # create a branch, see that --show-base fails
519
 
        from_tree = self.make_branch_and_tree('from')
520
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
521
 
        to_tree = self.make_branch_and_tree('to')
522
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
523
 
        out = self.run_bzr(['pull','-d','to','from'],retcode=1)
524
 
        self.assertEqual(out,
525
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))