~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_dpush.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) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008, 2009 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
18
18
"""Black-box tests for bzr dpush."""
19
19
 
20
20
 
21
 
from bzrlib import (
22
 
    tests,
23
 
    )
24
 
from bzrlib.tests import (
25
 
    script,
26
 
    test_foreign,
27
 
    )
28
 
from bzrlib.tests.blackbox import test_push
29
 
from bzrlib.tests.scenarios import (
30
 
    load_tests_apply_scenarios,
31
 
    )
32
 
 
33
 
 
34
 
load_tests = load_tests_apply_scenarios
35
 
 
36
 
 
37
 
class TestDpush(tests.TestCaseWithTransport):
 
21
import os
 
22
 
 
23
from bzrlib.branch import (
 
24
    Branch,
 
25
    )
 
26
from bzrlib.bzrdir import (
 
27
    BzrDirFormat,
 
28
    )
 
29
from bzrlib.foreign import (
 
30
    ForeignBranch,
 
31
    ForeignRepository,
 
32
    )
 
33
from bzrlib.repository import (
 
34
    Repository,
 
35
    )
 
36
from bzrlib.tests.blackbox import (
 
37
    ExternalBase,
 
38
    )
 
39
from bzrlib.tests.test_foreign import (
 
40
    DummyForeignVcsDirFormat,
 
41
    )
 
42
 
 
43
 
 
44
class TestDpush(ExternalBase):
38
45
 
39
46
    def setUp(self):
 
47
        BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
 
48
        self.addCleanup(self.unregister_format)
40
49
        super(TestDpush, self).setUp()
41
 
        test_foreign.register_dummy_foreign_for_test(self)
 
50
 
 
51
    def unregister_format(self):
 
52
        try:
 
53
            BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat)
 
54
        except ValueError:
 
55
            pass
42
56
 
43
57
    def make_dummy_builder(self, relpath):
