diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d62e67aa..a53ed54d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: - "3.10" - "3.11" - "3.12" + - "3.13" - "pypy-3.8" - "pypy-3.9" - "pypy-3.10" @@ -48,6 +49,7 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: pip + allow-prereleases: true - name: Install project dependencies run: | diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py deleted file mode 100644 index 05908e51..00000000 --- a/tests/integration/conftest.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import ssl - -import pytest - - -@pytest.fixture -def httpbin_ssl_context(): - ssl_ca_location = os.environ["REQUESTS_CA_BUNDLE"] - ssl_cert_location = os.environ["REQUESTS_CA_BUNDLE"].replace("cacert.pem", "cert.pem") - ssl_key_location = os.environ["REQUESTS_CA_BUNDLE"].replace("cacert.pem", "key.pem") - - ssl_context = ssl.create_default_context(cafile=ssl_ca_location) - ssl_context.load_cert_chain(ssl_cert_location, ssl_key_location) - - return ssl_context diff --git a/tests/integration/test_aiohttp.py b/tests/integration/test_aiohttp.py index 7bf5d771..97a489b8 100644 --- a/tests/integration/test_aiohttp.py +++ b/tests/integration/test_aiohttp.py @@ -1,7 +1,9 @@ import logging +import ssl import urllib.parse import pytest +import pytest_httpbin.certs import vcr @@ -11,6 +13,8 @@ from .aiohttp_utils import aiohttp_app, aiohttp_request # noqa: E402 +HTTPBIN_SSL_CONTEXT = ssl.create_default_context(cafile=pytest_httpbin.certs.where()) + def run_in_loop(fn): async def wrapper(): @@ -338,7 +342,7 @@ def test_double_requests(tmpdir, httpbin): assert cassette.play_count == 2 -def test_cookies(httpbin_both, httpbin_ssl_context, tmpdir): +def test_cookies(httpbin_both, tmpdir): async def run(loop): cookies_url = httpbin_both.url + ( "/response-headers?" @@ -353,12 +357,12 @@ async def run(loop): # ------------------------- Record -------------------------- # with vcr.use_cassette(tmp) as cassette: async with aiohttp.ClientSession(loop=loop, cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: - cookies_resp = await session.get(cookies_url, ssl=httpbin_ssl_context) + cookies_resp = await session.get(cookies_url, ssl=HTTPBIN_SSL_CONTEXT) home_resp = await session.get( home_url, cookies=req_cookies, headers=req_headers, - ssl=httpbin_ssl_context, + ssl=HTTPBIN_SSL_CONTEXT, ) assert cassette.play_count == 0 assert_responses(cookies_resp, home_resp) @@ -366,12 +370,12 @@ async def run(loop): # -------------------------- Play --------------------------- # with vcr.use_cassette(tmp, record_mode=vcr.mode.NONE) as cassette: async with aiohttp.ClientSession(loop=loop, cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: - cookies_resp = await session.get(cookies_url, ssl=httpbin_ssl_context) + cookies_resp = await session.get(cookies_url, ssl=HTTPBIN_SSL_CONTEXT) home_resp = await session.get( home_url, cookies=req_cookies, headers=req_headers, - ssl=httpbin_ssl_context, + ssl=HTTPBIN_SSL_CONTEXT, ) assert cassette.play_count == 2 assert_responses(cookies_resp, home_resp) @@ -388,7 +392,7 @@ def assert_responses(cookies_resp, home_resp): run_in_loop(run) -def test_cookies_redirect(httpbin_both, httpbin_ssl_context, tmpdir): +def test_cookies_redirect(httpbin_both, tmpdir): async def run(loop): # Sets cookie as provided by the query string and redirects cookies_url = httpbin_both.url + "/cookies/set?Cookie_1=Val_1" @@ -397,7 +401,7 @@ async def run(loop): # ------------------------- Record -------------------------- # with vcr.use_cassette(tmp) as cassette: async with aiohttp.ClientSession(loop=loop, cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: - cookies_resp = await session.get(cookies_url, ssl=httpbin_ssl_context) + cookies_resp = await session.get(cookies_url, ssl=HTTPBIN_SSL_CONTEXT) assert not cookies_resp.cookies cookies = session.cookie_jar.filter_cookies(cookies_url) assert cookies["Cookie_1"].value == "Val_1" @@ -408,7 +412,7 @@ async def run(loop): # -------------------------- Play --------------------------- # with vcr.use_cassette(tmp, record_mode=vcr.mode.NONE) as cassette: async with aiohttp.ClientSession(loop=loop, cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: - cookies_resp = await session.get(cookies_url, ssl=httpbin_ssl_context) + cookies_resp = await session.get(cookies_url, ssl=HTTPBIN_SSL_CONTEXT) assert not cookies_resp.cookies cookies = session.cookie_jar.filter_cookies(cookies_url) assert cookies["Cookie_1"].value == "Val_1" @@ -422,7 +426,7 @@ async def run(loop): "Cookie_1=Val_1; Expires=Wed, 21 Oct 2015 07:28:00 GMT", ] async with aiohttp.ClientSession(loop=loop, cookie_jar=aiohttp.CookieJar(unsafe=True)) as session: - cookies_resp = await session.get(cookies_url, ssl=httpbin_ssl_context) + cookies_resp = await session.get(cookies_url, ssl=HTTPBIN_SSL_CONTEXT) assert not cookies_resp.cookies cookies = session.cookie_jar.filter_cookies(cookies_url) assert cookies["Cookie_1"].value == "Val_1"