本文整理汇总了Python中responses.calls方法的典型用法代码示例。如果您正苦于以下问题:Python responses.calls方法的具体用法?Python responses.calls怎么用?Python responses.calls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类responses
的用法示例。
在下文中一共展示了responses.calls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_register_dynamic_client_if_client_registration_info_is_given
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_should_register_dynamic_client_if_client_registration_info_is_given(self):
registration_endpoint = self.PROVIDER_BASEURL + '/register'
responses.add(responses.POST, registration_endpoint, json={'client_id': 'client1', 'client_secret': 'secret1'})
provider_config = ProviderConfiguration(
provider_metadata=self.provider_metadata(registration_endpoint=registration_endpoint),
client_registration_info=ClientRegistrationInfo())
extra_args = {'extra_args': 'should be passed'}
redirect_uris = ['https://client.example.com/redirect']
provider_config.register_client(redirect_uris, extra_args)
assert provider_config._client_metadata['client_id'] == 'client1'
assert provider_config._client_metadata['client_secret'] == 'secret1'
assert provider_config._client_metadata['redirect_uris'] == redirect_uris
expected_registration_request = {'redirect_uris': redirect_uris}
expected_registration_request.update(extra_args)
assert json.loads(responses.calls[0].request.body.decode('utf-8')) == expected_registration_request
示例2: test_interest_form_post_triggers_slack_notification
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_interest_form_post_triggers_slack_notification(self, testapp):
''' A valid interest form post triggers a Slack notification.
'''
# set a fake Slack webhook URL
fake_webhook_url = 'http://webhook.example.com/'
current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url
# create a mock to receive POST requests to that URL
responses.add(responses.POST, fake_webhook_url, status=200)
# post an interest form submission
testapp.post("/interest/", params=dict(name="Jean Weaver", agency="Clinton Police Department", location="Clinton, OK", phone="580-970-3338", email="jean.weaver@example.com", comments="I'm interested in Comport as an open-source tool!"))
# test the captured post payload
post_body = json.loads(responses.calls[0].request.body)
assert 'New Interest Form Submission!' in post_body['text']
# delete the fake Slack webhook URL
del(current_app.config['SLACK_WEBHOOK_URL'])
# reset the mock
responses.reset()
示例3: test_extract_link
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_extract_link(self):
success_response = {'success': True, 'data': 'link'}
responses.add(responses.POST, constants.ENDPOINTS['extract_link'],
json=success_response,
status=200)
responses.add(responses.POST, constants.ENDPOINTS['extract_link'],
status=401)
# success call
result = utils.extract_link(self.session, 'https://www.ojbk.com')
self.assertEqual(result, 'link')
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].request.url, constants.ENDPOINTS['extract_link'])
self.assertEqual(responses.calls[0].response.json(), success_response)
# failed call
with self.assertRaises(requests.HTTPError) as cm:
utils.extract_link(self.session, 'https://www.ojbk.com')
self.assertEqual(len(responses.calls), 2)
self.assertEqual(cm.exception.response.status_code, 401)
示例4: test_get_uptoken
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_get_uptoken(self):
params = {'bucket': 'jike'}
success_reponse = {'uptoken': 'token'}
responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
json=success_reponse, status=200)
responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
status=404)
# success call
result = utils.get_uptoken()
self.assertEqual(result, 'token')
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].request.url,
constants.ENDPOINTS['picture_uptoken'] + '?' + urlencode(params))
self.assertEqual(responses.calls[0].response.json(), success_reponse)
# failed call
with self.assertRaises(requests.HTTPError) as cm:
utils.get_uptoken()
self.assertEqual(len(responses.calls), 2)
self.assertEqual(cm.exception.response.status_code, 404)
示例5: test_address
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_address(self):
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_address-00-get_accounts.json'),
status=200)
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_address-10-getaddress.json'),
status=200)
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_address-10-getaddress.json'),
status=200)
self.wallet = Wallet(JSONRPCWallet())
waddr = self.wallet.address()
a0addr = self.wallet.accounts[0].address()
self.assertEqual(len(responses.calls), 3)
self.assertEqual(waddr, a0addr)
self.assertIsInstance(waddr, Address)
self.assertEqual(
waddr,
'596ETuuDVZSNox73YLctrHaAv72fBboxy3atbEMnP3QtdnGFS9KWuHYGuy831SKWLUVCgrRfWLCxuCZ2fbVGh14X7mFrefy')
self.assertEqual(waddr.label, 'Primary account')
self.assertEqual(a0addr.label, 'Primary account')
示例6: test_request_made
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_request_made(self):
responses.add(responses.GET, 'https://example.com', status=200)
donation = Donation.objects.create(
timereceived=datetime.datetime(2018, 1, 1),
comment='',
amount=Decimal(1.5),
domain='PAYPAL',
donor=self.donor,
event=self.event,
)
eventutil.post_donation_to_postbacks(donation)
assert len(responses.calls) == 1
assert (
responses.calls[0].request.url
== 'https://example.com/?comment=&amount=1.5&timereceived=2018-01-01+00%3A00%3A00&donor__visibility=FIRST&domain=PAYPAL&id=1&donor__visiblename=%28No+Name%29'
)
assert responses.calls[0].response.status_code == 200
示例7: test_context_manager
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_context_manager():
testutil.add_response("login_response_200")
testutil.add_response("query_response_200")
testutil.add_response("logout_response_200")
client_args = {
"username": testutil.username,
"password": testutil.password,
"client_id": testutil.client_id,
"client_secret": testutil.client_secret,
"version": "37.0"}
with sfdc.client(**client_args) as client:
client.query("SELECT Id, Name FROM Account LIMIT 10")
"""
The above should have made 3 calls: login, query, logout
"""
assert len(responses.calls) == 3
示例8: test_context_manager_negative
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_context_manager_negative():
testutil.add_response("login_response_200")
testutil.add_response("query_response_200")
client_args = {
"username": testutil.username,
"password": testutil.password,
"client_id": testutil.client_id,
"client_secret": testutil.client_secret,
"version": "37.0"}
def logout():
raise Exception("Monkey patchin'...")
with sfdc.client(**client_args) as client:
client.query("SELECT Id, Name FROM Account LIMIT 10")
client.logout = logout
"""
The above should have made 2 calls: login, query
"""
assert len(responses.calls) == 2
示例9: test_los_angeles
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_los_angeles(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/timezone/json",
body='{"status":"OK"}',
status=200,
content_type="application/json",
)
ts = 1331766000
timezone = self.client.timezone((39.603481, -119.682251), ts)
self.assertIsNotNone(timezone)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/timezone/json"
"?location=39.603481,-119.682251×tamp=%d"
"&key=%s" % (ts, self.key),
responses.calls[0].request.url,
)
示例10: test_los_angeles_with_no_timestamp
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_los_angeles_with_no_timestamp(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/timezone/json",
body='{"status":"OK"}',
status=200,
content_type="application/json",
)
timezone = self.client.timezone((39.603481, -119.682251))
self.assertIsNotNone(timezone)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/timezone/json"
"?location=39.603481,-119.682251×tamp=%d"
"&key=%s" % (1608, self.key),
responses.calls[0].request.url,
)
示例11: test_simple_geolocate
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_simple_geolocate(self):
responses.add(
responses.POST,
"https://www.googleapis.com/geolocation/v1/geolocate",
body='{"location": {"lat": 51.0,"lng": -0.1},"accuracy": 1200.4}',
status=200,
content_type="application/json",
)
results = self.client.geolocate()
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://www.googleapis.com/geolocation/v1/geolocate?" "key=%s" % self.key,
responses.calls[0].request.url,
)
示例12: test_autocomplete_query
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_autocomplete_query(self):
url = "https://maps.googleapis.com/maps/api/place/queryautocomplete/json"
responses.add(
responses.GET,
url,
body='{"status": "OK", "predictions": []}',
status=200,
content_type="application/json",
)
self.client.places_autocomplete_query("pizza near New York")
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?input=pizza+near+New+York&key=%s" % (url, self.key),
responses.calls[0].request.url,
)
示例13: test_elevation_single
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_elevation_single(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/elevation/json",
body='{"status":"OK","results":[]}',
status=200,
content_type="application/json",
)
results = self.client.elevation((40.714728, -73.998672))
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/elevation/json?"
"locations=enc:abowFtzsbM&key=%s" % self.key,
responses.calls[0].request.url,
)
示例14: test_elevation_multiple
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_elevation_multiple(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/elevation/json",
body='{"status":"OK","results":[]}',
status=200,
content_type="application/json",
)
locations = [(40.714728, -73.998672), (-34.397, 150.644)]
results = self.client.elevation(locations)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/elevation/json?"
"locations=enc:abowFtzsbMhgmiMuobzi@&key=%s" % self.key,
responses.calls[0].request.url,
)
示例15: test_elevation_along_path
# 需要导入模块: import responses [as 别名]
# 或者: from responses import calls [as 别名]
def test_elevation_along_path(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/elevation/json",
body='{"status":"OK","results":[]}',
status=200,
content_type="application/json",
)
path = [(40.714728, -73.998672), (-34.397, 150.644)]
results = self.client.elevation_along_path(path, 5)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/elevation/json?"
"path=enc:abowFtzsbMhgmiMuobzi@&"
"key=%s&samples=5" % self.key,
responses.calls[0].request.url,
)