本文整理匯總了Python中channels.tests.HttpClient.get_next_message方法的典型用法代碼示例。如果您正苦於以下問題:Python HttpClient.get_next_message方法的具體用法?Python HttpClient.get_next_message怎麽用?Python HttpClient.get_next_message使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類channels.tests.HttpClient
的用法示例。
在下文中一共展示了HttpClient.get_next_message方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_demultiplexer_without_payload_and_steam
# 需要導入模塊: from channels.tests import HttpClient [as 別名]
# 或者: from channels.tests.HttpClient import get_next_message [as 別名]
def test_demultiplexer_without_payload_and_steam(self):
class Demultiplexer(WebsocketDemultiplexer):
mapping = {
'users': 'binding.users',
}
groups = ['inbound']
with apply_routes([Demultiplexer.as_route(path='/')]):
client = HttpClient()
client.send_and_consume('websocket.connect', path='/')
with self.assertRaises(ValueError) as value_error:
client.send_and_consume('websocket.receive', path='/', text={
'nostream': 'users', 'payload': 'test',
})
self.assertIn('no channel/payload key', value_error.exception.args[0])
message = client.get_next_message('binding.users')
self.assertIsNone(message)
with self.assertRaises(ValueError) as value_error:
client.send_and_consume('websocket.receive', path='/', text={
'stream': 'users',
})
self.assertIn('no channel/payload key', value_error.exception.args[0])
message = client.get_next_message('binding.users')
self.assertIsNone(message)
示例2: test_demultiplexer_with_wrong_payload
# 需要導入模塊: from channels.tests import HttpClient [as 別名]
# 或者: from channels.tests.HttpClient import get_next_message [as 別名]
def test_demultiplexer_with_wrong_payload(self):
class Demultiplexer(WebsocketDemultiplexer):
mapping = {
'users': 'binding.users',
}
groups = ['inbound']
with apply_routes([Demultiplexer.as_route(path='/')]):
client = HttpClient()
client.send_and_consume('websocket.connect', path='/')
with self.assertRaises(ValueError) as value_error:
client.send_and_consume('websocket.receive', path='/', text={
'stream': 'users', 'payload': 'test',
})
self.assertEqual(value_error.exception.args[0], 'Multiplexed frame payload is not a dict')
message = client.get_next_message('binding.users')
self.assertIsNone(message)
示例3: test_demultiplexer
# 需要導入模塊: from channels.tests import HttpClient [as 別名]
# 或者: from channels.tests.HttpClient import get_next_message [as 別名]
def test_demultiplexer(self):
class Demultiplexer(WebsocketDemultiplexer):
mapping = {
'users': 'binding.users',
}
groups = ['inbound']
with apply_routes([Demultiplexer.as_route(path='/')]):
client = HttpClient()
client.send_and_consume('websocket.connect', path='/')
# assert in group
Group('inbound').send({'text': json.dumps({'test': 'yes'})}, immediately=True)
self.assertEqual(client.receive(), {'test': 'yes'})
# assert that demultiplexer stream message
client.send_and_consume('websocket.receive', path='/',
text={'stream': 'users', 'payload': {'test': 'yes'}})
message = client.get_next_message('binding.users')
self.assertIsNotNone(message)
self.assertEqual(message.content['test'], 'yes')