)
from httpx._content_streams import ContentStream, JSONStream
+from ..common import FIXTURES_DIR
+
def get_header_value(headers, key, default=None):
lookup = key.encode("ascii").lower()
@pytest.mark.asyncio
async def test_netrc_auth() -> None:
- os.environ["NETRC"] = "tests/.netrc"
+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")
url = "http://netrcexample.org"
client = AsyncClient(transport=AsyncMockTransport())
@pytest.mark.asyncio
async def test_auth_header_has_priority_over_netrc() -> None:
- os.environ["NETRC"] = "tests/.netrc"
+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")
url = "http://netrcexample.org"
client = AsyncClient(transport=AsyncMockTransport())
@pytest.mark.asyncio
async def test_trust_env_auth() -> None:
- os.environ["NETRC"] = "tests/.netrc"
+ os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")
url = "http://netrcexample.org"
client = AsyncClient(transport=AsyncMockTransport(), trust_env=False)
)
from tests.utils import override_log_level
+from .common import FIXTURES_DIR, TESTS_DIR
+
@pytest.mark.parametrize(
"encoding",
def test_bad_get_netrc_login():
- netrc_info = NetRCInfo(["tests/does-not-exist"])
+ netrc_info = NetRCInfo([str(FIXTURES_DIR / "does-not-exist")])
assert netrc_info.get_credentials("netrcexample.org") is None
def test_get_netrc_login():
- netrc_info = NetRCInfo(["tests/.netrc"])
+ netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")])
expected_credentials = (
"example-username",
"example-password",
def test_get_netrc_unknown():
- netrc_info = NetRCInfo(["tests/.netrc"])
+ netrc_info = NetRCInfo([str(FIXTURES_DIR / ".netrc")])
assert netrc_info.get_credentials("nonexistant.org") is None
# Two environments is not set.
assert get_ca_bundle_from_env() is None
- os.environ["SSL_CERT_DIR"] = "tests/"
+ os.environ["SSL_CERT_DIR"] = str(TESTS_DIR)
# SSL_CERT_DIR is correctly set, SSL_CERT_FILE is not set.
- assert get_ca_bundle_from_env() == "tests"
+ ca_bundle = get_ca_bundle_from_env()
+ assert ca_bundle is not None and ca_bundle.endswith("tests")
del os.environ["SSL_CERT_DIR"]
- os.environ["SSL_CERT_FILE"] = "tests/test_utils.py"
+ os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py")
# SSL_CERT_FILE is correctly set, SSL_CERT_DIR is not set.
- assert get_ca_bundle_from_env() == "tests/test_utils.py"
+ ca_bundle = get_ca_bundle_from_env()
+ assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py")
os.environ["SSL_CERT_FILE"] = "wrongfile"
# SSL_CERT_FILE is set with wrong file, SSL_CERT_DIR is not set.
# SSL_CERT_DIR is set with wrong path, SSL_CERT_FILE is not set.
assert get_ca_bundle_from_env() is None
- os.environ["SSL_CERT_DIR"] = "tests/"
- os.environ["SSL_CERT_FILE"] = "tests/test_utils.py"
+ os.environ["SSL_CERT_DIR"] = str(TESTS_DIR)
+ os.environ["SSL_CERT_FILE"] = str(TESTS_DIR / "test_utils.py")
# Two environments is correctly set.
- assert get_ca_bundle_from_env() == "tests/test_utils.py"
+ ca_bundle = get_ca_bundle_from_env()
+ assert ca_bundle is not None and ca_bundle.endswith("tests/test_utils.py")
os.environ["SSL_CERT_FILE"] = "wrongfile"
# Two environments is set but SSL_CERT_FILE is not a file.
- assert get_ca_bundle_from_env() == "tests"
+ ca_bundle = get_ca_bundle_from_env()
+ assert ca_bundle is not None and ca_bundle.endswith("tests")
os.environ["SSL_CERT_DIR"] = "wrongpath"
# Two environments is set but both are not correct.