~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical
 
1
# Copyright (C) 2005, 2006 Canonical
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2
16
 
3
17
# FIXME: This test should be repeated for each available http client
4
18
# implementation; at the moment we have urllib and pycurl.
5
19
 
 
20
import bzrlib
6
21
from bzrlib.tests import TestCase
7
22
from bzrlib.transport.http import extract_auth
8
23
from bzrlib.transport.http._urllib import HttpTransport
 
24
from bzrlib.transport.http._pycurl import PyCurlTransport
 
25
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
9
26
 
10
27
class FakeManager (object):
11
28
    def __init__(self):
14
31
    def add_password(self, realm, host, username, password):
15
32
        self.credentials.append([realm, host, username, password])
16
33
 
17
 
        
 
34
 
18
35
class TestHttpUrls(TestCase):
19
36
    def test_url_parsing(self):
20
37
        f = FakeManager()
55
72
        eq = self.assertEqualDiff
56
73
        eq(t.abspath('.bzr/tree-version'),
57
74
           'http://bzr.ozlabs.org/.bzr/tree-version')
 
75
 
 
76
 
 
77
class TestHttpConnections(TestCaseWithWebserver):
 
78
 
 
79
    _transport = HttpTransport
 
80
 
 
81
    def setUp(self):
 
82
        super(TestHttpConnections, self).setUp()
 
83
        self.build_tree(['xxx', 'foo/', 'foo/bar'], line_endings='binary')
 
84
 
 
85
    def test_http_has(self):
 
86
        server = self.get_readonly_server()
 
87
        t = self._transport(server.get_url())
 
88
        self.assertEqual(t.has('foo/bar'), True)
 
89
        self.assertEqual(len(server.logs), 1)
 
90
        self.assertContainsRe(server.logs[0], 
 
91
            r'"HEAD /foo/bar HTTP/1.." (200|302) - "-" "bzr/')
 
92
 
 
93
    def test_http_has_not_found(self):
 
94
        server = self.get_readonly_server()
 
95
        t = self._transport(server.get_url())
 
96
        self.assertEqual(t.has('not-found'), False)
 
97
        self.assertContainsRe(server.logs[1], 
 
98
            r'"HEAD /not-found HTTP/1.." 404 - "-" "bzr/')
 
99
 
 
100
    def test_http_get(self):
 
101
        server = self.get_readonly_server()
 
102
        t = self._transport(server.get_url())
 
103
        fp = t.get('foo/bar')
 
104
        self.assertEqualDiff(
 
105
            fp.read(),
 
106
            'contents of foo/bar\n')
 
107
        self.assertEqual(len(server.logs), 1)
 
108
        self.assertTrue(server.logs[0].find(
 
109
            '"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s' % bzrlib.__version__) > -1)
 
110
 
 
111
 
 
112
class TestHttpConnections_pycurl(TestHttpConnections):
 
113
    _transport = PyCurlTransport
 
114
 
 
115
    def setUp(self):
 
116
        super(TestHttpConnections_pycurl, self).setUp()
 
117