~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_wsgi.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-09 15:19:06 UTC
  • mfrom: (2681.1.7 send-bundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070809151906-hdn9oyslf2qib2op
Allow omitting -o for bundle, add --format

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for WSGI application"""
18
18
 
33
33
 
34
34
    def build_environ(self, updates=None):
35
35
        """Builds an environ dict with all fields required by PEP 333.
36
 
 
 
36
        
37
37
        :param updates: a dict to that will be incorporated into the returned
38
38
            dict using dict.update(updates).
39
39
        """
58
58
        if updates is not None:
59
59
            environ.update(updates)
60
60
        return environ
61
 
 
 
61
        
62
62
    def read_response(self, iterable):
63
63
        response = ''
64
64
        for string in iterable:
82
82
        self.read_response(iterable)
83
83
        self.assertEqual('405 Method not allowed', self.status)
84
84
        self.assertTrue(('Allow', 'POST') in self.headers)
85
 
 
86
 
    def _fake_make_request(self, transport, write_func, bytes, rcp):
 
85
        
 
86
    def _fake_make_request(self, transport, write_func, bytes):
87
87
        request = FakeRequest(transport, write_func)
88
88
        request.accept_bytes(bytes)
89
89
        self.request = request
90
90
        return request
91
 
 
 
91
    
92
92
    def test_smart_wsgi_app_uses_given_relpath(self):
93
93
        # The SmartWSGIApp should use the "bzrlib.relpath" field from the
94
94
        # WSGI environ to clone from its backing transport to get a specific
106
106
        })
107
107
        iterable = wsgi_app(environ, self.start_response)
108
108
        response = self.read_response(iterable)
109
 
        self.assertEqual([('clone', 'foo/bar/')] , transport.calls)
 
109
        self.assertEqual([('clone', 'foo/bar')] , transport.calls)
110
110
 
111
111
    def test_smart_wsgi_app_request_and_response(self):
112
112
        # SmartWSGIApp reads the smart request from the 'wsgi.input' file-like
138
138
            fake_app, prefix='/abc/', path_var='FOO')
139
139
        wrapped_app({'FOO': '/abc/xyz/.bzr/smart'}, None)
140
140
        self.assertEqual(['xyz'], calls)
141
 
 
 
141
       
142
142
    def test_relpath_setter_bad_path_prefix(self):
143
143
        # wsgi.RelpathSetter will reject paths with that don't match the prefix
144
144
        # with a 404.  This is probably a sign of misconfiguration; a server
151
151
            {'FOO': 'AAA/abc/xyz/.bzr/smart'}, self.start_response)
152
152
        self.read_response(iterable)
153
153
        self.assertTrue(self.status.startswith('404'))
154
 
 
 
154
        
155
155
    def test_relpath_setter_bad_path_suffix(self):
156
156
        # Similar to test_relpath_setter_bad_path_prefix: wsgi.RelpathSetter
157
157
        # will reject paths with that don't match the suffix '.bzr/smart' with a
165
165
            {'FOO': '/abc/xyz/.bzr/AAA'}, self.start_response)
166
166
        self.read_response(iterable)
167
167
        self.assertTrue(self.status.startswith('404'))
168
 
 
 
168
        
169
169
    def test_make_app(self):
170
170
        # The make_app helper constructs a SmartWSGIApp wrapped in a
171
171
        # RelpathSetter.
179
179
        backing_transport = app.app.backing_transport
180
180
        chroot_backing_transport = backing_transport.server.backing_transport
181
181
        self.assertEndsWith(chroot_backing_transport.base, 'a%20root/')
182
 
        self.assertEqual(app.app.root_client_path, 'a prefix')
 
182
        self.assertEqual(app.prefix, 'a prefix')
183
183
        self.assertEqual(app.path_var, 'a path_var')
184
184
 
185
185
    def test_incomplete_request(self):
186
186
        transport = FakeTransport()
187
187
        wsgi_app = wsgi.SmartWSGIApp(transport)
188
 
        def make_request(transport, write_func, bytes, root_client_path):
 
188
        def make_request(transport, write_func, bytes):
189
189
            request = IncompleteRequest(transport, write_func)
190
190
            request.accept_bytes(bytes)
191
191
            self.request = request
243
243
 
244
244
 
245
245
class FakeRequest(object):
246
 
 
 
246
    
247
247
    def __init__(self, transport, write_func):
248
248
        self.transport = transport
249
249
        self.write_func = write_func