2021-05-27 19:30:36 +02:00
|
|
|
import socket
|
2021-09-23 10:37:23 +02:00
|
|
|
|
2016-03-06 10:42:35 +01:00
|
|
|
import pytest
|
2018-06-09 11:59:34 +02:00
|
|
|
from pytest_httpbin import certs
|
2016-03-06 10:42:35 +01:00
|
|
|
|
2022-02-01 10:14:24 +01:00
|
|
|
from .utils import ( # noqa
|
|
|
|
HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN,
|
|
|
|
HTTPBIN_WITH_CHUNKED_SUPPORT,
|
2022-04-14 16:42:05 +02:00
|
|
|
REMOTE_HTTPBIN_DOMAIN,
|
2022-04-28 14:18:20 +02:00
|
|
|
IS_PYOPENSSL,
|
2022-02-01 10:14:24 +01:00
|
|
|
mock_env
|
|
|
|
)
|
2021-11-30 09:12:51 +01:00
|
|
|
from .utils.plugins_cli import ( # noqa
|
2021-12-08 16:45:07 +01:00
|
|
|
broken_plugin,
|
2021-11-30 09:12:51 +01:00
|
|
|
dummy_plugin,
|
|
|
|
dummy_plugins,
|
|
|
|
httpie_plugins,
|
|
|
|
httpie_plugins_success,
|
|
|
|
interface,
|
|
|
|
)
|
2022-04-14 16:42:05 +02:00
|
|
|
from .utils.http_server import http_server, localhost_http_server # noqa
|
2021-05-27 19:30:36 +02:00
|
|
|
|
2016-03-06 10:42:35 +01:00
|
|
|
|
2018-06-09 11:59:34 +02:00
|
|
|
@pytest.fixture(scope='function', autouse=True)
|
|
|
|
def httpbin_add_ca_bundle(monkeypatch):
|
|
|
|
"""
|
|
|
|
Make pytest-httpbin's CA trusted by default.
|
|
|
|
|
|
|
|
(Same as `httpbin_ca_bundle`, just auto-used.).
|
|
|
|
|
|
|
|
"""
|
|
|
|
monkeypatch.setenv('REQUESTS_CA_BUNDLE', certs.where())
|
2016-03-06 10:42:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def httpbin_secure_untrusted(monkeypatch, httpbin_secure):
|
2018-06-09 11:59:34 +02:00
|
|
|
"""
|
|
|
|
Like the `httpbin_secure` fixture, but without the
|
|
|
|
make-CA-trusted-by-default.
|
|
|
|
|
|
|
|
"""
|
2016-03-06 10:42:35 +01:00
|
|
|
monkeypatch.delenv('REQUESTS_CA_BUNDLE')
|
|
|
|
return httpbin_secure
|
2021-05-27 19:30:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def _httpbin_with_chunked_support_available():
|
|
|
|
try:
|
|
|
|
socket.gethostbyname(HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN)
|
|
|
|
return True
|
|
|
|
except OSError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def httpbin_with_chunked_support(_httpbin_with_chunked_support_available):
|
|
|
|
if _httpbin_with_chunked_support_available:
|
|
|
|
return HTTPBIN_WITH_CHUNKED_SUPPORT
|
2021-05-29 12:06:06 +02:00
|
|
|
pytest.skip(f'{HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN} not resolvable')
|
2021-09-23 10:37:23 +02:00
|
|
|
|
|
|
|
|
2022-04-14 16:42:05 +02:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def _remote_httpbin_available():
|
|
|
|
try:
|
|
|
|
socket.gethostbyname(REMOTE_HTTPBIN_DOMAIN)
|
|
|
|
return True
|
|
|
|
except OSError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def remote_httpbin(_remote_httpbin_available):
|
|
|
|
if _remote_httpbin_available:
|
|
|
|
return 'http://' + REMOTE_HTTPBIN_DOMAIN
|
|
|
|
pytest.skip(f'{REMOTE_HTTPBIN_DOMAIN} not resolvable')
|
|
|
|
|
|
|
|
|
2021-09-23 10:37:23 +02:00
|
|
|
@pytest.fixture(autouse=True, scope='session')
|
|
|
|
def pyopenssl_inject():
|
|
|
|
"""
|
|
|
|
Injects `pyOpenSSL` module to make sure `requests` will use it.
|
|
|
|
<https://github.com/psf/requests/pull/5443#issuecomment-645740394>
|
|
|
|
"""
|
2022-04-28 14:18:20 +02:00
|
|
|
if IS_PYOPENSSL:
|
2021-09-23 10:37:23 +02:00
|
|
|
try:
|
|
|
|
import urllib3.contrib.pyopenssl
|
|
|
|
urllib3.contrib.pyopenssl.inject_into_urllib3()
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
pytest.fail('Missing "pyopenssl" module.')
|
|
|
|
|
|
|
|
yield
|