Fix new routing channel name collector and add test

This commit is contained in:
Andrew Godwin 2016-04-04 00:24:58 +02:00
parent 0071ca31c8
commit a563d4353f
2 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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"},
)