def test_HTTPMove_location_newlines(): environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/', } with pytest.raises(ValueError): webob_exc._HTTPMove(location='http://example.com\r\nX-Test: false')
def test_HTTPFound_unused_environ_variable(): class Crashy(object): def __str__(self): raise Exception('I crashed!') def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/', 'HTTP_ACCEPT': 'text/html', 'crashy': Crashy() } m = webob_exc._HTTPMove(location='http://www.example.com') assert_equal(m(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' The resource has been moved to ' b'<a href="http://www.example.com">' b'http://www.example.com</a>;\n' b'you should be redirected automatically.\n' b'\n\n' b' </body>\n' b'</html>' ])
def test_HTTPFound_unused_environ_variable(): class Crashy(object): def __str__(self): raise Exception("I crashed!") def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "GET", "PATH_INFO": "/", "HTTP_ACCEPT": "text/html", "crashy": Crashy(), } m = webob_exc._HTTPMove(location="http://www.example.com") assert m(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" The resource has been moved to " b'<a href="http://www.example.com">' b"http://www.example.com</a>;\n" b"you should be redirected automatically.\n" b"\n\n" b" </body>\n" b"</html>" ]
def test_HTTPFound_unused_environ_variable(): class Crashy(object): def __str__(self): raise Exception('I crashed!') def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/', 'HTTP_ACCEPT': 'text/html', 'crashy': Crashy() } m = webob_exc._HTTPMove(location='http://www.example.com') assert m(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' The resource has been moved to ' b'<a href="http://www.example.com">' b'http://www.example.com</a>;\n' b'you should be redirected automatically.\n' b'\n\n' b' </body>\n' b'</html>']
def test_HTTPMove_location_not_none(): def start_response(status, headers, exc_info=None): pass environ = {"wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD"} m = _HTTPMove(location="http://example.com") assert_equal(m(environ, start_response), [])
def test_HTTPMove_call_add_slash(): def start_response(status, headers, exc_info=None): pass environ = {"wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD"} m = _HTTPMove() m.add_slash = True assert_equal(m(environ, start_response), [])
def test_HTTPMove_location_not_none(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } m = _HTTPMove(location='http://example.com') assert_equal( m( environ, start_response ), [] )
def test_HTTPMove(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/', } m = _HTTPMove() assert_equal( m( environ, start_response ), [] )
def test_HTTPMove(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/', } m = webob_exc._HTTPMove() assert m( environ, start_response ) == []
def test_HTTPMove_call_add_slash(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } m = _HTTPMove() m.add_slash = True assert_equal( m( environ, start_response ), [] )
def test_HTTPMove_location_not_none(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD", "PATH_INFO": "/", } m = webob_exc._HTTPMove(location="http://example.com") assert m(environ, start_response) == []
def test_HTTPMove(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD", "PATH_INFO": "/", } m = webob_exc._HTTPMove() assert m(environ, start_response) == []
def test_HTTPMove_call_add_slash(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD", "PATH_INFO": "/", } m = webob_exc._HTTPMove() m.add_slash = True assert m(environ, start_response) == []
def test_HTTPMove_call_query_string(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } m = webob_exc._HTTPMove() m.add_slash = True environ[ 'QUERY_STRING' ] = 'querystring' environ['PATH_INFO'] = '/' assert m( environ, start_response ) == []
def test_HTTPMove_call_query_string(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD' } m = _HTTPMove() m.add_slash = True environ[ 'QUERY_STRING' ] = 'querystring' environ['PATH_INFO'] = '/' assert_equal( m( environ, start_response ), [] )
def test_HTTPMove_call_add_slash(): def start_response(status, headers, exc_info=None): pass environ = { 'wsgi.url_scheme': 'HTTP', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '80', 'REQUEST_METHOD': 'HEAD', 'PATH_INFO': '/', } m = webob_exc._HTTPMove() m.add_slash = True assert m(environ, start_response) == []
def test_HTTPMove_call_query_string(): def start_response(status, headers, exc_info=None): pass environ = { "wsgi.url_scheme": "HTTP", "SERVER_NAME": "localhost", "SERVER_PORT": "80", "REQUEST_METHOD": "HEAD", } m = webob_exc._HTTPMove() m.add_slash = True environ["QUERY_STRING"] = "querystring" environ["PATH_INFO"] = "/" assert m(environ, start_response) == []
def test_HTTPMove_add_slash_and_location(): def start_response(status, headers, exc_info=None): pass with pytest.raises(TypeError): webob_exc._HTTPMove(location="http://example.com", add_slash=True)
def test_HTTPMove_location_newlines(): with pytest.raises(ValueError): webob_exc._HTTPMove(location="http://example.com\r\nX-Test: false")
def test_HTTPMove_add_slash_and_location(): def start_response(status, headers, exc_info=None): pass with pytest.raises(TypeError): webob_exc._HTTPMove(location='http://example.com', add_slash=True)