mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 17:15:35 +00:00
@@ -1,4 +1,5 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
|
import logging
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
asyncio = pytest.importorskip("asyncio")
|
asyncio = pytest.importorskip("asyncio")
|
||||||
@@ -112,7 +113,8 @@ def test_stream(tmpdir, scheme):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('body', ['data', 'json'])
|
@pytest.mark.parametrize('body', ['data', 'json'])
|
||||||
def test_post(tmpdir, scheme, body):
|
def test_post(tmpdir, scheme, body, caplog):
|
||||||
|
caplog.set_level(logging.INFO)
|
||||||
data = {'key1': 'value1', 'key2': 'value2'}
|
data = {'key1': 'value1', 'key2': 'value2'}
|
||||||
url = scheme + '://httpbin.org/post'
|
url = scheme + '://httpbin.org/post'
|
||||||
with vcr.use_cassette(str(tmpdir.join('post.yaml'))):
|
with vcr.use_cassette(str(tmpdir.join('post.yaml'))):
|
||||||
@@ -125,6 +127,16 @@ def test_post(tmpdir, scheme, body):
|
|||||||
assert cassette_response_json == response_json
|
assert cassette_response_json == response_json
|
||||||
assert cassette.play_count == 1
|
assert cassette.play_count == 1
|
||||||
|
|
||||||
|
assert next(
|
||||||
|
(
|
||||||
|
log
|
||||||
|
for log in caplog.records
|
||||||
|
if log.getMessage()
|
||||||
|
== '<Request (POST) {}> not in cassette, sending to real server'.format(url)
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
), 'Log message not found.'
|
||||||
|
|
||||||
|
|
||||||
def test_params(tmpdir, scheme):
|
def test_params(tmpdir, scheme):
|
||||||
url = scheme + '://httpbin.org/get'
|
url = scheme + '://httpbin.org/get'
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ def vcr_request(cassette, real_request):
|
|||||||
response.close()
|
response.close()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
log.info("{} not in cassette, sending to real server", vcr_request)
|
log.info('%s not in cassette, sending to real server', vcr_request)
|
||||||
|
|
||||||
response = await real_request(self, method, url, **kwargs) # NOQA: E999
|
response = await real_request(self, method, url, **kwargs) # NOQA: E999
|
||||||
await record_responses(cassette, vcr_request, response)
|
await record_responses(cassette, vcr_request, response)
|
||||||
|
|||||||
Reference in New Issue
Block a user