Skip to content

Commit

Permalink
Disabling aiohttp for testing Python 3.12.
Browse files Browse the repository at this point in the history
  • Loading branch information
mindflayer committed Oct 28, 2023
1 parent 1457a0c commit 7026432
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 62 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test = [
"pook",
"flake8>5",
"xxhash",
"aiohttp",
"aiohttp;python_version<'3.12'",
"httpx",
"pipfile",
"build",
Expand All @@ -56,8 +56,8 @@ test = [
"wait-for-it",
]
speedups = [
'xxhash;platform_python_implementation=="CPython"',
'xxhash-cffi;platform_python_implementation=="PyPy"',
"xxhash;platform_python_implementation=='CPython'",
"xxhash-cffi;platform_python_implementation=='PyPy'",
]
pook = [
"pook>=0.2.1",
Expand Down
8 changes: 4 additions & 4 deletions tests/main/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_json(response):
def test_truesendall_with_recording_https():
with tempfile.TemporaryDirectory() as temp_dir:
with Mocketizer(truesocket_recording_dir=temp_dir):
url = "https://mockbin.org/ip"
url = "https://httpbin.org/ip"

requests.get(url, headers={"Accept": "application/json"})
resp = requests.get(url, headers={"Accept": "application/json"})
Expand All @@ -55,15 +55,15 @@ def test_truesendall_with_recording_https():
with io.open(dump_filename) as f:
responses = json.load(f)

assert len(responses["mockbin.org"]["443"].keys()) == 1
assert len(responses["httpbin.org"]["443"].keys()) == 1


@pytest.mark.skipif('os.getenv("SKIP_TRUE_HTTP", False)')
def test_truesendall_after_mocket_session():
Mocket.enable()
Mocket.disable()

url = "https://mockbin.org/ip"
url = "https://httpbin.org/ip"
resp = requests.get(url)
assert resp.status_code == 200

Expand All @@ -72,7 +72,7 @@ def test_truesendall_after_mocket_session():
def test_real_request_session():
session = requests.Session()

url1 = "https://mockbin.org/ip"
url1 = "https://httpbin.org/ip"
url2 = "http://httpbin.org/headers"

with Mocketizer():
Expand Down
2 changes: 1 addition & 1 deletion tests/main/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@mocketize
@pytest.mark.parametrize("url", ["http://httpbin.org/ip", "https://httpbin.org/ip"])
@pytest.mark.parametrize("url", ("http://httpbin.org/ip", "https://httpbin.org/ip"))
def test_body(url):
body = "asd" * 100
Entry.single_register(Entry.GET, url, body=body, status=404)
Expand Down
128 changes: 74 additions & 54 deletions tests/tests38/test_http_aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from unittest import IsolatedAsyncioTestCase

import aiohttp
import httpx
import pytest

Expand All @@ -10,61 +9,82 @@
from mocket.mockhttp import Entry
from mocket.plugins.httpretty import HTTPretty, async_httprettified


class AioHttpEntryTestCase(IsolatedAsyncioTestCase):
timeout = aiohttp.ClientTimeout(total=3)
try:
import aiohttp

ENABLE_TEST_CLASS = True
except ImportError:
ENABLE_TEST_CLASS = False


if ENABLE_TEST_CLASS:

class AioHttpEntryTestCase(IsolatedAsyncioTestCase):
timeout = aiohttp.ClientTimeout(total=3)
target_url = "http://httpbin.local/ip"

@async_mocketize
async def test_http_session(self):
body = "asd" * 100
Entry.single_register(Entry.GET, self.target_url, body=body, status=404)
Entry.single_register(
Entry.POST, self.target_url, body=body * 2, status=201
)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body

async with session.post(
self.target_url, data=body * 6
) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2
assert Mocket.last_request().method == "POST"
assert Mocket.last_request().body == body * 6

self.assertEqual(len(Mocket.request_list()), 2)

@async_mocketize
async def test_https_session(self):
body = "asd" * 100
Entry.single_register(Entry.GET, self.target_url, body=body, status=404)
Entry.single_register(
Entry.POST, self.target_url, body=body * 2, status=201
)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body

async with session.post(
self.target_url, data=body * 6
) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2

self.assertEqual(len(Mocket.request_list()), 2)

@pytest.mark.xfail
@async_httprettified
async def test_httprettish_session(self):
HTTPretty.register_uri(
HTTPretty.GET,
self.target_url,
body=json.dumps(dict(origin="127.0.0.1")),
)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 200
assert await get_response.text() == '{"origin": "127.0.0.1"}'


class HttpxEntryTestCase(IsolatedAsyncioTestCase):
target_url = "http://httpbin.local/ip"

@async_mocketize
async def test_http_session(self):
body = "asd" * 100
Entry.single_register(Entry.GET, self.target_url, body=body, status=404)
Entry.single_register(Entry.POST, self.target_url, body=body * 2, status=201)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body

async with session.post(self.target_url, data=body * 6) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2
assert Mocket.last_request().method == "POST"
assert Mocket.last_request().body == body * 6

self.assertEqual(len(Mocket.request_list()), 2)

@async_mocketize
async def test_https_session(self):
body = "asd" * 100
Entry.single_register(Entry.GET, self.target_url, body=body, status=404)
Entry.single_register(Entry.POST, self.target_url, body=body * 2, status=201)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body

async with session.post(self.target_url, data=body * 6) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2

self.assertEqual(len(Mocket.request_list()), 2)

@pytest.mark.xfail
@async_httprettified
async def test_httprettish_session(self):
HTTPretty.register_uri(
HTTPretty.GET,
self.target_url,
body=json.dumps(dict(origin="127.0.0.1")),
)

async with aiohttp.ClientSession(timeout=self.timeout) as session:
async with session.get(self.target_url) as get_response:
assert get_response.status == 200
assert await get_response.text() == '{"origin": "127.0.0.1"}'

@async_httprettified
async def test_httprettish_httpx_session(self):
expected_response = {"origin": "127.0.0.1"}
Expand Down

0 comments on commit 7026432

Please sign in to comment.