/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_simple.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-10 02:33:15 UTC
  • mto: This revision was merged to the branch mainline in revision 441.
  • Revision ID: john@arbash-meinel.com-20110210023315-515pkynlfpfs3cvm
Fix bug #716201 by suppressing body content when getting a HEAD request.

This adds some WSGI middleware that suppresses returning body content if a HEAD request
is received.

Note that we don't yet pass GET down to the lower levels, so they could still
decide whether they can do less work or not. We may want to make the standard BranchWSGIApp
do less work under those circumstances.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009 Canonical Ltd.
 
1
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd.
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
23
23
from bzrlib import config
24
24
 
25
25
from loggerhead.apps.branch import BranchWSGIApp
 
26
from loggerhead.apps.http_head import HeadMiddleware
26
27
from paste.fixture import TestApp
27
28
from paste.httpexceptions import HTTPExceptionHandler
28
29
 
157
158
        res = app.get('/changes', status=404)
158
159
 
159
160
 
 
161
class TestHeadMiddleware(BasicTests):
 
162
 
 
163
    def setUp(self):
 
164
        BasicTests.setUp(self)
 
165
        self.createBranch()
 
166
 
 
167
        self.msg = 'trivial commit message'
 
168
        self.revid = self.tree.commit(message=self.msg)
 
169
 
 
170
    def setUpLoggerhead(self, **kw):
 
171
        branch_app = BranchWSGIApp(self.tree.branch, '', **kw).app
 
172
        return TestApp(HTTPExceptionHandler(HeadMiddleware(branch_app)))
 
173
 
 
174
    def test_get(self):
 
175
        app = self.setUpLoggerhead()
 
176
        res = app.get('/changes')
 
177
        res.mustcontain(self.msg)
 
178
        self.assertEqual('text/html', res.header('Content-Type'))
 
179
 
 
180
    def test_head(self):
 
181
        app = self.setUpLoggerhead()
 
182
        res = app.get('/changes', extra_environ={'REQUEST_METHOD': 'HEAD'})
 
183
        self.assertEqual('text/html', res.header('Content-Type'))
 
184
        self.assertEqualDiff('', res.body)
 
185
 
160
186
#class TestGlobalConfig(BasicTests):
161
187
#    """
162
188
#    Test that global config settings are respected