当前位置: 首页>>代码示例>>Python>>正文


Python Betamax.configure方法代码示例

本文整理汇总了Python中betamax.Betamax.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Betamax.configure方法的具体用法?Python Betamax.configure怎么用?Python Betamax.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在betamax.Betamax的用法示例。


在下文中一共展示了Betamax.configure方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: configure

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
def configure():
    config = Betamax.configure()
    config.cassette_library_dir = "tests/test_api/betamax/"
    config.default_cassette_options['record_mode'] = 'once'
    config.default_cassette_options['match_requests_on'] = ['method', 'path_matcher']
    if credentials:
        auth_key = 'token' if 'token' in credentials else 'password'
        config.define_cassette_placeholder(
            '<ZENPY-CREDENTIALS>',
            str(base64.b64encode(
                "{}/token:{}".format(credentials['email'], credentials[auth_key]).encode('utf-8')
            ))
        )
    session = requests.Session()
    credentials['session'] = session
    zenpy_client = Zenpy(**credentials)
    recorder = Betamax(session=session)

    class PathMatcher(URIMatcher):
        """
        I use trial accounts for testing Zenpy and as such the subdomain is always changing.
        This matcher ignores the netloc section of the parsed URL which prevents the tests
        failing when the subdomain is changed.
        """
        name = 'path_matcher'

        def parse(self, uri):
            parse_result = super(PathMatcher, self).parse(uri)
            parse_result.pop('netloc')
            return parse_result

    Betamax.register_request_matcher(PathMatcher)
    recorder.register_serializer(PrettyJSONSerializer)
    return zenpy_client, recorder
开发者ID:Aloomaio,项目名称:zenpy,代码行数:36,代码来源:__init__.py

示例2: test_preserve_exact_body_bytes

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
    def test_preserve_exact_body_bytes(self):
        with Betamax.configure() as config:
            config.preserve_exact_body_bytes = True

        with Betamax(self.session) as b:
            b.use_cassette('global_preserve_exact_body_bytes')
            r = self.session.get('https://httpbin.org/get')
            assert 'headers' in r.json()

            interaction = b.current_cassette.interactions[0].json
            assert 'base64_string' in interaction['response']['body']
开发者ID:arhoyling,项目名称:betamax,代码行数:13,代码来源:test_preserve_exact_body_bytes.py

示例3: setUpClass

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
    def setUpClass(cls):

        cls.session = requests.Session()
        cls.recorder = Betamax(cls.session)

        cls.api_key = config.MAILCHIMP_API_KEY

        # the subdomain to use in the api url
        # is always the last 3 characters of the api key
        cls.subdomain = cls.api_key[-3:]

        # define the string that will be passed in the MailChimp request
        # 'Authorization' header
        MAILCHIMP_REQUEST_AUTH_HEADER_NAME = 'apikey'
        MAILCHIMP_REQUEST_AUTH_HEADER = '{}:{}'.format(
            MAILCHIMP_REQUEST_AUTH_HEADER_NAME, cls.api_key)

        # create the directory to store betamax cassettes
        abs_cassette_dir = os.path.join(os.path.dirname(
            os.path.abspath(__file__)), cls.cassette_dir)
        os.makedirs(abs_cassette_dir, exist_ok=True)

        Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
        with Betamax.configure() as betamaxconfig:
            betamaxconfig.cassette_library_dir = abs_cassette_dir
            betamaxconfig.default_cassette_options['record_mode'] = 'once'
            betamaxconfig.default_cassette_options[
                'serialize_with'] = 'prettyjson'
            betamaxconfig.default_cassette_options['match_requests_on'] = [
                'method'
            ]
            betamaxconfig.define_cassette_placeholder(
                '<MAILCHIMP_AUTH_B64>',
                base64.b64encode(
                    MAILCHIMP_REQUEST_AUTH_HEADER.encode()
                ).decode()
            )
            betamaxconfig.define_cassette_placeholder(
                '<MAILCHIMP_SUBDOMAIN>',
                cls.subdomain
            )

        # suppress these warnings (due to requests module): 
        # ResourceWarning: unclosed <ssl.SSLSocket
        warnings.simplefilter("ignore", ResourceWarning)
