本文整理汇总了Python中responses.start函数的典型用法代码示例。如果您正苦于以下问题:Python start函数的具体用法?Python start怎么用?Python start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了start函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(VstsIntegrationTestCase, self).setUp()
self.access_token = '9d646e20-7a62-4bcc-abc0-cb2d4d075e36'
self.refresh_token = '32004633-a3c0-4616-9aa0-a40632adac77'
self.vsts_account_id = 'c8a585ae-b61f-4ba6-833c-9e8d5d1674d8'
self.vsts_account_name = 'MyVSTSAccount'
self.vsts_account_uri = 'https://MyVSTSAccount.vssps.visualstudio.com:443/'
self.vsts_base_url = 'https://MyVSTSAccount.visualstudio.com/'
self.vsts_user_id = 'd6245f20-2af8-44f4-9451-8107cb2767db'
self.vsts_user_name = 'Foo Bar'
self.vsts_user_email = '[email protected]'
self.repo_id = '47166099-3e16-4868-9137-22ac6b05b06e'
self.repo_name = 'cool-service'
self.project_a = {
'id': 'eb6e4656-77fc-42a1-9181-4c6d8e9da5d1',
'name': 'ProjectA',
}
self.project_b = {
'id': '6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c',
'name': 'ProjectB',
}
responses.start()
self._stub_vsts()
开发者ID:alexandrul,项目名称:sentry,代码行数:30,代码来源:testutils.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():
# 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
示例5: setUp
def setUp(self):
super(AkismetClientTests, self).setUp()
responses.start()
Flag.objects.update_or_create(
name=SPAM_CHECKS_FLAG,
defaults={'everyone': True},
)
开发者ID:2015xray,项目名称:kuma,代码行数:7,代码来源:test_akismet.py
示例6: 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
示例7: setUp
def setUp(self):
self.ably = RestSetup.get_ably_rest(use_binary_protocol=False)
# Mocked responses
# without headers
responses.add(responses.GET,
'http://rest.ably.io/channels/channel_name/ch1',
body='[{"id": 0}, {"id": 1}]', status=200,
content_type='application/json')
# with headers
responses.add_callback(
responses.GET,
'http://rest.ably.io/channels/channel_name/ch2',
self.get_response_callback(
headers={
'link':
'<http://rest.ably.io/channels/channel_name/ch2?page=1>; rel="first",'
' <http://rest.ably.io/channels/channel_name/ch2?page=2>; rel="next"'
},
body='[{"id": 0}, {"id": 1}]',
status=200),
content_type='application/json')
# start intercepting requests
responses.start()
self.paginated_result = PaginatedResult.paginated_query(
self.ably.http,
url='http://rest.ably.io/channels/channel_name/ch1',
response_processor=lambda response: response.to_native())
self.paginated_result_with_headers = PaginatedResult.paginated_query(
self.ably.http,
url='http://rest.ably.io/channels/channel_name/ch2',
response_processor=lambda response: response.to_native())
开发者ID:ably,项目名称:ably-python,代码行数:34,代码来源:restpaginatedresult_test.py
示例8: 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
示例9: test_hook_is_found_and_checksum_fails___hook_is_not_saved
def test_hook_is_found_and_checksum_fails___hook_is_not_saved(self, name, content, hook_type):
self.set_existing_search_response(name, content, hook_type, response_content=content + 'tamper')
responses.start()
with FakeRepoDir():
sys.argv = ['foo', 'install', hook_type, name]
cmd.Hooks().run()
self.assertFalse(os.path.exists(os.path.join(repo.hook_type_directory(hook_type), name)))
开发者ID:wildfish,项目名称:git-hooks,代码行数:9,代码来源:test_cmd.py
示例10: setUp
def setUp(self):
feed_url = 'http://microblog.brianschrader.com/feed'
self.feed = models.RemoteFeed.objects.create(feed_url=feed_url)
with open(os.path.join(settings.BASE_DIR, 'tests', 'fixtures', 'sonic_feed.xml')) as fixture_file:
self.test_feed = fixture_file.read()
responses.add(responses.GET, feed_url, body=self.test_feed,
status=200, content_type='application/xml')
responses.start()
self.feed.update_feed()
开发者ID:macro1,项目名称:djublog,代码行数:9,代码来源:test_models.py
示例11: setUp
def setUp(self):
super(TestMigrateForks, self).setUp()
# Create registration with correct settings
self.user = UserFactory()
self.consolidated_auth = Auth(user=self.user)
# Create base project
self.base_project = ProjectFactory(
creator=self.user,
piwik_site_id=1,
)
self.base_component = NodeFactory(
project=self.base_project,
creator=self.user,
piwik_site_id=2,
)
# Create valid fork
self.fork_project = self.base_project.fork_node(
auth=self.consolidated_auth
)
self.fork_project.piwik_site_id = 3
self.fork_project.save()
self.fork_component = self.fork_project.nodes[0]
self.fork_component.piwik_site_id = 4
self.fork_component.save()
# Create broken fork
self.bad_fork_project = self.base_project.fork_node(
auth=self.consolidated_auth
)
self.bad_fork_project.piwik_site_id = self.base_project.piwik_site_id
self.bad_fork_project.save()
self.bad_fork_component = self.bad_fork_project.nodes[0]
self.bad_fork_component.piwik_site_id = self.base_component.piwik_site_id
self.bad_fork_component.save()
responses.start()
responses.add(
responses.GET,
'{host}index.php?module=API&method=SitesManager.getAllSites&format=JSON&token_auth={auth_token}'.format(
host=PIWIK_HOST,
auth_token=PIWIK_ADMIN_TOKEN,
),
status=200,
content_type='application/json',
body=json.dumps({
'1': {'name': 'Node: ' + self.base_project._id},
'2': {'name': 'Node: ' + self.base_component._id},
'3': {'name': 'Node: ' + self.fork_project._id},
'4': {'name': 'Node: ' + self.fork_component._id},
}),
match_querystring=True,
)
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:57,代码来源:migrate_piwik_derived_nodes.py
示例12: activate_responses
def activate_responses(request):
responses.start()
def fin():
responses.reset()
responses.stop()
request.addfinalizer(fin)
开发者ID:adusca,项目名称:treeherder,代码行数:9,代码来源:conftest.py
示例13: test_hook_is_found_and_checksum_passes___hook_is_saved
def test_hook_is_found_and_checksum_passes___hook_is_saved(self, name, content, hook_type):
self.set_existing_search_response(name, content, hook_type)
responses.start()
with FakeRepoDir():
sys.argv = ['foo', 'install', hook_type, name]
cmd.Hooks().run()
with open(os.path.join(repo.hook_type_directory(hook_type), name)) as f:
self.assertEqual(content, f.read())
开发者ID:wildfish,项目名称:git-hooks,代码行数:10,代码来源:test_cmd.py
示例14: 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
示例15: 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
示例16: mock_responses
def mock_responses(request):
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']
responses.start()
responses.add_callback(responses.GET,
re.compile('.*'),
callback=callback)
request.addfinalizer(responses.stop)
开发者ID:avengerpenguin,项目名称:doyoulikeit,代码行数:12,代码来源:test_views_likes.py
示例17: responses
def responses(request):
"""
Set up the `responses` module for mocking HTTP requests
https://github.com/getsentry/responses
"""
resp_module.start()
def done():
resp_module.stop()
resp_module.reset()
request.addfinalizer(done)
开发者ID:singingwolfboy,项目名称:flask-dance,代码行数:13,代码来源:conftest.py
示例18: 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
示例19: setup_module
def setup_module():
with open(os.path.join(HERE, 'response.json'), 'r') as fp:
response_body = fp.read()
responses.add(
responses.GET,
'http://pypi.python.org/pypi/webargs/json',
body=response_body,
content_type='application/json'
)
responses.add(
responses.GET,
'http://pypi.python.org/pypi/nope/json',
status=404
)
responses.start()
开发者ID:sloria,项目名称:pipstat,代码行数:15,代码来源:test_package.py
示例20: setUp
def setUp(self):
super(AkismetFormTests, self).setUp()
responses.start()
# reset Akismet client verification for each test
AkismetTestForm.akismet_client._verified = None
self.request = self.rf.get(
'/',
REMOTE_ADDR=self.remote_addr,
HTTP_USER_AGENT=self.http_user_agent,
HTTP_REFERER=self.http_referer,
)
Flag.objects.update_or_create(
name=SPAM_CHECKS_FLAG,
defaults={'everyone': True},
)
开发者ID:2015xray,项目名称:kuma,代码行数:15,代码来源:test_forms.py
注:本文中的responses.start函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论