mirror of
https://github.com/django/daphne.git
synced 2025-04-21 17:22:03 +03:00
Fix new routing channel name collector and add test
This commit is contained in:
parent
0071ca31c8
commit
a563d4353f
|
@ -141,7 +141,7 @@ class Route(object):
|
|||
"""
|
||||
Returns the channel names this route listens on
|
||||
"""
|
||||
return self.channel
|
||||
return {self.channel,}
|
||||
|
||||
def __str__(self):
|
||||
return "%s %s -> %s" % (
|
||||
|
@ -204,7 +204,7 @@ class Include(object):
|
|||
"""
|
||||
result = set()
|
||||
for entry in self.routing:
|
||||
result.union(entry.channel_names())
|
||||
result.update(entry.channel_names())
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -281,3 +281,24 @@ class RoutingTests(SimpleTestCase):
|
|||
consumer=consumer_2,
|
||||
kwargs={"version": "2", "room": "django"},
|
||||
)
|
||||
|
||||
def test_channels(self):
|
||||
"""
|
||||
Tests that the router reports channels to listen on correctly
|
||||
"""
|
||||
router = Router([
|
||||
route("http.request", consumer_1, path=r"^/chat/$"),
|
||||
route("http.disconnect", consumer_2),
|
||||
route("http.request", consumer_3),
|
||||
])
|
||||
# Initial check
|
||||
self.assertEqual(
|
||||
router.channels,
|
||||
{"http.request", "http.disconnect"},
|
||||
)
|
||||
# Dynamically add route, recheck
|
||||
router.add_route(route("websocket.receive", consumer_1))
|
||||
self.assertEqual(
|
||||
router.channels,
|
||||
{"http.request", "http.disconnect", "websocket.receive"},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user