本文整理汇总了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')