Example #1
0
def test_multimethod_teapot():
    h = httplib_server()
    h.request("TEAPOT", "/test_multimethod")
    r = h.getresponse()
    assert r.status == 418, r.status
    s = r.read()
    assert s == "short and stout", repr(s)
Example #2
0
def test_multimethod_teapot():
    h = httplib_server()
    h.request("TEAPOT", "/test_multimethod")
    r = h.getresponse()
    assert r.status == 418, r.status
    s = r.read()
    assert s == "short and stout", repr(s)
Example #3
0
def test_echo_simple_post_missing_content_length():
    # First, make sure I can call it
    h = httplib_server()
    h.request("POST", "/test_echo_simple_post", "Body",
              {"Content-Length": 4, "Content-Type": "text/plain"})
    r = h.getresponse()
    assert r.status == 200, r.status

    # Try again, this time without a Content-Length
    # (The only way to do that with httplib is to use Content-Length of None)
    h = httplib_server()
    h.request("POST", "/test_echo_simple_post", "Body",
              {"Content-Length": None, "Content-Type": "text/plain"})
    r = h.getresponse()
    # 411 is "Length Required"
    assert r.status == 411, r.status
Example #4
0
def test_multimethod_unknown():
    h = httplib_server()
    # This one isn't supported on the server
    h.request("COFFEEPOT", "/test_multimethod")
    r = h.getresponse()
    assert r.status == 405, r.status
    accept = r.getheader("Allow")
    terms = [s.strip() for s in accept.split(",")]
    terms.sort()
    assert terms == ["DELETE", "GET", "HEAD", "POST", "TEAPOT"], terms
Example #5
0
def test_multimethod_unknown():
    h = httplib_server()
    # This one isn't supported on the server
    h.request("COFFEEPOT", "/test_multimethod")
    r = h.getresponse()
    assert r.status == 405, r.status
    accept = r.getheader("Allow")
    terms = [s.strip() for s in accept.split(",")]
    terms.sort()
    assert terms == ["DELETE", "GET", "HEAD", "POST", "TEAPOT"], terms
Example #6
0
def test_multimethod_delete():
    h = httplib_server()
    h.request("DELETE", "/test_multimethod", "[U235]",
              {"Content-Length": 6, "Content-Type": "chemical/x-daylight-smiles"})
    r = h.getresponse()
    assert r.status == 202, r.status

    s = r.read()
    assert s == ('<?xml version="1.0" encoding="utf-8"?>\n'
                 '<nothing city="G\xc3\xb6teborg" name="\xc3\x85sa"><something/></nothing>'), repr(s)
Example #7
0
def test_echo_simple_post_missing_content_length():
    # First, make sure I can call it
    h = httplib_server()
    h.request("POST", "/test_echo_simple_post", "Body", {
        "Content-Length": 4,
        "Content-Type": "text/plain"
    })
    r = h.getresponse()
    assert r.status == 200, r.status

    # Try again, this time without a Content-Length
    # (The only way to do that with httplib is to use Content-Length of None)
    h = httplib_server()
    h.request("POST", "/test_echo_simple_post", "Body", {
        "Content-Length": None,
        "Content-Type": "text/plain"
    })
    r = h.getresponse()
    # 411 is "Length Required"
    assert r.status == 411, r.status
Example #8
0
def test_multimethod_delete():
    h = httplib_server()
    h.request("DELETE", "/test_multimethod", "[U235]", {
        "Content-Length": 6,
        "Content-Type": "chemical/x-daylight-smiles"
    })
    r = h.getresponse()
    assert r.status == 202, r.status

    s = r.read()
    assert s == (
        '<?xml version="1.0" encoding="utf-8"?>\n'
        '<nothing city="G\xc3\xb6teborg" name="\xc3\x85sa"><something/></nothing>'
    ), repr(s)
Example #9
0
def test_head_vs_get():
    h = httplib_server()
    h.request("GET", "/test_add_headers")
    r = h.getresponse()
    assert r.status == 200, r.status
    get_headers = r.getheaders()
    content_length = r.getheader("content-length")
    assert content_length == "33", content_length
    get_body = r.read()
    assert len(get_body) == 33, (get_body, content_length)

    h.request("HEAD", "/test_add_headers")
    r = h.getresponse()
    assert r.status == 200, r.status
    head_headers = r.getheaders()
    head_body = r.read()
    assert head_body == "", head_body

    assert get_headers == head_headers, (get_headers, head_headers)
Example #10
0
def test_head_vs_get():
    h = httplib_server()
    h.request("GET", "/test_add_headers")
    r = h.getresponse()
    assert r.status == 200, r.status
    get_headers = r.getheaders()
    content_length = r.getheader("content-length")
    assert content_length == "33", content_length
    get_body = r.read()
    assert len(get_body) == 33, (get_body, content_length)

    h.request("HEAD", "/test_add_headers")
    r = h.getresponse()
    assert r.status == 200, r.status
    head_headers = r.getheaders()
    head_body = r.read()
    assert head_body == "", head_body

    assert get_headers == head_headers, (get_headers, head_headers)
Example #11
0
def test_bad_path():
    h = httplib_server()
    # the request is missing the leading '/'
    h.request("GET", "missing_slash")
    r = h.getresponse()
    assert r.status == 400, r.status
Example #12
0
def test_good_path():
    h = httplib_server()
    h.request("GET", "/")
    r = h.getresponse()
    assert r.status == 200, r.status
Example #13
0
def test_bad_path():
    h = httplib_server()
    # the request is missing the leading '/'
    h.request("GET", "missing_slash")
    r = h.getresponse()
    assert r.status == 400, r.status
Example #14
0
def test_good_path():
    h = httplib_server()
    h.request("GET", "/")
    r = h.getresponse()
    assert r.status == 200, r.status