Use relative tests directory references (#1052)
* Use relative tests directory references * Use absolute TESTS_DIR Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
parent
ff93a011a4
commit
09672a99dd
@ -18,6 +18,8 @@ from httpx import (
|
||||
)
|
||||
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()
|
||||
@ -233,7 +235,7 @@ async def test_custom_auth() -> None:
|
||||
|
||||
@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())
|
||||
@ -247,7 +249,7 @@ async def test_netrc_auth() -> None:
|
||||
|
||||
@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())
|
||||
@ -259,7 +261,7 @@ async def test_auth_header_has_priority_over_netrc() -> None:
|
||||
|
||||
@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)
|
||||
|
||||
4
tests/common.py
Normal file
4
tests/common.py
Normal file
@ -0,0 +1,4 @@
|
||||
import pathlib
|
||||
|
||||
TESTS_DIR = pathlib.Path(__file__).parent
|
||||
FIXTURES_DIR = TESTS_DIR / "fixtures"
|
||||
0
tests/.netrc → tests/fixtures/.netrc
vendored
0
tests/.netrc → tests/fixtures/.netrc
vendored
@ -16,6 +16,8 @@ from httpx._utils import (
|
||||
)
|
||||
from tests.utils import override_log_level
|
||||
|
||||
from .common import FIXTURES_DIR, TESTS_DIR
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"encoding",
|
||||
@ -54,12 +56,12 @@ def test_guess_by_bom(encoding, expected):
|
||||
|
||||
|
||||
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",
|
||||
@ -68,7 +70,7 @@ def test_get_netrc_login():
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -137,14 +139,16 @@ def test_get_ssl_cert_file():
|
||||
# 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.
|
||||
@ -155,14 +159,16 @@ def test_get_ssl_cert_file():
|
||||
# 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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user