コード例 #1
0
ファイル: test_services.py プロジェクト: mredar/akara
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)
コード例 #2
0
ファイル: test_services.py プロジェクト: dpla/akara
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)
コード例 #3
0
ファイル: test_services.py プロジェクト: dpla/akara
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
コード例 #4
0
ファイル: test_services.py プロジェクト: mredar/akara
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
コード例 #5
0
ファイル: test_services.py プロジェクト: dpla/akara
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
コード例 #6
0
ファイル: test_services.py プロジェクト: dpla/akara
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)
コード例 #7
0
ファイル: test_services.py プロジェクト: mredar/akara
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
コード例 #8
0
ファイル: test_services.py プロジェクト: mredar/akara
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)
コード例 #9
0
ファイル: test_services.py プロジェクト: mredar/akara
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)
コード例 #10
0
ファイル: test_services.py プロジェクト: dpla/akara
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)
コード例 #11
0
ファイル: test_services.py プロジェクト: mredar/akara
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
コード例 #12
0
ファイル: test_services.py プロジェクト: mredar/akara
def test_good_path():
    h = httplib_server()
    h.request("GET", "/")
    r = h.getresponse()
    assert r.status == 200, r.status
コード例 #13
0
ファイル: test_services.py プロジェクト: dpla/akara
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
コード例 #14
0
ファイル: test_services.py プロジェクト: dpla/akara
def test_good_path():
    h = httplib_server()
    h.request("GET", "/")
    r = h.getresponse()
    assert r.status == 200, r.status