|
| 1 | +import asyncio |
1 | 2 | import json |
2 | | -from unittest import IsolatedAsyncioTestCase |
| 3 | +from unittest import IsolatedAsyncioTestCase, TestCase |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
6 | 7 | from mocket.async_mocket import async_mocketize |
7 | | -from mocket.mocket import Mocket, Mocketizer |
| 8 | +from mocket.mocket import Mocket, Mocketizer, mocketize |
8 | 9 | from mocket.mockhttp import Entry |
9 | 10 | from mocket.plugins.httpretty import HTTPretty, async_httprettified |
10 | 11 |
|
|
18 | 19 |
|
19 | 20 | if ENABLE_TEST_CLASS: |
20 | 21 |
|
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): |
22 | 46 | timeout = aiohttp.ClientTimeout(total=3) |
23 | 47 | target_url = "http://httpbin.local/ip" |
24 | 48 |
|
|
0 commit comments