Skip to content

Commit

Permalink
Added tests for #1125 fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
defnull committed Dec 8, 2019
1 parent e0a9278 commit 1c22d42
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import with_statement
import bottle
from .tools import ServerTestBase, chdir
from bottle import tob, touni
from bottle import tob, touni, HTTPResponse

class TestWsgi(ServerTestBase):
''' Tests for WSGI functionality, routing and output casting (decorators) '''
Expand Down Expand Up @@ -58,7 +58,6 @@ def get204(self):
for h, v in bottle.response.headerlist:
self.assertFalse(h.lower() in bad, "Header %s not deleted" % h)


def get304(self):
""" 304 responses must not return entity headers """
bad = ('allow', 'content-encoding', 'content-language',
Expand Down Expand Up @@ -173,6 +172,7 @@ def test():
self.assertTrue('b=b' in c)
self.assertTrue('c=c; Path=/' in c)


class TestErrorHandling(ServerTestBase):
def test_error_routing(self):

Expand Down Expand Up @@ -364,6 +364,26 @@ def _get():
self.assertInBody("hook_content", "/")
self.assertEqual(["route", "after"], called)

def test_after_response_hook_can_set_headers(self):
""" Issue #1125 """

@bottle.route()
def test1():
return "test"
@bottle.route()
def test2():
return HTTPResponse("test", 200)
@bottle.route()
def test3():
raise HTTPResponse("test", 200)

@bottle.hook('after_request')
def hook():
bottle.response.headers["X-Hook"] = 'works'

for route in ("/test1", "/test2", "/test3"):
self.assertBody('test', route)
self.assertHeader('X-Hook', 'works', route)

def test_template(self):
@bottle.route(template='test {{a}} {{b}}')
Expand Down Expand Up @@ -458,7 +478,7 @@ def e(x=5, y=6): pass
class TestAppShortcuts(ServerTestBase):
def setUp(self):
ServerTestBase.setUp(self)

def testWithStatement(self):
default = bottle.default_app()
inner_app = bottle.Bottle()
Expand Down

0 comments on commit 1c22d42

Please sign in to comment.