本文整理汇总了Python中responses.start函数的典型用法代码示例。如果您正苦于以下问题:Python start函数的具体用法?Python start怎么用?Python start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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
示例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()
示例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()
示例5: setUp
def setUp(self):
super(AkismetClientTests, self).setUp()
responses.start()
Flag.objects.update_or_create(
name=SPAM_CHECKS_FLAG,
defaults={'everyone': True},
)
示例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()
示例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())
示例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
示例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)))
示例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()
示例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,
)
示例12: activate_responses
def activate_responses(request):
responses.start()
def fin():
responses.reset()
responses.stop()
request.addfinalizer(fin)
示例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())
示例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()
示例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()