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


Python betamax.Betamax方法代码示例

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


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

示例1: create_app

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def create_app(self):
        from storage_api.app import app
        app.config['TESTING'] = True
        app.config['LIVESERVER_PORT'] = 8943
        app.config['LIVESERVER_TIMEOUT'] = 10
        app.debug = True

        vserver = os.environ.get('ONTAP_VSERVER', 'vs1rac11')
        server_host = os.environ.get('ONTAP_HOST', 'db-51195')
        server_username = os.environ.get('ONTAP_USERNAME', "user-placeholder")
        server_password = os.environ.get('ONTAP_PASSWORD',
                                         "password-placeholder")

        self.backend = extensions.NetappStorage(
            hostname=server_host,
            username=server_username,
            password=server_password,
            vserver=vserver)

        # This magic, apparently, doesn't work. At all.
        self.recorder = betamax.Betamax(self.backend.server.session)
        self.backend.init_app(app, 'test')
        extensions.DummyStorage().init_app(app, 'dummy')

        return app 
开发者ID:cerndb,项目名称:storage-api,代码行数:27,代码来源:test_system.py

示例2: hard_delete_volume

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def hard_delete_volume(self, volume_name):
        ONTAP_VSERVER = os.environ.get('ONTAP_VSERVER', 'vs1rac11')
        server_host = os.environ.get('ONTAP_HOST', 'db-51195')
        server_username = os.environ.get('ONTAP_USERNAME', "user-placeholder")
        server_password = os.environ.get('ONTAP_PASSWORD',
                                         "password-placeholder")

        s = netapp.api.Server(hostname=server_host, username=server_username,
                              password=server_password)

        recorder = betamax.Betamax(s.session)

        with recorder.use_cassette('hard_delete'):
            with s.with_vserver(ONTAP_VSERVER):
                try:
                    s.unmount_volume(volume_name)
                    s.take_volume_offline(volume_name)
                finally:
                    s.destroy_volume(volume_name) 
开发者ID:cerndb,项目名称:storage-api,代码行数:21,代码来源:test_system.py

示例3: test_modpack_fetch

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_modpack_fetch(minimal_pack, tinkers_update):
    """Does the File.fetch fetches the file correctly?"""

    minimal_pack.path /= 'files'
    session = requests.Session()
    file = tinkers_update

    with betamax.Betamax(session).use_cassette('file-fetch'):
        with pytest.raises(OSError):
            minimal_pack.fetch(file, session=session)

        minimal_pack.path.mkdir()
        minimal_pack.fetch(file, session=session)

        filepath = minimal_pack.path / file.name
        assert filepath.is_file()
        assert filepath.stat().st_mtime == file.date.timestamp()

    with responses.RequestsMock() as rsps:
        minimal_pack.fetch(file, session=session)

        assert len(rsps.calls) == 0 
开发者ID:khardix,项目名称:mccurse,代码行数:24,代码来源:test_pack.py

示例4: test_get_source_valid_url

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_get_source_valid_url(self):
        with betamax.Betamax(self.session) as vcr:
            vcr.use_cassette('test_get_source_valid_url')
            url = 'http://www.google.com'
            response = self.engine.get_page_source(url)
            assert isinstance(response, Webpage)
            assert isinstance(response.source, str) 
开发者ID:anidata,项目名称:rasp,代码行数:9,代码来源:test_engines.py

示例5: test_webpage_correct_status

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_webpage_correct_status(self):
        with betamax.Betamax(self.session) as vcr:
            vcr.use_cassette('test_webpage_correct_status')
            url = 'http://google.com/404'
            response = self.engine.get_page_source(url)
            assert response.response_code == 404 
开发者ID:anidata,项目名称:rasp,代码行数:8,代码来源:test_engines.py

