當前位置: 首頁>>代碼示例>>Python>>正文


Python HttpClient.get_next_message方法代碼示例

本文整理匯總了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)
開發者ID:raiderrobert,項目名稱:channels,代碼行數:33,代碼來源:test_binding.py

示例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)
開發者ID:raiderrobert,項目名稱:channels,代碼行數:23,代碼來源:test_binding.py

示例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')
開發者ID:raiderrobert,項目名稱:channels,代碼行數:24,代碼來源:test_binding.py


注:本文中的channels.tests.HttpClient.get_next_message方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。