~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_wsgi.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
 
        
 
85
 
86
86
    def _fake_make_request(self, transport, write_func, bytes, rcp):
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
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.
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