Exemplo n.º 1
0
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')
Exemplo n.º 2
0
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')
Exemplo n.º 3
0
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>'
    ])
Exemplo n.º 4
0
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>"
    ]
Exemplo n.º 5
0
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>"
    ]
Exemplo n.º 6
0
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>']
Exemplo n.º 7
0
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), [])
Exemplo n.º 8
0
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), [])
Exemplo n.º 9
0
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 ), [] )
Exemplo n.º 10
0
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 ), [] )
Exemplo n.º 11
0
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 ) == [] 
Exemplo n.º 12
0
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 ), [] )
Exemplo n.º 13
0
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) == []
Exemplo n.º 14
0
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) == []
Exemplo n.º 15
0
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) == []
Exemplo n.º 16
0
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 ) == [] 
Exemplo n.º 17
0
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 ), [] )
Exemplo n.º 18
0
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) == []
Exemplo n.º 19
0
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) == []
Exemplo n.º 20
0
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) == []
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
def test_HTTPMove_location_newlines():
    with pytest.raises(ValueError):
        webob_exc._HTTPMove(location="http://example.com\r\nX-Test: false")
Exemplo n.º 23
0
def test_HTTPMove_location_newlines():
    with pytest.raises(ValueError):
        webob_exc._HTTPMove(location="http://example.com\r\nX-Test: false")
Exemplo n.º 24
0
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)