本文整理匯總了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
示例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)
示例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
示例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)
示例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
示例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)
示例7: recorder
# 需要導入模塊: import betamax [as 別名]
# 或者: from betamax import Betamax [as 別名]
def recorder(client):
return betamax.Betamax(client.session)
示例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
示例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
示例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))
示例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)
示例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'
示例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()
示例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)
示例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