mirror of
https://github.com/django/daphne.git
synced 2025-04-20 08:42:18 +03:00
parent
e6236f79e6
commit
7de6ff17d6
|
@ -62,6 +62,31 @@ and post the square of it to the ``"result"`` channel::
|
|||
self.assertEqual(result['value'], 1089)
|
||||
|
||||
|
||||
Generic Consumers
|
||||
-----------------
|
||||
|
||||
You can use ``ChannelTestCase`` to test generic consumers as well. Just pass the message
|
||||
object from ``get_next_message`` to the constructor of the class. To test replies to a specific channel,
|
||||
use the ``reply_channel`` property on the ``Message`` object. For example::
|
||||
|
||||
from channels import Channel
|
||||
from channels.tests import ChannelTestCase
|
||||
|
||||
from myapp.consumers import MyConsumer
|
||||
|
||||
class MyTests(ChannelTestCase):
|
||||
|
||||
def test_a_thing(self):
|
||||
# Inject a message onto the channel to use in a consumer
|
||||
Channel("input").send({"value": 33})
|
||||
# Run the consumer with the new Message object
|
||||
message = self.get_next_message("input", require=True)
|
||||
MyConsumer(message)
|
||||
# Verify there's a reply and that it's accurate
|
||||
result = self.get_next_message(message.reply_channel.name, require=True)
|
||||
self.assertEqual(result['value'], 1089)
|
||||
|
||||
|
||||
Groups
|
||||
------
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user