44
 
        builder = self.make_branch_builder(
45
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
46
 
        builder.build_snapshot('revid', None,
 
58
        builder = self.make_branch_builder(relpath, 
 
59
                format=DummyForeignVcsDirFormat())
 
60
        builder.build_snapshot('revid', None, 
47
61
            [('add', ('', 'TREE_ROOT', 'directory', None)),
48
62
             ('add', ('foo', 'fooid', 'file', 'bar'))])
49
63
        return builder
53
67
        source_tree = self.make_branch_and_tree("dc")
54
68
        output, error = self.run_bzr("dpush -d dc dp", retcode=3)
55
69
        self.assertEquals("", output)
56
 
        self.assertContainsRe(error,
57
 
            'in the same VCS, lossy push not necessary. Please use regular '
58
 
            'push.')
 
70
        self.assertContainsRe(error, 'not a foreign branch, use regular push')
59
71
 
60
72
    def test_dpush(self):
61
73
        branch = self.make_dummy_builder('d').get_branch()
64
76
        self.build_tree(("dc/foo", "blaaaa"))
65
77
        dc.open_workingtree().commit('msg')
66
78
 
67
 
        script.run_script(self, """
68
 
            $ bzr dpush -d dc d
69
 
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
70
 
            2>This may take some time. Upgrade the repositories to the same format for better performance.
71
 
            2>Pushed up to revision 2.
72
 
            $ bzr status dc
73
 
            """)
 
79
        self.check_output("", "dpush -d dc d")
 
80
        self.check_output("", "status dc")
74
81
 
75
82
    def test_dpush_new(self):
76
 
        b = self.make_dummy_builder('d').get_branch()
 
83
        branch = self.make_dummy_builder('d').get_branch()
77
84
 
78
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
85
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
79
86
        self.build_tree_contents([("dc/foofile", "blaaaa")])
80
87
        dc_tree = dc.open_workingtree()
81
88
        dc_tree.add("foofile")
82
89
        dc_tree.commit("msg")
83
90
 
84
 
        script.run_script(self, '''
85
 
            $ bzr dpush -d dc d
86
 
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
87
 
            2>This may take some time. Upgrade the repositories to the same format for better performance.
88
 
            2>Pushed up to revision 2.
89
 
            $ bzr revno dc
90
 
            2
91
 
            $ bzr status dc
92
 
            ''')
 
91
        self.check_output("", "dpush -d dc d")
 
92
        self.check_output("2\n", "revno dc")
 
93
        self.check_output("", "status dc")
93
94
 
94
95
    def test_dpush_wt_diff(self):
95
 
        b = self.make_dummy_builder('d').get_branch()
 
96
        branch = self.make_dummy_builder('d').get_branch()
96
97
 
97
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
98
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
98
99
        self.build_tree_contents([("dc/foofile", "blaaaa")])
99
100
        dc_tree = dc.open_workingtree()
100
101
        dc_tree.add("foofile")
101
102
        newrevid = dc_tree.commit('msg')
102
103
 
103
104
        self.build_tree_contents([("dc/foofile", "blaaaal")])
104
 
        script.run_script(self, '''
105
 
            $ bzr dpush -d dc d --no-strict
106
 
            2>Doing on-the-fly conversion from DummyForeignVcsRepositoryFormat() to RepositoryFormat2a().
107
 
            2>This may take some time. Upgrade the repositories to the same format for better performance.
108
 
            2>Pushed up to revision 2.
109
 
            ''')
 
105
        self.check_output("", "dpush -d dc d")
110
106
        self.assertFileEqual("blaaaal", "dc/foofile")
111
 
        # if the dummy vcs wasn't that dummy we could uncomment the line below
112
 
        # self.assertFileEqual("blaaaa", "d/foofile")
113
 
        script.run_script(self, '''
114
 
            $ bzr status dc
115
 
            modified:
116
 
              foofile
117
 
            ''')
 
107
        self.check_output('modified:\n  foofile\n', "status dc")
118
108
 
119
109
    def test_diverged(self):
120
110
        builder = self.make_dummy_builder('d')
121
111
 
122
 
        b = builder.get_branch()
 
112
        branch = builder.get_branch()
123
113
 
124
 
        dc = b.bzrdir.sprout('dc', force_new_repo=True)
 
114
        dc = branch.bzrdir.sprout('dc', force_new_repo=True)
125
115
        dc_tree = dc.open_workingtree()
126
116
 
127
117
        self.build_tree_contents([("dc/foo", "bar")])
133
123
        output, error = self.run_bzr("dpush -d dc d", retcode=3)
134
124
        self.assertEquals(output, "")
135
125
        self.assertContainsRe(error, "have diverged")
136
 
 
137
 
 
138
 
class TestDpushStrictMixin(object):
139
 
 
140
 
    def setUp(self):
141
 
        test_foreign.register_dummy_foreign_for_test(self)
142
 
        # Create an empty branch where we will be able to push
143
 
        self.foreign = self.make_branch(
144
 
            'to', format=test_foreign.DummyForeignVcsDirFormat())
145
 
 
146
 
    def set_config_push_strict(self, value):
147
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
148
 
        # should do)
149
 
        conf = self.tree.branch.get_config()
150
 
        conf.set_user_option('dpush_strict', value)
151
 
 
152
 
    _default_command = ['dpush', '../to']
153
 
 
154
 
 
155
 
class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
156
 
                                    test_push.TestPushStrictWithoutChanges):
157
 
 
158
 
    def setUp(self):
159
 
        test_push.TestPushStrictWithoutChanges.setUp(self)
160
 
        TestDpushStrictMixin.setUp(self)
161
 
 
162
 
 
163
 
class TestDpushStrictWithChanges(TestDpushStrictMixin,
164
 
                                 test_push.TestPushStrictWithChanges):
165
 
 
166
 
    scenarios = test_push.strict_push_change_scenarios
167
 
 
168
 
    _changes_type = None # Set by load_tests
169
 
 
170
 
    def setUp(self):
171
 
        test_push.TestPushStrictWithChanges.setUp(self)
172
 
        TestDpushStrictMixin.setUp(self)
173
 
 
174
 
    def test_push_with_revision(self):
175
 
        raise tests.TestNotApplicable('dpush does not handle --revision')