当前位置: 首页>>代码示例>>Python>>正文


Python tutils.treq函数代码示例

本文整理汇总了Python中netlib.tutils.treq函数的典型用法代码示例。如果您正苦于以下问题:Python treq函数的具体用法?Python treq怎么用?Python treq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了treq函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_assemble_request_headers

def test_assemble_request_headers():
    # https://github.com/mitmproxy/mitmproxy/issues/186
    r = treq(body=b"")
    r.headers[b"Transfer-Encoding"] = b"chunked"
    c = _assemble_request_headers(r)
    assert b"Transfer-Encoding" in c

    assert b"Host" in _assemble_request_headers(treq(headers=Headers()))
开发者ID:pombredanne,项目名称:netlib,代码行数:8,代码来源:test_assemble.py

示例2: test_equal

    def test_equal(self):
        a = tutils.treq(timestamp_start=42, timestamp_end=43)
        b = tutils.treq(timestamp_start=42, timestamp_end=43)
        assert a == b

        assert not a == 'foo'
        assert not b == 'foo'
        assert not 'foo' == a
        assert not 'foo' == b
开发者ID:pombredanne,项目名称:netlib,代码行数:9,代码来源:test_models.py

示例3: test_equal

    def test_equal(self):
        a = tutils.treq()
        b = tutils.treq()
        assert a == b

        assert not a == 'foo'
        assert not b == 'foo'
        assert not 'foo' == a
        assert not 'foo' == b
开发者ID:fireswood,项目名称:netlib,代码行数:9,代码来源:test_semantics.py

示例4: test_get_form_with_url_encoded

    def test_get_form_with_url_encoded(self, mock_method_urlencoded, mock_method_multipart):
        req = tutils.treq()
        assert req.get_form() == ODict()

        req = tutils.treq()
        req.body = "foobar"
        req.headers["Content-Type"] = HDR_FORM_URLENCODED
        req.get_form()
        assert req.get_form_urlencoded.called
        assert not req.get_form_multipart.called
开发者ID:pombredanne,项目名称:netlib,代码行数:10,代码来源:test_models.py

示例5: test_assemble_request_line

def test_assemble_request_line():
    assert _assemble_request_line(treq().data) == b"GET /path HTTP/1.1"

    authority_request = treq(method=b"CONNECT", first_line_format="authority").data
    assert _assemble_request_line(authority_request) == b"CONNECT address:22 HTTP/1.1"

    absolute_request = treq(first_line_format="absolute").data
    assert _assemble_request_line(absolute_request) == b"GET http://address:22/path HTTP/1.1"

    with raises(RuntimeError):
        _assemble_request_line(treq(first_line_format="invalid_form").data)
开发者ID:tempbottle,项目名称:netlib,代码行数:11,代码来源:test_assemble.py

示例6: test_assemble_request

def test_assemble_request():
    assert assemble_request(treq()) == (
        b"GET /path HTTP/1.1\r\n"
        b"header: qvalue\r\n"
        b"content-length: 7\r\n"
        b"host: address:22\r\n"
        b"\r\n"
        b"content"
    )

    with raises(HttpException):
        assemble_request(treq(content=None))
开发者ID:thomasbhatia,项目名称:mitmproxy,代码行数:12,代码来源:test_assemble.py

示例7: test_assemble_request

def test_assemble_request():
    c = assemble_request(treq()) == (
        b"GET /path HTTP/1.1\r\n"
        b"header: qvalue\r\n"
        b"Host: address:22\r\n"
        b"Content-Length: 7\r\n"
        b"\r\n"
        b"content"
    )

    with raises(HttpException):
        assemble_request(treq(content=CONTENT_MISSING))
开发者ID:tempbottle,项目名称:netlib,代码行数:12,代码来源:test_assemble.py

示例8: test_har_extractor

def test_har_extractor(log):
    if sys.version_info >= (3, 0):
        with tutils.raises("does not work on Python 3"):
            with example("har_extractor.py -"):
                pass
        return

    with tutils.raises(script.ScriptException):
        with example("har_extractor.py"):
            pass

    times = dict(
        timestamp_start=746203272,
        timestamp_end=746203272,
    )

    flow = tutils.tflow(
        req=netutils.treq(**times),
        resp=netutils.tresp(**times)
    )

    with example("har_extractor.py -") as ex:
        ex.run("response", flow)

        with open(tutils.test_data.path("data/har_extractor.har")) as fp:
            test_data = json.load(fp)
            assert json.loads(ex.ns["context"].HARLog.json()) == test_data["test_response"]
开发者ID:christofferqa,项目名称:mitmproxy,代码行数:27,代码来源:test_examples.py

示例9: test_anticache

 def test_anticache(self):
     req = tutils.treq()
     req.headers.add("If-Modified-Since", "foo")
     req.headers.add("If-None-Match", "bar")
     req.anticache()
     assert "If-Modified-Since" not in req.headers
     assert "If-None-Match" not in req.headers
开发者ID:gsilverman-memeo-inc,项目名称:netlib,代码行数:7,代码来源:test_semantics.py

示例10: test_set_cookies

 def test_set_cookies(self):
     r = tutils.treq()
     r.headers = Headers(cookie="cookiename=cookievalue")
     result = r.get_cookies()
     result["cookiename"] = ["foo"]
     r.set_cookies(result)
     assert r.get_cookies()["cookiename"] == ["foo"]
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py

示例11: test_get_cookies_withequalsign

 def test_get_cookies_withequalsign(self):
     r = tutils.treq()
     r.headers = Headers(cookie="cookiename=coo=kievalue;othercookiename=othercookievalue")
     result = r.get_cookies()
     assert len(result) == 2
     assert result['cookiename'] == ['coo=kievalue']
     assert result['othercookiename'] == ['othercookievalue']
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py

示例12: test_get_cookies_double

 def test_get_cookies_double(self):
     request = treq()
     request.headers = Headers(cookie="cookiename=cookievalue;othercookiename=othercookievalue")
     result = request.cookies
     assert len(result) == 2
     assert result['cookiename'] == 'cookievalue'
     assert result['othercookiename'] == 'othercookievalue'
开发者ID:AlTune,项目名称:mitmproxy,代码行数:7,代码来源:test_request.py

示例13: test_read_response

def test_read_response():
    req = treq()
    rfile = BytesIO(b"HTTP/1.1 418 I'm a teapot\r\n\r\nbody")
    r = read_response(rfile, req)
    assert r.status_code == 418
    assert r.content == b"body"
    assert r.timestamp_end
开发者ID:007durgesh219,项目名称:mitmproxy,代码行数:7,代码来源:test_read.py

示例14: test_legacy_first_line

    def test_legacy_first_line(self):
        req = tutils.treq()

        assert req.legacy_first_line('relative') == "GET /path HTTP/1.1"
        assert req.legacy_first_line('authority') == "GET address:22 HTTP/1.1"
        assert req.legacy_first_line('absolute') == "GET http://address:22/path HTTP/1.1"
        tutils.raises(http.HttpError, req.legacy_first_line, 'foobar')
开发者ID:fireswood,项目名称:netlib,代码行数:7,代码来源:test_semantics.py

示例15: test_get_form_with_multipart

 def test_get_form_with_multipart(self, mock_method_urlencoded, mock_method_multipart):
     req = tutils.treq()
     req.body = "foobar"
     req.headers["Content-Type"] = HDR_FORM_MULTIPART
     req.get_form()
     assert not req.get_form_urlencoded.called
     assert req.get_form_multipart.called
开发者ID:pombredanne,项目名称:netlib,代码行数:7,代码来源:test_models.py


注:本文中的netlib.tutils.treq函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。