From a563d4353f44dce032ed8aad3bc6ef7ae2467190 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 4 Apr 2016 00:24:58 +0200 Subject: [PATCH] Fix new routing channel name collector and add test --- channels/routing.py | 4 ++-- channels/tests/test_routing.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/channels/routing.py b/channels/routing.py index 41ab0b0..0806bd5 100644 --- a/channels/routing.py +++ b/channels/routing.py @@ -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 diff --git a/channels/tests/test_routing.py b/channels/tests/test_routing.py index 5605175..bfc44cd 100644 --- a/channels/tests/test_routing.py +++ b/channels/tests/test_routing.py @@ -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"}, + )