]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Fix aiohttp stub to support version >= 3.1.0
authorLuiz Menezes <luiz.menezesf@gmail.com>
Tue, 1 May 2018 21:20:37 +0000 (18:20 -0300)
committerLuiz Menezes <luiz.menezesf@gmail.com>
Mon, 7 May 2018 12:25:21 +0000 (09:25 -0300)
tests/integration/aiohttp_utils.py
tests/integration/async_def.py [deleted file]
tests/integration/test_aiohttp.py
vcr/stubs/aiohttp_stubs/__init__.py

index 991877b1f2d2e3fbced8a727b190ac383046e5c4..edf56bf1cd39ade0747925048cd26ae520c36a32 100644 (file)
@@ -1,15 +1,13 @@
-import asyncio
 import aiohttp
 
 
-@asyncio.coroutine
-def aiohttp_request(loop, method, url, output='text', **kwargs):
+async def aiohttp_request(loop, method, url, output='text', **kwargs):
     with aiohttp.ClientSession(loop=loop) as session:
-        response = yield from session.request(method, url, **kwargs)  # NOQA: E999
+        response = await session.request(method, url, **kwargs)  # NOQA: E999
         if output == 'text':
-            content = yield from response.text()  # NOQA: E999
+            content = await response.text()  # NOQA: E999
         elif output == 'json':
-            content = yield from response.json()  # NOQA: E999
+            content = await response.json()  # NOQA: E999
         elif output == 'raw':
-            content = yield from response.read()  # NOQA: E999
+            content = await response.read()  # NOQA: E999
         return response, content
diff --git a/tests/integration/async_def.py b/tests/integration/async_def.py
deleted file mode 100644 (file)
index 96cab1d..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-import aiohttp
-import pytest
-import vcr
-
-
-@vcr.use_cassette()
-@pytest.mark.asyncio
-async def test_http():  # noqa: E999
-    async with aiohttp.ClientSession() as session:
-        url = 'https://httpbin.org/get'
-        params = {'ham': 'spam'}
-        resp = await session.get(url, params=params)  # noqa: E999
-        assert (await resp.json())['args'] == {'ham': 'spam'}  # noqa: E999
index bccd4e67e964019cb9dd2eeed04028c15de41deb..a81e8e9e3a9a122311fbaae6890271e85cc40977 100644 (file)
@@ -7,12 +7,11 @@ import contextlib  # noqa: E402
 import pytest  # noqa: E402
 import vcr  # noqa: E402
 
-from .aiohttp_utils import aiohttp_request  # noqa: E402
 
 try:
-    from .async_def import test_http  # noqa: F401
+    from .aiohttp_utils import aiohttp_request  # noqa: E402
 except SyntaxError:
-    pass
+    pytest.skip('python<3.5', allow_module_level=True)
 
 
 def run_in_loop(fn):
index 79ce06c1ff9b6d30a0f6a7e043ba2a678fd45e51..7b2837d3e0963132b030c31f721fe6f8bc8d8e63 100644 (file)
@@ -12,6 +12,20 @@ from vcr.request import Request
 
 
 class MockClientResponse(ClientResponse):
+    def __init__(self, method, url):
+        super().__init__(
+            method=method,
+            url=url,
+            writer=None,
+            continue100=None,
+            timer=None,
+            request_info=None,
+            auto_decompress=None,
+            traces=None,
+            loop=asyncio.get_event_loop(),
+            session=None,
+        )
+
     # TODO: get encoding from header
     @asyncio.coroutine
     def json(self, *, encoding='utf-8', loads=json.loads):  # NOQA: E999