示例6: test_tor_get_source_valid_url

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_tor_get_source_valid_url(self):
        with betamax.Betamax(self.session) as vcr:
            vcr.use_cassette('test_tor_get_source_valid_url')
            url = 'http://www.google.com'
            response = self.engine.get_page_source(url)
            assert isinstance(response, Webpage)
            assert isinstance(response.source, str) 
开发者ID:anidata,项目名称:rasp,代码行数:9,代码来源:test_engines.py

示例7: recorder

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def recorder(client):
    return betamax.Betamax(client.session) 
开发者ID:neurolearn,项目名称:pynv,代码行数:4,代码来源:conftest.py

示例8: setup_method

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def setup_method(self, method):
        self.log.info('GitRepoTestCase.setup_method({})'.format(method))
        # build temporary directory
        self.tempdir = TemporaryDirectory()
        # when initiating service with no repository, the connection is not triggered
        self.service = self.get_service()
        # setup http api mockup
        self.recorder = betamax.Betamax(self.get_requests_session())
        self.get_requests_session().headers['Accept-Encoding'] = 'identity'
        # setup git command mockup
        self.setup_git_popen()
        # when initiating service with no repository, the connection is not triggered
        self.service.repository = self.repository
        # have git commands logged
        Git.GIT_PYTHON_TRACE = True
        FORMAT = '> %(message)s'
        formatter = logging.Formatter(fmt=FORMAT)
        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
        logging.getLogger('git.cmd').removeHandler(logging.NullHandler())
        logging.getLogger('git.cmd').addHandler(handler)
        logging.getLogger('git.cmd').propagate = True
        # have HTTP requests logged
        import http.client
        http.client.HTTPConnection.debuglevel = 1
        logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
        logging.getLogger('requests.packages.urllib3').propagate = True 
开发者ID:guyzmo,项目名称:git-repo,代码行数:29,代码来源:helpers.py

示例9: on_all_backends

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def on_all_backends(func):
    """
    This has to be a separate decorator because the storage
    parameter must be initialised on every run with a fresh object.

    Will parametrise the decorated test to run once for every type of
    storage provided here.
    """

    vserver = os.environ.get('ONTAP_VSERVER', 'vs1rac11')
    ontap_host = os.environ.get('ONTAP_HOST', 'dbnasa-cluster-mgmt')
    ontap_username = os.environ.get('ONTAP_USERNAME', "user-placeholder")
    ontap_password = os.environ.get('ONTAP_PASSWORD', "password-placeholder")

    backend = NetappStorage(hostname=ontap_host,
                            username=ontap_username,
                            password=ontap_password,
                            vserver=vserver)
    recorder = betamax.Betamax(backend.server.session)

    @functools.wraps(func)
    @pytest.mark.parametrize("storage,recorder", [(DummyStorage(),
                                                   mock.MagicMock()),
                                                  (backend, recorder)])
    def backend_wrapper(*args, **kwargs):
        func(*args, **kwargs)
    return backend_wrapper 
开发者ID:cerndb,项目名称:storage-api,代码行数:29,代码来源:test_storage.py

示例10: filter_access_token

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def filter_access_token(interaction, current_cassette):
    """Add Betamax placeholder to filter access token."""
    request_uri = interaction.data['request']['uri']
    response = interaction.data['response']
    if ('api/v1/access_token' not in request_uri or
            response['status']['code'] != 200):
        return
    body = response['body']['string']
    try:
        token = json.loads(body)['access_token']
    except (KeyError, TypeError, ValueError):
        return
    current_cassette.placeholders.append(
            betamax.cassette.cassette.Placeholder(
                placeholder='<ACCESS_TOKEN>', replace=token)) 
开发者ID:leviroth,项目名称:bernard,代码行数:17,代码来源:helper.py

