mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
Compare commits
1 Commits
v1.12.0
...
add-pytest
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ce937978e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,7 +1,6 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
.tox
|
.tox
|
||||||
.cache
|
.cache
|
||||||
.pytest_cache/
|
|
||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
*.egg/
|
*.egg/
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: TOX_SUFFIX="boto3"
|
- env: TOX_SUFFIX="boto3"
|
||||||
- env: TOX_SUFFIX="aiohttp"
|
|
||||||
python: "pypy3.5-5.9.0"
|
|
||||||
exclude:
|
exclude:
|
||||||
# Only run flakes on a single Python 2.x and a single 3.x
|
# Only run flakes on a single Python 2.x and a single 3.x
|
||||||
- env: TOX_SUFFIX="flakes"
|
- env: TOX_SUFFIX="flakes"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
Changelog
|
Changelog
|
||||||
---------
|
---------
|
||||||
- 1.12.0 - Fix support to latest aiohttp version (3.2.1), Adapted setup to PEP508, Support binary responses on aiohttp, Dropped support for EOL python versions (2.6 and 3.3)
|
|
||||||
- 1.11.1 Fix compatibility with newest requests and urllib3 releases
|
- 1.11.1 Fix compatibility with newest requests and urllib3 releases
|
||||||
- 1.11.0 Allow injection of persistence methods + bugfixes (thanks @j-funk and @IvanMalison),
|
- 1.11.0 Allow injection of persistence methods + bugfixes (thanks @j-funk and @IvanMalison),
|
||||||
Support python 3.6 + CI tests (thanks @derekbekoe and @graingert),
|
Support python 3.6 + CI tests (thanks @derekbekoe and @graingert),
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -37,7 +37,7 @@ if sys.version_info[0] == 2:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='vcrpy',
|
name='vcrpy',
|
||||||
version='1.12.0',
|
version='1.11.1',
|
||||||
description=(
|
description=(
|
||||||
"Automatically mock your HTTP interactions to simplify and "
|
"Automatically mock your HTTP interactions to simplify and "
|
||||||
"speed up testing"
|
"speed up testing"
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
# flake8: noqa
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def aiohttp_request(loop, method, url, output='text', encoding='utf-8', **kwargs):
|
def aiohttp_request(loop, method, url, output='text', **kwargs):
|
||||||
session = aiohttp.ClientSession(loop=loop)
|
with aiohttp.ClientSession(loop=loop) as session:
|
||||||
response_ctx = session.request(method, url, **kwargs)
|
response = yield from session.request(method, url, **kwargs) # NOQA: E999
|
||||||
|
if output == 'text':
|
||||||
response = yield from response_ctx.__aenter__()
|
content = yield from response.text() # NOQA: E999
|
||||||
if output == 'text':
|
elif output == 'json':
|
||||||
content = yield from response.text()
|
content = yield from response.json() # NOQA: E999
|
||||||
elif output == 'json':
|
elif output == 'raw':
|
||||||
content = yield from response.json(encoding=encoding)
|
content = yield from response.read() # NOQA: E999
|
||||||
elif output == 'raw':
|
return response, content
|
||||||
content = yield from response.read()
|
|
||||||
|
|
||||||
response_ctx._resp.close()
|
|
||||||
yield from session.close()
|
|
||||||
|
|
||||||
return response, content
|
|
||||||
|
|||||||
13
tests/integration/async_def.py
Normal file
13
tests/integration/async_def.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
@@ -1,12 +1,19 @@
|
|||||||
import contextlib
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
asyncio = pytest.importorskip("asyncio")
|
|
||||||
aiohttp = pytest.importorskip("aiohttp")
|
aiohttp = pytest.importorskip("aiohttp")
|
||||||
|
|
||||||
|
import asyncio # noqa: E402
|
||||||
|
import contextlib # noqa: E402
|
||||||
|
|
||||||
|
import pytest # noqa: E402
|
||||||
import vcr # noqa: E402
|
import vcr # noqa: E402
|
||||||
|
|
||||||
from .aiohttp_utils import aiohttp_request # noqa: E402
|
from .aiohttp_utils import aiohttp_request # noqa: E402
|
||||||
|
|
||||||
|
try:
|
||||||
|
from .async_def import test_http # noqa: F401
|
||||||
|
except SyntaxError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def run_in_loop(fn):
|
def run_in_loop(fn):
|
||||||
with contextlib.closing(asyncio.new_event_loop()) as loop:
|
with contextlib.closing(asyncio.new_event_loop()) as loop:
|
||||||
@@ -71,13 +78,11 @@ def test_text(tmpdir, scheme):
|
|||||||
|
|
||||||
def test_json(tmpdir, scheme):
|
def test_json(tmpdir, scheme):
|
||||||
url = scheme + '://httpbin.org/get'
|
url = scheme + '://httpbin.org/get'
|
||||||
headers = {'Content-Type': 'application/json'}
|
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('json.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('json.yaml'))):
|
||||||
_, response_json = get(url, output='json', headers=headers)
|
_, response_json = get(url, output='json')
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('json.yaml'))) as cassette:
|
with vcr.use_cassette(str(tmpdir.join('json.yaml'))) as cassette:
|
||||||
_, cassette_response_json = get(url, output='json', headers=headers)
|
_, cassette_response_json = get(url, output='json')
|
||||||
assert cassette_response_json == response_json
|
assert cassette_response_json == response_json
|
||||||
assert cassette.play_count == 1
|
assert cassette.play_count == 1
|
||||||
|
|
||||||
@@ -107,28 +112,24 @@ def test_post(tmpdir, scheme):
|
|||||||
|
|
||||||
def test_params(tmpdir, scheme):
|
def test_params(tmpdir, scheme):
|
||||||
url = scheme + '://httpbin.org/get'
|
url = scheme + '://httpbin.org/get'
|
||||||
headers = {'Content-Type': 'application/json'}
|
|
||||||
params = {'a': 1, 'b': False, 'c': 'c'}
|
params = {'a': 1, 'b': False, 'c': 'c'}
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
||||||
|
_, response_json = get(url, output='json', params=params)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
||||||
_, response_json = get(url, output='json', params=params, headers=headers)
|
_, cassette_response_json = get(url, output='json', params=params)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
|
||||||
_, cassette_response_json = get(url, output='json', params=params, headers=headers)
|
|
||||||
assert cassette_response_json == response_json
|
assert cassette_response_json == response_json
|
||||||
assert cassette.play_count == 1
|
assert cassette.play_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_params_same_url_distinct_params(tmpdir, scheme):
|
def test_params_same_url_distinct_params(tmpdir, scheme):
|
||||||
url = scheme + '://httpbin.org/get'
|
url = scheme + '://httpbin.org/get'
|
||||||
headers = {'Content-Type': 'application/json'}
|
|
||||||
params = {'a': 1, 'b': False, 'c': 'c'}
|
params = {'a': 1, 'b': False, 'c': 'c'}
|
||||||
|
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
||||||
|
_, response_json = get(url, output='json', params=params)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
||||||
_, response_json = get(url, output='json', params=params, headers=headers)
|
_, cassette_response_json = get(url, output='json', params=params)
|
||||||
|
|
||||||
with vcr.use_cassette(str(tmpdir.join('get.yaml'))) as cassette:
|
|
||||||
_, cassette_response_json = get(url, output='json', params=params, headers=headers)
|
|
||||||
assert cassette_response_json == response_json
|
assert cassette_response_json == response_json
|
||||||
assert cassette.play_count == 1
|
assert cassette.play_count == 1
|
||||||
|
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ def test_post_chunked_binary(tmpdir, httpbin):
|
|||||||
assert req1 == req2
|
assert req1 == req2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xskip('sys.version_info >= (3, 6)', strict=True, raises=ConnectionError)
|
@pytest.mark.xfail('sys.version_info >= (3, 6)', strict=True, raises=ConnectionError)
|
||||||
@pytest.mark.xskip((3, 5) < sys.version_info < (3, 6) and
|
@pytest.mark.xfail((3, 5) < sys.version_info < (3, 6) and
|
||||||
platform.python_implementation() == 'CPython',
|
platform.python_implementation() == 'CPython',
|
||||||
reason='Fails on CPython 3.5')
|
reason='Fails on CPython 3.5')
|
||||||
def test_post_chunked_binary_secure(tmpdir, httpbin_secure):
|
def test_post_chunked_binary_secure(tmpdir, httpbin_secure):
|
||||||
|
|||||||
5
tox.ini
5
tox.ini
@@ -11,12 +11,13 @@ deps = flake8
|
|||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands =
|
commands =
|
||||||
./runtests.sh {posargs}
|
./runtests.sh -n 4 {posargs}
|
||||||
deps =
|
deps =
|
||||||
Flask<1
|
Flask<1
|
||||||
mock
|
mock
|
||||||
pytest
|
pytest
|
||||||
pytest-httpbin
|
pytest-httpbin
|
||||||
|
pytest-xdist
|
||||||
PyYAML
|
PyYAML
|
||||||
requests27: requests==2.7.0
|
requests27: requests==2.7.0
|
||||||
httplib2: httplib2
|
httplib2: httplib2
|
||||||
@@ -25,7 +26,7 @@ deps =
|
|||||||
{py27,py35,py36,pypy}-tornado4: pytest-tornado
|
{py27,py35,py36,pypy}-tornado4: pytest-tornado
|
||||||
{py27,py35,py36}-tornado4: pycurl
|
{py27,py35,py36}-tornado4: pycurl
|
||||||
boto3: boto3
|
boto3: boto3
|
||||||
aiohttp: aiohttp
|
aiohttp: aiohttp<3
|
||||||
aiohttp: pytest-asyncio
|
aiohttp: pytest-asyncio
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
|
|||||||
@@ -12,20 +12,6 @@ from vcr.request import Request
|
|||||||
|
|
||||||
|
|
||||||
class MockClientResponse(ClientResponse):
|
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
|
# TODO: get encoding from header
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def json(self, *, encoding='utf-8', loads=json.loads): # NOQA: E999
|
def json(self, *, encoding='utf-8', loads=json.loads): # NOQA: E999
|
||||||
|
|||||||
Reference in New Issue
Block a user