當前位置: 首頁>>代碼示例>>Python>>正文


Python requests_unixsocket.monkeypatch方法代碼示例

本文整理匯總了Python中requests_unixsocket.monkeypatch方法的典型用法代碼示例。如果您正苦於以下問題:Python requests_unixsocket.monkeypatch方法的具體用法?Python requests_unixsocket.monkeypatch怎麽用?Python requests_unixsocket.monkeypatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests_unixsocket的用法示例。


在下文中一共展示了requests_unixsocket.monkeypatch方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_peercreds_unix_sock

# 需要導入模塊: import requests_unixsocket [as 別名]
# 或者: from requests_unixsocket import monkeypatch [as 別名]
def test_peercreds_unix_sock(peercreds_enabled_server):
    """Check that ``PEERCRED`` lookup works when enabled."""
    httpserver = peercreds_enabled_server
    bind_addr = httpserver.bind_addr

    if isinstance(bind_addr, six.binary_type):
        bind_addr = bind_addr.decode()

    quoted = urllib.parse.quote(bind_addr, safe='')
    unix_base_uri = 'http+unix://{quoted}'.format(**locals())

    expected_peercreds = os.getpid(), os.getuid(), os.getgid()
    expected_peercreds = '|'.join(map(str, expected_peercreds))

    with requests_unixsocket.monkeypatch():
        peercreds_resp = requests.get(unix_base_uri + PEERCRED_IDS_URI)
        peercreds_resp.raise_for_status()
        assert peercreds_resp.text == expected_peercreds

        peercreds_text_resp = requests.get(unix_base_uri + PEERCRED_TEXTS_URI)
        assert peercreds_text_resp.status_code == 500 
開發者ID:cherrypy,項目名稱:cheroot,代碼行數:23,代碼來源:test_server.py

示例2: test_peercreds_unix_sock_with_lookup

# 需要導入模塊: import requests_unixsocket [as 別名]
# 或者: from requests_unixsocket import monkeypatch [as 別名]
def test_peercreds_unix_sock_with_lookup(peercreds_enabled_server):
    """Check that ``PEERCRED`` resolution works when enabled."""
    httpserver = peercreds_enabled_server
    httpserver.peercreds_resolve_enabled = True

    bind_addr = httpserver.bind_addr

    if isinstance(bind_addr, six.binary_type):
        bind_addr = bind_addr.decode()

    quoted = urllib.parse.quote(bind_addr, safe='')
    unix_base_uri = 'http+unix://{quoted}'.format(**locals())

    import grp
    import pwd
    expected_textcreds = (
        pwd.getpwuid(os.getuid()).pw_name,
        grp.getgrgid(os.getgid()).gr_name,
    )
    expected_textcreds = '!'.join(map(str, expected_textcreds))
    with requests_unixsocket.monkeypatch():
        peercreds_text_resp = requests.get(unix_base_uri + PEERCRED_TEXTS_URI)
        peercreds_text_resp.raise_for_status()
        assert peercreds_text_resp.text == expected_textcreds 
開發者ID:cherrypy,項目名稱:cheroot,代碼行數:26,代碼來源:test_server.py

示例3: test_peercreds_unix_sock

# 需要導入模塊: import requests_unixsocket [as 別名]
# 或者: from requests_unixsocket import monkeypatch [as 別名]
def test_peercreds_unix_sock(peercreds_enabled_server_and_client):
    """Check that peercred lookup works when enabled."""
    httpserver, testclient = peercreds_enabled_server_and_client
    bind_addr = httpserver.bind_addr

    if isinstance(bind_addr, six.binary_type):
        bind_addr = bind_addr.decode()

    unix_base_uri = 'http+unix://{}'.format(
        bind_addr.replace('\0', '%00').replace('/', '%2F'),
    )

    expected_peercreds = os.getpid(), os.getuid(), os.getgid()
    expected_peercreds = '|'.join(map(str, expected_peercreds))

    with requests_unixsocket.monkeypatch():
        peercreds_resp = requests.get(unix_base_uri + PEERCRED_IDS_URI)
        peercreds_resp.raise_for_status()
        assert peercreds_resp.text == expected_peercreds

        peercreds_text_resp = requests.get(unix_base_uri + PEERCRED_TEXTS_URI)
        assert peercreds_text_resp.status_code == 500 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:24,代碼來源:test_server.py

示例4: test_peercreds_unix_sock_with_lookup

# 需要導入模塊: import requests_unixsocket [as 別名]
# 或者: from requests_unixsocket import monkeypatch [as 別名]
def test_peercreds_unix_sock_with_lookup(peercreds_enabled_server_and_client):
    """Check that peercred resolution works when enabled."""
    httpserver, testclient = peercreds_enabled_server_and_client
    httpserver.peercreds_resolve_enabled = True

    bind_addr = httpserver.bind_addr

    if isinstance(bind_addr, six.binary_type):
        bind_addr = bind_addr.decode()

    unix_base_uri = 'http+unix://{}'.format(
        bind_addr.replace('\0', '%00').replace('/', '%2F'),
    )

    import grp
    import pwd
    expected_textcreds = (
        pwd.getpwuid(os.getuid()).pw_name,
        grp.getgrgid(os.getgid()).gr_name,
    )
    expected_textcreds = '!'.join(map(str, expected_textcreds))
    with requests_unixsocket.monkeypatch():
        peercreds_text_resp = requests.get(unix_base_uri + PEERCRED_TEXTS_URI)
        peercreds_text_resp.raise_for_status()
        assert peercreds_text_resp.text == expected_textcreds 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:27,代碼來源:test_server.py

示例5: test_unix_domain_adapter_monkeypatch

# 需要導入模塊: import requests_unixsocket [as 別名]
# 或者: from requests_unixsocket import monkeypatch [as 別名]
def test_unix_domain_adapter_monkeypatch():
    with UnixSocketServerThread() as usock_thread:
        with requests_unixsocket.monkeypatch('http+unix://'):
            urlencoded_usock = requests.compat.quote_plus(usock_thread.usock)
            url = 'http+unix://%s/path/to/page' % urlencoded_usock

            for method in ['get', 'post', 'head', 'patch', 'put', 'delete',
                           'options']:
                logger.debug('Calling session.%s(%r) ...', method, url)
                r = getattr(requests, method)(url)
                logger.debug(
                    'Received response: %r with text: %r and headers: %r',
                    r, r.text, r.headers)
                assert r.status_code == 200
                assert r.headers['server'] == 'waitress'
                assert r.headers['X-Transport'] == 'unix domain socket'
                assert r.headers['X-Requested-Path'] == '/path/to/page'
                assert r.headers['X-Socket-Path'] == usock_thread.usock
                assert isinstance(r.connection,
                                  requests_unixsocket.UnixAdapter)
                assert r.url.lower() == url.lower()
                if method == 'head':
                    assert r.text == ''
                else:
                    assert r.text == 'Hello world!'

    for method in ['get', 'post', 'head', 'patch', 'put', 'delete', 'options']:
        with pytest.raises(requests.exceptions.InvalidSchema):
            getattr(requests, method)(url) 
開發者ID:msabramo,項目名稱:requests-unixsocket,代碼行數:31,代碼來源:test_requests_unixsocket.py


注:本文中的requests_unixsocket.monkeypatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。