def test_WSGIHTTPException_generate_response(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'PUT', 'HTTP_ACCEPT': 'text/html' } excep = webob_exc.WSGIHTTPException() assert_equal(excep(environ, start_response), [ b'<html>\n' b' <head>\n' b' <title>500 Internal Server Error</title>\n' b' </head>\n' b' <body>\n' b' <h1>500 Internal Server Error</h1>\n' b' <br /><br />\n' b'\n' b'\n\n' b' </body>\n' b'</html>' ])
def test_WSGIHTTPException_generate_response(): def start_response(status, headers, exc_info=None): assert ("Content-Type", "text/html; charset=UTF-8") in headers pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "PUT", "HTTP_ACCEPT": "text/html", } excep = webob_exc.WSGIHTTPException() assert excep(environ, start_response) == [ b"<html>\n" b" <head>\n" b" <title>500 Internal Server Error</title>\n" b" </head>\n" b" <body>\n" b" <h1>500 Internal Server Error</h1>\n" b" <br /><br />\n" b"\n" b"\n\n" b" </body>\n" b"</html>" ]
def test_WSGIHTTPException___str__(): exc1 = webob_exc.WSGIHTTPException(detail='Detail') eq_(str(exc1), 'Detail') class Explain(webob_exc.WSGIHTTPException): explanation = 'Explanation' eq_(str(Explain()), 'Explanation')
def test_WSGIHTTPException___str__(): exc1 = webob_exc.WSGIHTTPException(detail='Detail') assert str(exc1) == 'Detail' class Explain(webob_exc.WSGIHTTPException): explanation = 'Explanation' assert str(Explain()) == 'Explanation'
def test_WSGIHTTPException___str__(): exc1 = webob_exc.WSGIHTTPException(detail="Detail") assert str(exc1) == "Detail" class Explain(webob_exc.WSGIHTTPException): explanation = "Explanation" assert str(Explain()) == "Explanation"
def test_WSGIHTTPException_w_body_template(): from string import Template TEMPLATE = '$foo: $bar' exc = webob_exc.WSGIHTTPException(body_template=TEMPLATE) assert_equal(exc.body_template, TEMPLATE) ok_(isinstance(exc.body_template_obj, Template)) eq_(exc.body_template_obj.substitute({ 'foo': 'FOO', 'bar': 'BAR' }), 'FOO: BAR')
def test_WSGIHTTPException_w_body_template(): from string import Template TEMPLATE = "$foo: $bar" exc = webob_exc.WSGIHTTPException(body_template=TEMPLATE) assert exc.body_template == TEMPLATE assert isinstance(exc.body_template_obj, Template) assert exc.body_template_obj.substitute({ "foo": "FOO", "bar": "BAR" }) == "FOO: BAR"
def test_WSGIHTTPException_wsgi_response(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } excep = webob_exc.WSGIHTTPException() assert_equal(excep.wsgi_response(environ, start_response), [])
def test_WSGIHTTPException_wsgi_response(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD", } excep = webob_exc.WSGIHTTPException() assert excep.wsgi_response(environ, start_response) == []
def test_WSGIHTTPException_call_w_body(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'PUT' } excep = webob_exc.WSGIHTTPException() excep.body = b'test' assert_equal(excep(environ, start_response), [b'test'])
def test_WSGIHTTPException_exception_no_newstyle(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } excep = webob_exc.WSGIHTTPException() webob_exc.newstyle_exceptions = False assert excep(environ, start_response) == []
def test_WSGIHTTPException_call_w_body(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "PUT", } excep = webob_exc.WSGIHTTPException() excep.body = b"test" assert excep(environ, start_response) == [b"test"]
def test_WSGIHTTPException_respects_accept_star_star(): def start_response(status, headers, exc_info=None): for header in headers: if header[0] == 'Content-Type': assert header[1].startswith('text/html') exc = webob_exc.WSGIHTTPException() resp = exc.generate_response(environ={ 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'GET', 'HTTP_ACCEPT': '*/*', }, start_response=start_response)
def test_WSGIHTTPException_respects_accept_star_star(): def start_response(status, headers, exc_info=None): for header in headers: if header[0] == "Content-Type": assert header[1].startswith("text/html") exc = webob_exc.WSGIHTTPException() exc.generate_response( environ={ "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "GET", "HTTP_ACCEPT": "*/*", }, start_response=start_response, )
def test_WSGIHTTPException_headers(): exc = webob_exc.WSGIHTTPException(headers=[('Set-Cookie', 'a=1'), ('Set-Cookie', 'a=2')]) mixed = exc.headers.mixed() assert mixed['set-cookie'] == ['a=1', 'a=2']
def test_WSGIHTTPException_headers(): exc = webob_exc.WSGIHTTPException(headers=[("Set-Cookie", "a=1"), ("Set-Cookie", "a=2")]) mixed = exc.headers.mixed() assert mixed["set-cookie"] == ["a=1", "a=2"]