Skip to content

Commit d09e3eb

Browse files
authored
Merge pull request #220 from mindflayer/bugfix-209
Adding testcase for proving #209 was fixed
2 parents 3edce14 + 574562d commit d09e3eb

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/tests38/test_http_aiohttp.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import asyncio
12
import json
2-
from unittest import IsolatedAsyncioTestCase
3+
from unittest import IsolatedAsyncioTestCase, TestCase
34

45
import pytest
56

67
from mocket.async_mocket import async_mocketize
7-
from mocket.mocket import Mocket, Mocketizer
8+
from mocket.mocket import Mocket, Mocketizer, mocketize
89
from mocket.mockhttp import Entry
910
from mocket.plugins.httpretty import HTTPretty, async_httprettified
1011

@@ -18,7 +19,30 @@
1819

1920
if ENABLE_TEST_CLASS:
2021

21-
class AioHttpEntryTestCase(IsolatedAsyncioTestCase):
22+
class AioHttpEntryTestCase(TestCase):
23+
@mocketize
24+
def test_https_session(self):
25+
url = "https://httpbin.org/ip"
26+
body = "asd" * 100
27+
Entry.single_register(Entry.GET, url, body=body, status=404)
28+
Entry.single_register(Entry.POST, url, body=body * 2, status=201)
29+
30+
async def main(l):
31+
async with aiohttp.ClientSession(
32+
loop=l, timeout=aiohttp.ClientTimeout(total=3)
33+
) as session:
34+
async with session.get(url) as get_response:
35+
assert get_response.status == 404
36+
assert await get_response.text() == body
37+
38+
async with session.post(url, data=body * 6) as post_response:
39+
assert post_response.status == 201
40+
assert await post_response.text() == body * 2
41+
42+
loop = asyncio.new_event_loop()
43+
loop.run_until_complete(main(loop))
44+
45+
class AioHttpEntryAsyncTestCase(IsolatedAsyncioTestCase):
2246
timeout = aiohttp.ClientTimeout(total=3)
2347
target_url = "http://httpbin.local/ip"
2448

0 commit comments

Comments
 (0)