~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-06 17:07:58 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061006170758-dcfe0c203afa330c
Implements Range header handling for GET requests. Fix a test.

* bzrlib/transport/http/__init__.py:
(TestingHTTPRequestHandler.parse_ranges,
TestingHTTPRequestHandler.send_range_content,
TestingHTTPRequestHandler.get_single_range,
TestingHTTPRequestHandler.get_multiple_ranges,
TestingHTTPRequestHandler.do_GET): New methods. Implements the Range
header handling for GET request.

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_readv): Add a test with a single range.

* bzrlib/tests/test_fetch.py:
(TestHttpFetch._count_log_matches): GET can succeeds with a 206 code.
(TestHttpFetch.test_weaves_are_retrieved_once): log_pattern was not
used here.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import re
18
19
import sys
19
20
 
20
21
from bzrlib.branch import Branch
198
199
 
199
200
    def _count_log_matches(self, target, logs):
200
201
        """Count the number of times the target file pattern was fetched in an http log"""
201
 
        log_pattern = '%s HTTP/1.1" 200 - "-" "bzr/%s' % \
202
 
            (target, bzrlib.__version__)
 
202
        get_succeeds_re = re.compile(
 
203
            '.*"GET .*%s HTTP/1.1" 20[06] - "-" "bzr/%s' %
 
204
            (     target,                    bzrlib.__version__))
203
205
        c = 0
204
206
        for line in logs:
205
 
            # TODO: perhaps use a regexp instead so we can match more
206
 
            # precisely?
207
 
            if line.find(log_pattern) > -1:
 
207
            if get_succeeds_re.match(line):
208
208
                c += 1
209
209
        return c
210
210
 
219
219
        target = BzrDir.create_branch_and_repo("target/")
220
220
        source = Branch.open(self.get_readonly_url("source/"))
221
221
        self.assertEqual(target.fetch(source), (2, []))
222
 
        log_pattern = '%%s HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__
223
222
        # this is the path to the literal file. As format changes 
224
223
        # occur it needs to be updated. FIXME: ask the store for the
225
224
        # path.