本文整理汇总了Python中responses.stop函数的典型用法代码示例。如果您正苦于以下问题:Python stop函数的具体用法?Python stop怎么用?Python stop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: mock_api
def mock_api():
# Mock get the license list.
with open(path.join(ROOT, 'licenses.json')) as f:
mock_response_body = f.read()
responses.add(responses.GET, 'https://api.github.com/licenses',
body=mock_response_body)
# Mock get each license template.
for license in os.listdir(path.join(ROOT, 'licenses')):
with open(path.join(ROOT, 'licenses/{0}'.format(license))) as f:
mock_response_body = f.read()
responses.add(responses.GET,
'https://api.github.com/licenses/{0}'.format(
path.splitext(license)[0]),
body=mock_response_body, content_type='application/json')
# Mock get the invalid license.
with open(path.join(ROOT, 'not_found.json')) as f:
mock_not_found_body = f.read()
responses.add(responses.GET, 'https://api.github.com/licenses/invalid',
body=mock_not_found_body, content_type='application/json')
responses.start()
yield responses
responses.stop()
开发者ID:lord63,项目名称:choosealicense-cli,代码行数:25,代码来源:conftest.py
示例2: wrapper
def wrapper(*args, **kwargs):
responses.start()
responses.add(**response_dict)
result = f(response_data=json.loads(response_dict["body"]), *args, **kwargs)
responses.stop()
responses.reset()
return result
开发者ID:jthi3rry,项目名称:hasoffers,代码行数:7,代码来源:mocks.py
示例3: mock_api
def mock_api():
"""A mock for the PyPI JSON API."""
with open(os.path.join(HERE, 'response.json'), 'r') as fp:
webargs_response = fp.read()
# A valid package with a proper response
responses.add(
responses.GET,
'https://pypi.python.org/pypi/webargs/json',
body=webargs_response,
content_type='application/json'
)
# A valid package with no releases
with open(os.path.join(HERE, 'response_noreleases.json'), 'r') as fp:
foo_response = fp.read()
responses.add(
responses.GET,
'https://pypi.python.org/pypi/foo/json',
body=foo_response,
content_type='application/json'
)
# An invalid package name
responses.add(
responses.GET,
'https://pypi.python.org/pypi/nope/json',
status=404
)
responses.start()
yield responses
responses.stop()
开发者ID:barseghyanartur,项目名称:pypi-cli,代码行数:33,代码来源:conftest.py
示例4: mock_api
def mock_api():
with open(path.join(ROOT, 'signin.html'), encoding='utf-8') as f:
mock_signin_body = f.read()
responses.add(responses.POST, 'https://www.v2ex.com/signin',
body=mock_signin_body)
responses.add(responses.GET, 'https://www.v2ex.com/signin',
body=mock_signin_body)
with open(path.join(ROOT, 'once.html'), encoding='utf-8') as f:
mock_once_body = f.read()
responses.add(responses.GET,
'https://www.v2ex.com/mission/daily/redeem?once=51947',
body=mock_once_body)
with open(path.join(ROOT, 'balance.html'), encoding='utf-8') as f:
mock_balance_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/balance',
body=mock_balance_body)
with open(path.join(ROOT, 'mission.html'), encoding='utf-8') as f:
mock_mission_body = f.read()
responses.add(responses.GET, 'https://www.v2ex.com/mission/daily',
body=mock_mission_body)
responses.start()
yield responses
responses.stop()
开发者ID:tuutoo,项目名称:v2ex_daily_mission,代码行数:28,代码来源:conftest.py
示例5: testTearDown
def testTearDown(self):
try:
responses.stop()
except RuntimeError:
pass
finally:
responses.reset()
开发者ID:propertyshelf,项目名称:ps.plone.mls,代码行数:7,代码来源:testing.py
示例6: wrapper
def wrapper(*args, **kwargs):
responses.start()
for response in resps:
responses.add(**response)
result = f(responses=responses, *args, **kwargs)
responses.stop()
responses.reset()
return result
开发者ID:jthi3rry,项目名称:uniauth,代码行数:8,代码来源:mocks.py
示例7: tearDown
def tearDown(self):
super(AkismetClientTests, self).tearDown()
responses.stop()
responses.reset()
Flag.objects.update_or_create(
name=SPAM_CHECKS_FLAG,
defaults={'everyone': None},
)
开发者ID:2015xray,项目名称:kuma,代码行数:8,代码来源:test_akismet.py
示例8: mock_api
def mock_api():
for package_name in ['requests', 'flask', 'pip']:
mock_package_response(package_name)
for package_name in ['this_package_name_has_not_been_used',
'you_will_never_use_this_package_name',
'I_suck_and_my_tests_are_order_dependent']:
mock_package_response(package_name, status_code=404)
responses.start()
yield responses
responses.stop()
开发者ID:lord63,项目名称:caniuse,代码行数:11,代码来源:conftest.py
示例9: fixture
def fixture():
responses.add(
responses.POST,
url,
status=status,
body=json.dumps(data or {}),
content_type='application/json',
)
responses.start()
yield responses
responses.stop()
responses.reset()
开发者ID:BenderV,项目名称:betfair2.py,代码行数:12,代码来源:utils.py
示例10: callback
def callback(req):
# clean up after last callback
add_downloaded_files(state['downloaded'], spec, state['previous_url'])
if state['requests'] == state['total_requests']:
raise MaxDownloadsReached()
# make a real requests call somehow
responses.stop()
# when testing this testing function
# (testTestutil.RepoTester.test_download_setfile) we
# still want to disable responses, but we don't want
# to make an actual HTTP call. Detect if we are
# running that test by examining the stack, and if so,
# mock the requests.get call in a different way.
frames = [f for f in inspect.stack() if f[3] == "test_download_setfile"]
if frames:
frame = frames[0][0]
resp = frame.f_locals['self']._myget(req.url)
else:
resp = requests.get(req.url)
responses.start()
# create a filename. use .html as suffix unless we
# should use something else
contenttype = resp.headers["Content-type"]
stem = os.path.splitext(specfile)[0]
suffix = {'application/pdf': 'pdf',
'application/json': 'json',
'text/plain': 'txt'}.get(contenttype, "html")
outfile = "%s-%s.%s" % (stem, state['requests'], suffix)
with open(outfile, "wb") as fp:
fp.write(resp.content)
if not frames and os.environ.get("TRAVIS") != "true":
if suffix == "html":
print(
"requested %s, saved as %s. Edit if needed, then press enter" %
(req.url, outfile))
x = input()
else:
print("requested %s, saved %s" % (req.url, outfile))
with open(outfile, "rb") as fp:
content = fp.read()
spec[req.url] = {'file': os.path.basename(outfile)}
if resp.encoding != 'utf-8':
spec[req.url]['encoding'] = resp.encoding
state['requests'] += 1
state['previous_url'] = req.url
return (resp.status_code, resp.headers, content)
开发者ID:staffanm,项目名称:ferenda,代码行数:49,代码来源:testutil.py
示例11: start_responses_mocking
def start_responses_mocking(request):
"""Enable ``responses`` this enforcing us to explicitly mark tests
that require internet usage.
"""
marker = request.node.get_closest_marker('allow_external_http_requests')
if not marker:
responses.start()
yield
try:
if not marker:
responses.stop()
responses.reset()
except RuntimeError:
# responses patcher was already uninstalled
pass
开发者ID:diox,项目名称:olympia,代码行数:18,代码来源:conftest.py
示例12: mock_request
def mock_request():
with open(path.join(path.dirname(path.realpath(__file__)),
'fake_response.json')) as f:
fake_response = json.load(f)
responses.add(
responses.GET,
url=("https://www.bing.com/HPImageArchive.aspx?format"
"=js&idx=0&n=1&nc=1409879295618&pid=hp"),
json=fake_response,
status=200,
match_querystring=True
)
responses.add(
responses.GET,
url=("https://www.bing.com/az/hprichbg/rb/HudsonBayPolars_"
"ZH-CN10500767857_1920x1080.jpg"),
status=200,
body='Hello, world'
)
responses.start()
yield responses
responses.stop()
开发者ID:DeastinY,项目名称:wonderful_bing,代码行数:24,代码来源:conftest.py
示例13: done
def done():
responses.stop()
responses.reset()
开发者ID:dabibbit,项目名称:ripple-sepa-bridge,代码行数:3,代码来源:tests.py
示例14: done
def done():
resp_module.stop()
resp_module.reset()
开发者ID:singingwolfboy,项目名称:flask-dance,代码行数:3,代码来源:conftest.py
示例15: teardown_limetypes
def teardown_limetypes():
responses.stop()
responses.reset()
开发者ID:Lundalogik,项目名称:limeclient,代码行数:3,代码来源:limetypes_spec.py
示例16: teardown_limeobjects
def teardown_limeobjects():
responses.stop()
responses.reset()
开发者ID:Lundalogik,项目名称:limeclient,代码行数:3,代码来源:limeobjects_spec.py
示例17: tearDown
def tearDown(self):
responses.stop()
responses.reset()
开发者ID:propertyshelf,项目名称:mls.apiclient,代码行数:3,代码来源:test_resources.py
示例18: tearDown
def tearDown(self):
responses.stop()
responses.reset()
super(MockRequestsMixin, self).tearDown()
开发者ID:TabbedOut,项目名称:django_canary_endpoint,代码行数:4,代码来源:mocks.py
示例19: callback
def callback(http_request):
responses.stop()
response = testypie.get_response(http_request.url, http_request.headers)
responses.start()
return response['code'], response['headers'], response['body']
开发者ID:avengerpenguin,项目名称:doyoulikeit,代码行数:5,代码来源:test_views_likes.py
示例20: teardown
def teardown():
responses.stop()
responses.reset()
开发者ID:Lundalogik,项目名称:limeclient,代码行数:3,代码来源:limeviews_spec.py
注:本文中的responses.stop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论