~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: Michael Ellerman
  • Date: 2005-12-10 22:11:13 UTC
  • mto: This revision was merged to the branch mainline in revision 1528.
  • Revision ID: michael@ellerman.id.au-20051210221113-99ca561aaab4661e
Simplify handling of DivergedBranches in cmd_pull()

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
import sys
19
19
 
 
20
import bzrlib.errors
 
21
from bzrlib.tests.test_revision import make_branches
 
22
from bzrlib.trace import mutter
20
23
from bzrlib.branch import Branch
21
 
from bzrlib.builtins import merge
22
 
import bzrlib.errors
23
24
from bzrlib.fetch import greedy_fetch
24
 
from bzrlib.tests.test_revision import make_branches
 
25
from bzrlib.merge import merge
 
26
from bzrlib.clone import copy_branch
 
27
 
25
28
from bzrlib.tests import TestCaseInTempDir
26
29
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
27
 
from bzrlib.trace import mutter
28
30
 
29
31
 
30
32
def has_revision(branch, revision_id):
31
33
    try:
32
 
        branch.repository.get_revision_xml_file(revision_id)
 
34
        branch.get_revision_xml(revision_id)
33
35
        return True
34
36
    except bzrlib.errors.NoSuchRevision:
35
37
        return False
84
86
        self.assertFalse(has_revision(br_a3, br_a.revision_history()[revno]))
85
87
    self.assertEqual(greedy_fetch(br_a3, br_a2, br_a.revision_history()[2])[0], 3)
86
88
    fetched = greedy_fetch(br_a3, br_a2, br_a.revision_history()[3])[0]
87
 
    self.assertEquals(fetched, 6, "fetched %d instead of 6" % fetched)
 
89
    self.assertEquals(fetched, 3, "fetched %d instead of 3" % fetched)
88
90
    # InstallFailed should be raised if the branch is missing the revision
89
91
    # that was requested.
90
92
    self.assertRaises(bzrlib.errors.InstallFailed, greedy_fetch, br_a3,
126
128
        os.mkdir('br1')
127
129
        br1 = Branch.initialize('br1')
128
130
        br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
129
 
        br1.clone('br2')
 
131
        copy_branch(br1, 'br2')
130
132
        br2 = Branch.open('br2')
131
133
        br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
132
134
        br2.working_tree().commit(message='rev 2-1', rev_id='2-1')
136
138
 
137
139
    def _check_revs_present(self, br2):
138
140
        for rev_id in '1-1', '1-2', '2-1':
139
 
            self.assertTrue(br2.repository.has_revision(rev_id))
140
 
            rev = br2.repository.get_revision(rev_id)
 
141
            self.assertTrue(br2.has_revision(rev_id))
 
142
            rev = br2.get_revision(rev_id)
141
143
            self.assertEqual(rev.revision_id, rev_id)
142
 
            self.assertTrue(br2.repository.get_inventory(rev_id))
 
144
            self.assertTrue(br2.get_inventory(rev_id))
143
145
 
144
146
 
145
147
 
151
153
        self.build_tree_contents([('br1/file', 'original contents\n')])
152
154
        br1.working_tree().add(['file'], ['this-file-id'])
153
155
        br1.working_tree().commit(message='rev 1-1', rev_id='1-1')
154
 
        br1.clone('br2')
 
156
        copy_branch(br1, 'br2')
155
157
        br2 = Branch.open('br2')
156
158
        self.build_tree_contents([('br1/file', 'original from 1\n')])
157
159
        br1.working_tree().commit(message='rev 1-2', rev_id='1-2')
171
173
                             ('1-3', 'agreement\n'),
172
174
                             ('2-1', 'contents in 2\n'),
173
175
                             ('2-2', 'agreement\n')]:
174
 
            self.assertEqualDiff(
175
 
                br2.repository.revision_tree(
176
 
                    rev_id).get_file_text('this-file-id'), text)
 
176
            self.assertEqualDiff(br2.revision_tree(rev_id).get_file_text('this-file-id'),
 
177
                                 text)
177
178
 
178
179
 
179
180
 
180
181
 
181
182
class TestHttpFetch(TestCaseWithWebserver):
182
183
 
 
184
    def setUp(self):
 
185
        super(TestHttpFetch, self).setUp()
 
186
        self.weblogs = []
 
187
 
183
188
    def test_fetch(self):
184
189
        #highest indices a: 5, b: 7
185
190
        br_a, br_b = make_branches(self)
186
 
        br_rem_a = Branch.open(self.get_remote_url(br_a.base))
 
191
        br_rem_a = Branch.open(self.get_remote_url(br_a._transport.base))
187
192
        fetch_steps(self, br_rem_a, br_b, br_a)
188
193
 
 
194
    def log(self, *args):
 
195
        """Capture web server log messages for introspection."""
 
196
        super(TestHttpFetch, self).log(*args)
 
197
        # if this call indicates a url being fetched, save it specially
 
198
        if args[0].startswith("webserver"):
 
199
            self.weblogs.append(args[3])
 
200
 
189
201
    def test_weaves_are_retrieved_once(self):
190
202
        self.build_tree(("source/", "source/file", "target/"))
191
203
        branch = Branch.initialize("source")
201
213
        # path.
202
214
        weave_suffix = 'weaves/ce/id.weave HTTP/1.1" 200 -'
203
215
        self.assertEqual(1,
204
 
            len([log for log in self.server.logs if log.endswith(weave_suffix)]))
 
216
            len([log for log in self.weblogs if log.endswith(weave_suffix)]))
205
217
        inventory_weave_suffix = 'inventory.weave HTTP/1.1" 200 -'
206
218
        self.assertEqual(1,
207
 
            len([log for log in self.server.logs if log.endswith(
 
219
            len([log for log in self.weblogs if log.endswith(
208
220
                inventory_weave_suffix)]))
209
221
        # this r-h check test will prevent regressions, but it currently already 
210
222
        # passes, before the patch to cache-rh is applied :[
211
223
        revision_history_suffix = 'revision-history HTTP/1.1" 200 -'
212
224
        self.assertEqual(1,
213
 
            len([log for log in self.server.logs if log.endswith(
 
225
            len([log for log in self.weblogs if log.endswith(
214
226
                revision_history_suffix)]))
215
 
        # FIXME naughty poking in there.
216
 
        self.server.logs = []
 
227
        self.weblogs = []
217
228
        # check there is nothing more to fetch
218
229
        source = Branch.open(self.get_remote_url("source/"))
219
230
        self.assertEqual(greedy_fetch(target, source), (0, []))
220
 
        self.failUnless(self.server.logs[0].endswith('branch-format HTTP/1.1" 200 -'))
221
 
        self.failUnless(self.server.logs[1].endswith('revision-history HTTP/1.1" 200 -'))
222
 
        self.assertEqual(2, len(self.server.logs))
 
231
        self.failUnless(self.weblogs[0].endswith('branch-format HTTP/1.1" 200 -'))
 
232
        self.failUnless(self.weblogs[1].endswith('revision-history HTTP/1.1" 200 -'))
 
233
        self.assertEqual(2, len(self.weblogs))