本文整理汇总了Python中pulsar.apps.http.HttpClient.get方法的典型用法代码示例。如果您正苦于以下问题:Python HttpClient.get方法的具体用法?Python HttpClient.get怎么用?Python HttpClient.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulsar.apps.http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_verify(self):
c = HttpClient()
yield from self.async.assertRaises(SSLError, c.get, self.httpbin())
response = yield from c.get(self.httpbin(), verify=False)
self.assertEqual(response.status_code, 200)
response = yield from c.get(self.httpbin(), verify=crt)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request.verify, crt)
示例2: test_home
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_home(self):
http = HttpClient()
response = yield from http.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers['content-type'],
'text/html; charset=utf-8')
cookie = response.cookies.get('luxtest')
self.assertTrue(cookie)
self.assertTrue(cookie.value)
response = yield from http.get(self.url)
cookie2 = response.cookies.get('luxtest')
self.assertFalse(cookie2)
示例3: testBadRequests
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def testBadRequests(self):
c = HttpClient()
response = yield c.post(self.ws_uri)
self.assertEqual(response.status_code, 405)
#
response = yield c.get(self.ws_uri,
headers=[('Sec-Websocket-Key', 'x')])
self.assertEqual(response.status_code, 400)
#
response = yield c.get(self.ws_uri,
headers=[('Sec-Websocket-Key', 'bla')])
self.assertEqual(response.status_code, 400)
#
response = yield c.get(self.ws_uri,
headers=[('Sec-Websocket-version', 'xxx')])
self.assertEqual(response.status_code, 400)
示例4: test_graph
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_graph(self):
c = HttpClient()
handler = Echo(c._loop)
ws = yield c.get(self.ws_uri, websocket_handler=handler)
self.assertEqual(ws.event('post_request').fired(), 0)
message = yield handler.get()
self.assertTrue(message)
示例5: test_login
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_login(self):
http = HttpClient()
url = self.url + self.app.config['LOGIN_URL']
response = yield from http.get(url)
cookie = response.cookies.get('luxtest')
self.assertTrue(cookie)
self.assertEqual(response.status_code, 200)
doc = self.bs(response)
token = self.authenticity_token(doc)
self.assertEqual(len(token), 1)
# try to login
data = {'username': 'pippo', 'password': 'pluto'}
response2 = yield from http.post(url, data=data)
self.assertEqual(response2.status_code, 403)
#
# Add csrf token
data.update(token)
response2 = yield from http.post(url, data=data)
self.assertEqual(response2.status_code, 200)
cookie2 = response2.cookies.get('luxtest')
self.assertTrue(cookie2)
self.assertNotEqual(cookie2.value, cookie.value)
self.assertEqual(response2.headers['content-type'],
'application/json; charset=utf-8')
data = response2.json()
self.assertTrue('redirect' in data)
self.assertEqual(data['success'], True)
#
# Login again should cause MethodNotAllowed
response3 = yield from http.post(url, data=data)
self.assertEqual(response3.status_code, 405)
示例6: test_pong
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_pong(self):
c = HttpClient()
handler = Echo()
ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
#
ws.ping('TESTING CLIENT PING')
message = yield handler.get()
self.assertEqual(message, 'PONG: TESTING CLIENT PING')
示例7: test_ping
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_ping(self):
c = HttpClient()
handler = Echo()
ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
#
# ASK THE SERVER TO SEND A PING FRAME
ws.write('send ping TESTING PING')
message = yield handler.get()
self.assertEqual(message, 'PING: TESTING PING')
示例8: test_dodgy_on_header_event
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_dodgy_on_header_event(self):
client = HttpClient()
hook = partial(dodgyhook, self)
response = client.get(self.httpbin(), on_headers=hook)
try:
yield response.on_finished
except ValueError:
pass
self.assertTrue(response.headers)
self.assertIsInstance(response.on_headers.result, Failure)
示例9: test_close
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_close(self):
c = HttpClient()
handler = Echo()
ws = yield c.get(self.ws_echo, websocket_handler=handler)
self.assertEqual(ws.event('post_request').fired(), 0)
ws.write('send close 1001')
message = yield handler.get()
self.assertEqual(message, 'CLOSE')
self.assertTrue(ws.close_reason)
self.assertEqual(ws.close_reason[0], 1001)
self.assertTrue(ws._connection.closed)
示例10: test_close_sync
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_close_sync(self):
loop = new_event_loop()
c = HttpClient(loop=loop)
handler = Echo(loop)
ws = c.get(self.ws_echo, websocket_handler=handler)
self.assertEqual(ws.event('post_request').fired(), 0)
self.assertEqual(ws._loop, loop)
self.assertFalse(ws._loop.is_running())
ws.write('send close 1001')
message = ws._loop.run_until_complete(handler.get())
self.assertEqual(message, 'CLOSE')
self.assertTrue(ws.close_reason)
self.assertEqual(ws.close_reason[0], 1001)
self.assertTrue(ws._connection.closed)
示例11: test_upgrade
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_upgrade(self):
c = HttpClient()
handler = Echo()
ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
response = ws.handshake
self.assertEqual(response.status_code, 101)
self.assertEqual(response.headers['upgrade'], 'websocket')
self.assertEqual(ws.connection, response.connection)
self.assertEqual(ws.handler, handler)
#
# on_finished
self.assertFalse(response.on_finished.done())
self.assertFalse(ws.on_finished.done())
# Send a message to the websocket
ws.write('Hi there!')
message = yield handler.get()
self.assertEqual(message, 'Hi there!')
示例12: media_libraries
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def media_libraries():
global _media_libraries
if _media_libraries is None:
if os.path.isfile('libs.json'): # pragma nocover
with open('libs.json') as f:
data = f.read()
_media_libraries = json.loads(data)
else:
from pulsar import new_event_loop
from pulsar.apps.http import HttpClient
http = HttpClient(loop=new_event_loop())
try:
response = http.get(_libs_url)
_media_libraries = response.json()
except Exception: # pragma nocover
http.logger.error('Could not import media library',
exc_info=True)
_media_libraries = {'libs': {}, 'deps': {}}
return _media_libraries
示例13: test_home
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_home(self):
c = HttpClient()
response = yield c.get(self.uri)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers['content-type'],
'text/html; charset=utf-8')
示例14: test_404
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_404(self):
http = HttpClient()
url = self.url + '/dkvshcvsdkchsdkc'
response = yield from http.get(url)
self.assertEqual(response.status_code, 404)
示例15: test_reset_password
# 需要导入模块: from pulsar.apps.http import HttpClient [as 别名]
# 或者: from pulsar.apps.http.HttpClient import get [as 别名]
def test_reset_password(self):
http = HttpClient()
url = self.url + self.app.config['RESET_PASSWORD_URL']
response = yield from http.get(url)
self.assertEqual(response.status_code, 200)