示例11: configure

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def configure(self):
        self.r = praw.Reddit(
            user_agent="Tests for BernardJOrtcutt - [email protected]")
        placeholders = {
            x: getattr(self.r.config, x)
            for x in ("client_id client_secret username password "
                      "user_agent").split()}
        placeholders['basic_auth'] = b64_string(
            '{}:{}'.format(placeholders['client_id'],
                           placeholders['client_secret']))
        betamax.Betamax.register_serializer(pretty_json.PrettyJSONSerializer)
        with betamax.Betamax.configure() as config:
            config.cassette_library_dir = 'tests/integration/cassettes'
            config.default_cassette_options['serialize_with'] = 'prettyjson'
            config.before_record(callback=filter_access_token)
            for key, value in placeholders.items():
                if key == 'password':
                    value = quote_plus(value)
                config.define_cassette_placeholder('<{}>'.format(key.upper()),
                                                   value)

        self.subreddit = self.r.subreddit('thirdrealm')
        self.db = sqlite3.connect(':memory:')
        self.db.row_factory = sqlite3.Row
        self.cur = self.db.cursor()
        with open('create_tables.sql') as f:
            command = f.read()
        self.db.executescript(command) 
开发者ID:leviroth,项目名称:bernard,代码行数:30,代码来源:helper.py

示例12: betamax_configure

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def betamax_configure(self):
        http = self.r._core._requestor._http
        self.recorder = betamax.Betamax(http,
                                        cassette_library_dir='test/cassettes')

        http.headers['Accept-Encoding'] = 'identity' 
开发者ID:leviroth,项目名称:bernard,代码行数:8,代码来源:helper.py

示例13: test_modpack_apply

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_modpack_apply(
        minimal_pack,
        minecraft,
        tinkers_construct_file,
        mantle_file,
        tinkers_update
):
    """Test proper application of change sequence."""

    session = requests.Session()

    mp = minimal_pack
    mp.game = minecraft

    with betamax.Betamax(session).use_cassette('modpack-apply'):
        changes_install = [
            pack.FileChange.installation(mp, where=mp.dependencies, file=mantle_file),
            pack.FileChange.installation(mp, where=mp.mods, file=tinkers_construct_file),
        ]
        minimal_pack.apply(changes_install, session=session)

        # Upgrade requires the mod to already exist in the mod-pack
        changes_upgrade = [
            pack.FileChange.explicit(mp, file=mantle_file),
            pack.FileChange.upgrade(mp, file=tinkers_update),
        ]
        minimal_pack.apply(changes_upgrade, session=session)

    assert not minimal_pack.dependencies
    assert len(minimal_pack.mods) == 2
    assert mantle_file.mod.id in minimal_pack.mods
    assert tinkers_update.mod.id in minimal_pack.mods
    assert minimal_pack.mods[tinkers_construct_file.mod.id] == tinkers_update

    mantle_path = mp.path / mantle_file.name
    tinkers_path = mp.path / tinkers_update.name

    assert mantle_path.exists() and tinkers_path.exists() 
开发者ID:khardix,项目名称:mccurse,代码行数:40,代码来源:test_pack.py

示例14: test_fetch_complete_timestamp

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_fetch_complete_timestamp(minecraft_feed):
    """Fetches and decodes the timestamp correctly?"""

    with betamax.Betamax(minecraft_feed.session).use_cassette('feed-timestamp'):  # noqa: E501
        timestamp = minecraft_feed.fetch_complete_timestamp()
        assert isinstance(timestamp, datetime.datetime) 
开发者ID:khardix,项目名称:mccurse,代码行数:8,代码来源:test_curse.py

示例15: test_fetch_complete

# 需要导入模块: import betamax [as 别名]
# 或者: from betamax import Betamax [as 别名]
def test_fetch_complete(minecraft_feed):
    """Fetches and decodes the contents correctly?"""

    with betamax.Betamax(minecraft_feed.session).use_cassette('fetch-feed'), \
            minecraft_feed.fetch_complete() as feed:
        timestamp = next(ijson.items(feed, 'timestamp'), None)
        assert isinstance(timestamp, int)


# Database tests 
开发者ID:khardix,项目名称:mccurse,代码行数:12,代码来源:test_curse.py


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