本文整理汇总了Python中httpretty.last_request方法的典型用法代码示例。如果您正苦于以下问题:Python httpretty.last_request方法的具体用法?Python httpretty.last_request怎么用?Python httpretty.last_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httpretty
的用法示例。
在下文中一共展示了httpretty.last_request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_command_token
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_command_token(self):
"""Test if autogender is called with token parameter"""
setup_genderize_server()
code = self.cmd.run('--api-token', 'abcdefghi')
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, PROFILE_AUTOGENDER)
expected = {
'name': ['john'],
'apikey': ['abcdefghi']
}
req = httpretty.last_request()
self.assertEqual(req.querystring, expected)
示例2: test_genderize
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_genderize(self):
"""Test if the gender of a name is obtained"""
setup_genderize_server()
gender, acc = genderize('John')
self.assertEqual(gender, 'male')
self.assertEqual(acc, 99)
expected = {
'name': ['John']
}
req = httpretty.last_request()
self.assertEqual(req.method, 'GET')
self.assertEqual(req.querystring, expected)
示例3: test_name_not_found
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_name_not_found(self):
"""Test if a null response is returned when the name is not found"""
setup_genderize_server()
gender, acc = genderize('Jack')
self.assertEqual(gender, None)
self.assertEqual(acc, None)
expected = {
'name': ['Jack']
}
req = httpretty.last_request()
self.assertEqual(req.method, 'GET')
self.assertEqual(req.querystring, expected)
示例4: test_request_format
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_request_format(self):
httpretty.register_uri(httpretty.GET, self.test_url, body='{}')
response = self.client.get(self.test_endpoint)
self.assertEqual(httpretty.last_request().headers['Accept'], 'application/json')
self.assertDictEqual(response, {})
httpretty.register_uri(httpretty.GET, self.test_url, body='not-json')
response = self.client.get(self.test_endpoint, data_format=data_formats.CSV)
self.assertEqual(httpretty.last_request().headers['Accept'], 'text/csv')
self.assertEqual(response, 'not-json')
httpretty.register_uri(httpretty.GET, self.test_url, body='{}')
response = self.client.get(self.test_endpoint, data_format=data_formats.JSON)
self.assertEqual(httpretty.last_request().headers['Accept'], 'application/json')
self.assertDictEqual(response, {})
示例5: test_send_key_with_file
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_send_key_with_file(self):
driver = android_w3c_driver()
# Should not send this file
tmp_f = tempfile.NamedTemporaryFile()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element/element_id/value')
)
try:
element = MobileWebElement(driver, 'element_id', w3c=True)
element.send_keys(tmp_f.name)
finally:
tmp_f.close()
d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])
示例6: test_find_element_by_android_data_matcher
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_find_element_by_android_data_matcher(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element'),
body='{"value": {"element-6066-11e4-a52e-4f735466cecf": "element-id"}}'
)
el = driver.find_element_by_android_data_matcher(
name='title', args=['title', 'Animation'], className='class name')
d = get_httpretty_request_body(httpretty.last_request())
assert d['using'] == '-android datamatcher'
value_dict = json.loads(d['value'])
assert value_dict['args'] == ['title', 'Animation']
assert value_dict['name'] == 'title'
assert value_dict['class'] == 'class name'
assert el.id == 'element-id'
示例7: test_find_elements_by_android_data_matcher
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_find_elements_by_android_data_matcher(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/elements'),
body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "element-id2"}]}'
)
els = driver.find_elements_by_android_data_matcher(name='title', args=['title', 'Animation'])
d = get_httpretty_request_body(httpretty.last_request())
assert d['using'] == '-android datamatcher'
value_dict = json.loads(d['value'])
assert value_dict['args'] == ['title', 'Animation']
assert value_dict['name'] == 'title'
assert els[0].id == 'element-id1'
assert els[1].id == 'element-id2'
示例8: test_providing_res_with_url_calls_datapusher_correctly
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_providing_res_with_url_calls_datapusher_correctly(self):
config['datapusher.url'] = 'http://datapusher.ckan.org'
httpretty.HTTPretty.register_uri(
httpretty.HTTPretty.POST,
'http://datapusher.ckan.org/job',
content_type='application/json',
body=json.dumps({'job_id': 'foo', 'job_key': 'bar'}))
package = model.Package.get('annakarenina')
tests.call_action_api(
self.app,
'datastore_create',
apikey=self.sysadmin_user.apikey,
resource=dict(package_id=package.id, url='demo.ckan.org')
)
assert len(package.resources) == 4, len(package.resources)
resource = package.resources[3]
data = json.loads(httpretty.last_request().body)
assert data['metadata']['resource_id'] == resource.id, data
assert not data['metadata'].get('ignore_hash'), data
assert data['result_url'].endswith('/action/datapusher_hook'), data
assert data['result_url'].startswith('http://'), data
示例9: test_pass_the_received_ignore_hash_param_to_the_datapusher
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_pass_the_received_ignore_hash_param_to_the_datapusher(self):
config['datapusher.url'] = 'http://datapusher.ckan.org'
httpretty.HTTPretty.register_uri(
httpretty.HTTPretty.POST,
'http://datapusher.ckan.org/job',
content_type='application/json',
body=json.dumps({'job_id': 'foo', 'job_key': 'bar'}))
package = model.Package.get('annakarenina')
resource = package.resources[0]
tests.call_action_api(
self.app, 'datapusher_submit', apikey=self.sysadmin_user.apikey,
resource_id=resource.id,
ignore_hash=True
)
data = json.loads(httpretty.last_request().body)
assert data['metadata']['ignore_hash'], data
示例10: setup_http_server
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def setup_http_server():
url_projects = read_file(URL_PROJECTS_FILE)
http_requests = []
def request_callback(method, uri, headers):
last_request = httpretty.last_request()
body = url_projects
http_requests.append(last_request)
return 200, headers, body
httpretty.register_uri(httpretty.GET,
PROJECTS_URL,
responses=[
httpretty.Response(body=request_callback)
])
return http_requests
示例11: setup_http_server
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def setup_http_server():
remote_identities = read_file(REMOTE_IDENTITIES_FILE)
http_requests = []
def request_callback(method, uri, headers):
last_request = httpretty.last_request()
if uri.startswith(REMOTE_IDENTITIES_FILE_URL):
body = remote_identities
http_requests.append(last_request)
return 200, headers, body
httpretty.register_uri(httpretty.GET,
REMOTE_IDENTITIES_FILE_URL,
responses=[
httpretty.Response(body=request_callback)
])
return http_requests
示例12: because_an_event_is_published_on_a_stream
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def because_an_event_is_published_on_a_stream(self):
httpretty.register_uri(
httpretty.POST,
"http://{}:{}/streams/{}".format(self._host, self._port, self.stream),
body='{}')
data = {'foo': 'bar'}
metadata = {'lorem': 'ipsum'}
evt = Event(
id=self.event_id,
type='my-event-type',
data=data,
stream=self.stream,
sequence=None,
metadata=metadata,
)
self.publisher.post(evt, correlation_id=self.correlation_id)
self.response_body = json.loads(httpretty.last_request().body.decode())[0]
示例13: test_disable_api_key
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_disable_api_key(mocked_url, mocked_owner_apikey, mocked_owner_apikey_id,
mocked_account_resource_id, capsys):
api_key_id = str(uuid.uuid4())
mocked_url.return_value = '', MOCK_API_URL
mocked_owner_apikey.return_value = str(uuid.uuid4())
mocked_owner_apikey_id.return_value = str(uuid.uuid4())
mocked_account_resource_id.return_value = str(uuid.uuid4())
httpretty.register_uri(httpretty.PATCH, MOCK_API_URL,
status=200,
content_type='application/json',
body=json.dumps({}))
api.update(api_key_id, False)
out, err = capsys.readouterr()
assert {'apikey': {'active': False}} == json.loads(httpretty.last_request().body)
assert not err
assert 'Disabled api key with id: %s' % api_key_id in out
示例14: test_enable_api_key
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_enable_api_key(mocked_url, mocked_owner_apikey, mocked_owner_apikey_id,
mocked_account_resource_id, capsys):
api_key_id = str(uuid.uuid4())
mocked_url.return_value = '', MOCK_API_URL
mocked_owner_apikey.return_value = str(uuid.uuid4())
mocked_owner_apikey_id.return_value = str(uuid.uuid4())
mocked_account_resource_id.return_value = str(uuid.uuid4())
httpretty.register_uri(httpretty.PATCH, MOCK_API_URL,
status=200,
content_type='application/json',
body=json.dumps({}))
api.update(api_key_id, True)
out, err = capsys.readouterr()
assert {'apikey': {'active': True}} == json.loads(httpretty.last_request().body)
assert not err
assert 'Enabled api key with id: %s' % api_key_id in out
示例15: test_patch_saved_query_none_fields
# 需要导入模块: import httpretty [as 别名]
# 或者: from httpretty import last_request [as 别名]
def test_patch_saved_query_none_fields(mocked_url, mocked_rw_apikey, mocked_account_resource_id,
capsys):
test_saved_query_id = str(uuid.uuid4())
mocked_url.return_value = '', MOCK_API_URL
mocked_rw_apikey.return_value = str(uuid.uuid4())
mocked_account_resource_id.return_value = str(uuid.uuid4())
httpretty.register_uri(httpretty.PATCH, MOCK_API_URL, status=200,
content_type='application/json',
body=json.dumps({"saved_query": SAVED_QUERY_RESPONSE}))
api.update_saved_query(test_saved_query_id, name=None,
statement="new_statement")
out, err = capsys.readouterr()
assert "Saved query with id %s updated" % test_saved_query_id in out
body = json.loads(httpretty.last_request().body)['saved_query']
assert "name" not in body
assert "statement" in body['leql']