Exemplo n.º 1
0
def test_linkcheck_request_headers_default(app, capsys):
    with http_server(HeadersDumperHandler):
        app.builder.build_all()

    stdout, _stderr = capsys.readouterr()
    assert "Accepts: application/json\n" not in stdout
    assert "X-Secret: open sesami\n" in stdout
Exemplo n.º 2
0
def init(host='localhost',port=port,on_init=None) : 
    global ws 
    global http_thread 
    http_thread = u.http_server(9005,get_handler) 
    log.i("Initializing...") 
    if on_init : 
        on_init() 
Exemplo n.º 3
0
def test_linkcheck_request_headers(app, capsys):
    with http_server(HeadersDumperHandler):
        app.builder.build_all()

    stdout, _stderr = capsys.readouterr()
    assert "Accept: text/html\n" in stdout
    assert "X-Secret" not in stdout
    assert "sesami" not in stdout
Exemplo n.º 4
0
def test_raises_for_invalid_status(app):
    class InternalServerErrorHandler(http.server.BaseHTTPRequestHandler):
        def do_GET(self):
            self.send_error(500, "Internal Server Error")

    with http_server(InternalServerErrorHandler):
        app.builder.build_all()
    content = (app.outdir / 'output.txt').read_text()
    assert content == ("index.rst:1: [broken] http://localhost:7777/#anchor: "
                       "500 Server Error: Internal Server Error "
                       "for url: http://localhost:7777/\n")
Exemplo n.º 5
0
def test_invalid_ssl(app):
    # Link indicates SSL should be used (https) but the server does not handle it.
    with http_server(OKHandler):
        app.builder.build_all()

    with open(app.outdir / 'output.json') as fp:
        content = json.load(fp)
    assert content["status"] == "broken"
    assert content["filename"] == "index.rst"
    assert content["lineno"] == 1
    assert content["uri"] == "https://localhost:7777/"
    assert "SSLError" in content["info"]
Exemplo n.º 6
0
def test_follows_redirects_on_HEAD(app, capsys):
    with http_server(make_redirect_handler(support_head=True)):
        app.builder.build_all()
    stdout, stderr = capsys.readouterr()
    content = (app.outdir / 'output.txt').read_text()
    assert content == (
        "index.rst:1: [redirected with Found] "
        "http://localhost:7777/ to http://localhost:7777/?redirected=1\n"
    )
    assert stderr == textwrap.dedent(
        """\
        127.0.0.1 - - [] "HEAD / HTTP/1.1" 302 -
        127.0.0.1 - - [] "HEAD /?redirected=1 HTTP/1.1" 204 -
        """
    )
Exemplo n.º 7
0
def test_inspect_main_url(capsys):
    """inspect_main interface, with url argument"""
    class InventoryHandler(http.server.BaseHTTPRequestHandler):
        def do_GET(self):
            self.send_response(200, "OK")
            self.end_headers()
            self.wfile.write(inventory_v2)

        def log_message(*args, **kwargs):
            # Silenced.
            pass

    url = 'http://localhost:7777/' + INVENTORY_FILENAME

    with http_server(InventoryHandler):
        inspect_main([url])

    stdout, stderr = capsys.readouterr()
    assert stdout.startswith("c:function\n")
    assert stderr == ""
Exemplo n.º 8
0
def test_auth_header_no_match(app, capsys):
    with http_server(HeadersDumperHandler):
        app.builder.build_all()
    stdout, stderr = capsys.readouterr()
    assert "Authorization" not in stdout
Exemplo n.º 9
0
def test_auth_header_uses_first_match(app, capsys):
    with http_server(HeadersDumperHandler):
        app.builder.build_all()
    stdout, stderr = capsys.readouterr()
    auth = requests.auth._basic_auth_str('user1', 'password')
    assert "Authorization: %s\n" % auth in stdout