Beispiel #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')
Beispiel #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')
Beispiel #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>'
    ])
Beispiel #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>"
    ]
Beispiel #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>"
    ]
Beispiel #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>']
Beispiel #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), [])
Beispiel #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), [])
Beispiel #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 ), [] )
Beispiel #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 ), [] )
Beispiel #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 ) == [] 
Beispiel #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 ), [] )
Beispiel #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) == []
Beispiel #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) == []
Beispiel #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) == []
Beispiel #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 ) == [] 
Beispiel #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 ), [] )
Beispiel #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) == []
Beispiel #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) == []
Beispiel #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) == []
Beispiel #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)
Beispiel #22
0
def test_HTTPMove_location_newlines():
    with pytest.raises(ValueError):
        webob_exc._HTTPMove(location="http://example.com\r\nX-Test: false")
Beispiel #23
0
def test_HTTPMove_location_newlines():
    with pytest.raises(ValueError):
        webob_exc._HTTPMove(location="http://example.com\r\nX-Test: false")
Beispiel #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)