~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: Aaron Bentley
  • Date: 2006-03-31 02:39:09 UTC
  • mfrom: (1558.7.10 bzr.ab.integration)
  • mto: This revision was merged to the branch mainline in revision 1634.
  • Revision ID: aaron.bentley@utoronto.ca-20060331023909-957277c1233c6aff
Merge from bzr.ab.integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        br_a, br_b = make_branches(self)
104
104
        fetch_steps(self, br_a, br_b, br_a)
105
105
 
 
106
    def test_fetch_self(self):
 
107
        wt = self.make_branch_and_tree('br')
 
108
        self.assertEqual(wt.branch.fetch(wt.branch), (0, []))
 
109
 
106
110
 
107
111
class TestMergeFetch(TestCaseWithTransport):
108
112
 
186
190
        br_rem_a = Branch.open(self.get_readonly_url('branch1'))
187
191
        fetch_steps(self, br_rem_a, br_b, br_a)
188
192
 
 
193
    def _count_log_matches(self, target, logs):
 
194
        """Count the number of times the target file pattern was fetched in an http log"""
 
195
        log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
 
196
            (target, bzrlib.__version__)
 
197
        c = 0
 
198
        for line in logs:
 
199
            # TODO: perhaps use a regexp instead so we can match more
 
200
            # precisely?
 
201
            if line.find(log_pattern) > -1:
 
202
                c += 1
 
203
        return c
 
204
 
189
205
    def test_weaves_are_retrieved_once(self):
190
206
        self.build_tree(("source/", "source/file", "target/"))
191
207
        wt = self.make_branch_and_tree('source')
197
213
        target = BzrDir.create_branch_and_repo("target/")
198
214
        source = Branch.open(self.get_readonly_url("source/"))
199
215
        self.assertEqual(target.fetch(source), (2, []))
200
 
        log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s"' % bzrlib.__version__
 
216
        log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
201
217
        # this is the path to the literal file. As format changes 
202
218
        # occur it needs to be updated. FIXME: ask the store for the
203
219
        # path.
204
 
        weave_suffix = log_pattern % 'weaves/ce/id.weave'
205
 
        self.assertEqual(1,
206
 
            len([log for log in self.get_readonly_server().logs if log.endswith(weave_suffix)]))
207
 
        inventory_weave_suffix = log_pattern % 'inventory.weave'
208
 
        self.assertEqual(1,
209
 
            len([log for log in self.get_readonly_server().logs if log.endswith(
210
 
                inventory_weave_suffix)]))
 
220
        self.log("web server logs are:")
 
221
        http_logs = self.get_readonly_server().logs
 
222
        self.log('\n'.join(http_logs))
 
223
        self.assertEqual(1, self._count_log_matches('weaves/ce/id.weave', http_logs))
 
224
        self.assertEqual(1, self._count_log_matches('inventory.weave', http_logs))
211
225
        # this r-h check test will prevent regressions, but it currently already 
212
226
        # passes, before the patch to cache-rh is applied :[
213
 
        revision_history_suffix = log_pattern % 'revision-history'
214
 
        self.assertEqual(1,
215
 
            len([log for log in self.get_readonly_server().logs if log.endswith(
216
 
                revision_history_suffix)]))
 
227
        self.assertEqual(1, self._count_log_matches('revision-history', http_logs))
217
228
        # FIXME naughty poking in there.
218
229
        self.get_readonly_server().logs = []
219
230
        # check there is nothing more to fetch
220
231
        source = Branch.open(self.get_readonly_url("source/"))
221
232
        self.assertEqual(target.fetch(source), (0, []))
222
 
        self.failUnless(self.get_readonly_server().logs[0].endswith(log_pattern % 'branch-format'))
223
 
        self.failUnless(self.get_readonly_server().logs[1].endswith(log_pattern % 'revision-history'))
224
 
        self.assertEqual(2, len(self.get_readonly_server().logs))
 
233
        # should make just two requests
 
234
        http_logs = self.get_readonly_server().logs
 
235
        self.log("web server logs are:")
 
236
        self.log('\n'.join(http_logs))
 
237
        self.assertEqual(1, self._count_log_matches('branch-format', http_logs[0:1]))
 
238
        self.assertEqual(1, self._count_log_matches('revision-history', http_logs[1:2]))
 
239
        self.assertEqual(2, len(http_logs))