本文整理汇总了Python中vcr.VCR.ensure_suffix方法的典型用法代码示例。如果您正苦于以下问题:Python VCR.ensure_suffix方法的具体用法?Python VCR.ensure_suffix怎么用?Python VCR.ensure_suffix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcr.VCR
的用法示例。
在下文中一共展示了VCR.ensure_suffix方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ensure_suffix
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
def test_ensure_suffix():
vcr = VCR(inject_cassette=True, path_transformer=VCR.ensure_suffix('.yaml'))
@vcr.use_cassette
def function_name(cassette):
assert cassette._path == os.path.join(os.path.dirname(__file__),
'function_name.yaml')
function_name()
示例2: vcr
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
def vcr(vcr):
def scrub_request(request):
for header in ("Authorization", "Set-Cookie", "Cookie"):
if header in request.headers:
del request.headers[header]
return request
def scrub_response(response):
for header in ("Authorization", "Set-Cookie", "Cookie", "Date", "Expires", "Transfer-Encoding"):
if header in response["headers"]:
del response["headers"][header]
return response
def range_header_matcher(r1, r2):
return r1.headers.get('Range', '') == r2.headers.get('Range', '')
vcr.cassette_library_dir = CASSETTE_DIR
vcr.path_transformer = VCR.ensure_suffix('.yaml')
vcr.filter_headers = ['Set-Cookie']
vcr.before_record_request = scrub_request
vcr.before_record_response = scrub_response
vcr.decode_compressed_response = True
vcr.register_serializer('custom', BinaryContentSerializer(CASSETTE_DIR))
vcr.serializer = 'custom'
vcr.register_matcher('range_header', range_header_matcher)
vcr.match_on = ['uri', 'method', 'body', 'range_header']
return vcr
示例3: VCR
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
# -*- coding: utf-8 -*-
import bot_mock
from pyfibot.modules import module_urltitle
from utils import check_re
import pytest
from vcr import VCR
my_vcr = VCR(
path_transformer=VCR.ensure_suffix(".yaml"),
cassette_library_dir="tests/cassettes/",
record_mode=pytest.config.getoption("--vcrmode"),
)
@pytest.fixture
def botmock():
bot = bot_mock.BotMock()
module_urltitle.init(bot)
return bot
length_str_regex = u"\d+(h|m|s)(\d+(m))?(\d+s)?"
views_str_regex = u"\d+(\.\d+)?(k|M|Billion|Trillion)?"
age_str_regex = u"(FRESH|(\d+(\.\d+)?(y|d) (ago|from now)))"
@my_vcr.use_cassette
def test_areena_radio(botmock):
示例4: my_vcr
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
def my_vcr(gocd_docker):
return VCR(
path_transformer=VCR.ensure_suffix('.yaml'),
cassette_library_dir=os.path.join(root_cassette_library_dir, gocd_docker),
)
示例5: session_fixture
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
session.server_url = 'http://example.com'
return session
@pytest.fixture()
def session_fixture():
options = copy.deepcopy(Yagocd.DEFAULT_OPTIONS)
options['server'] = 'http://local.docker:8153/'
return Session(
auth=('admin', '12345'),
options=options
)
my_vcr_object = VCR(
path_transformer=VCR.ensure_suffix('.yaml'),
cassette_library_dir=os.path.join(tests_dir(), 'fixtures/cassettes'),
)
@pytest.fixture()
def my_vcr():
return my_vcr_object
CONTAINER_NAME = 'yagocd-server'
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
def pytest_addoption(parser):
parser.addoption(
示例6: VCR
# 需要导入模块: from vcr import VCR [as 别名]
# 或者: from vcr.VCR import ensure_suffix [as 别名]
"""
body = request.body
if helpers.PY3:
body = request.body.decode('utf-8')
payload = json.loads(body)
payload['SignRequest']['OptionalInputs']['ClaimedIdentity']['Name'] = 'X:Y'
request.body = json.dumps(payload)
return request
my_vcr = VCR(
serializer='json',
record_mode='once',
cassette_library_dir=join(dirname(__file__), 'cassettes'),
path_transformer=VCR.ensure_suffix('.json'),
before_record=before_record_callback
)
if helpers.PY3:
my_vcr.register_serializer('json', JSONSerializer)
def fixture_path(filename):
"""Build the full path of a fixture file."""
return join(dirname(__file__), 'fixtures', filename)
class BaseCase(unittest.TestCase):
pass