开发者ID:ulyssesv,项目名称:mailchimpy,代码行数:47,代码来源:basemailchimptest.py

示例4: configure_betamax

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
def configure_betamax(api, **additional_apis):
    with Betamax.configure() as config:
        config.cassette_library_dir = 'tests/fixtures/cassettes'
        config.match_requests_on = ['method', 'uri', 'body']

        def _set_api(api, template):
            for attr in ('username', 'password', 'password_hash'):
                value = getattr(api, attr, None)
                if value:
                    config.define_cassette_placeholder(template % attr.upper(), value)

        # Configure primary API
        config.define_cassette_placeholder('<URL>', api.url)
        _set_api(api, '<%s>')

        # Any additional APIs
        for name, api in additional_apis.items():
            template = '<' + name.upper() + '_%s>' if name else '<%s>'
            _set_api(api, template)
开发者ID:aschenkels-ictstudio,项目名称:openprovider.py,代码行数:21,代码来源:api_tests.py

示例5: configure_betamax

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
def configure_betamax(api, **additional_apis):
    with Betamax.configure() as config:
        config.cassette_library_dir = 'tests/fixtures/cassettes'
        config.default_cassette_options['match_options'] = ['method', 'uri', 'body']

        def _set_api(api, template):
            for attr in ('username', 'password', 'password_hash'):
                value = getattr(api, attr, None)
                if value:
                    config.define_cassette_placeholder(template % attr.upper(), value)

        # Configure primary API
        config.define_cassette_placeholder('<URL>', api.url)
        _set_api(api, '<%s>')
        # placeholders aren't replaced in gzipped responses
        api.session.headers['Accept-Encoding'] = ''

        # Any additional APIs
        for name, api in additional_apis.items():
            template = '<' + name.upper() + '_%s>' if name else '<%s>'
            _set_api(api, template)
            # placeholders aren't replaced in gzipped responses
            api.session.headers['Accept-Encoding'] = ''
开发者ID:AntagonistHQ,项目名称:openprovider.py,代码行数:25,代码来源:api_tests.py

示例6: none

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
        self.assertTrue(first_hit)
        return first_hit

    def none(self, sequence, predicate):
        self.assertEqual(
            None, next((x for x in sequence if predicate(x)), None))

    def setUp(self):
        self.configure()

    def url(self, path):
        return urljoin(self.r.config.permalink_url, path)


Betamax.register_request_matcher(BodyMatcher)
with Betamax.configure() as config:
    if os.getenv('TRAVIS'):
        config.default_cassette_options['record_mode'] = 'none'
    config.cassette_library_dir = 'tests/cassettes'
    config.default_cassette_options['match_requests_on'].append('PRAWBody')


def betamax(cassette_name=None, **cassette_options):
    """Utilze betamax to record/replay any network activity of the test.

    The wrapped function's `betmax_init` method will be invoked if it exists.

    """
    def factory(function):
        @wraps(function)
        def betamax_function(obj):
开发者ID:vallard192,项目名称:praw,代码行数:33,代码来源:helper.py

示例7: setUp

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
 def setUp(self):
     super(TestPlaceholders, self).setUp()
     config = Betamax.configure()
     config.define_cassette_placeholder('<AUTHORIZATION>', b64_foobar)
开发者ID:dgouldin,项目名称:betamax,代码行数:6,代码来源:test_placeholders.py

示例8: setUp

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
 def setUp(self):
     with Betamax.configure() as config:
         config.default_cassette_options['record_mode'] = 'none'
开发者ID:arhoyling,项目名称:betamax,代码行数:5,代码来源:test_cassettes_retain_global_configuration.py

示例9: tearDown

# 需要导入模块: from betamax import Betamax [as 别名]
# 或者: from betamax.Betamax import configure [as 别名]
 def tearDown(self):
     with Betamax.configure() as config:
         config.default_cassette_options['record_mode'] = 'once'
开发者ID:arhoyling,项目名称:betamax,代码行数:5,代码来源:test_cassettes_retain_global_configuration.py


注:本文中的betamax.Betamax.configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。