def ready(self): if not apps.is_installed('debug_toolbar'): return # patch routes: adding debug routes to default layer for route in routes.debug_channel_routes: channel_layers[DEFAULT_CHANNEL_LAYER].router.add_route(route) # patch layers: substitution by debug layer with events monitoring for alias in getattr(settings, "CHANNEL_LAYERS", {}).keys(): new_backend = layer_factory(channel_layers[alias], alias) channel_layers.set(alias, new_backend) # patch routes: wrap routes debug decorator for alias in getattr(settings, "CHANNEL_LAYERS", {}).keys(): _match = channel_layers[alias].router.root.match def new_match(message): if in_debug(message.channel.name): m = _match(message) if m and not is_no_debug(m[0]): return debug_decorator(m[0], alias), m[1] return _match(message) channel_layers[alias].router.root.match = new_match
def tearDown(self): """ Undoes the channel rerouting """ for alias in self.test_channel_aliases: # Swap in an in memory layer wrapper and keep the old one around channel_layers.set(alias, self._old_layers[alias]) del self._old_layers super(ChannelTestCase, self).tearDown()
def setUp(self): import channels.log self.stream = StringIO() channels.log.handler = logging.StreamHandler(self.stream) BindingMetaclass.binding_classes = [] self._old_layer = channel_layers.set( 'fake_channel', ChannelLayerWrapper( FakeChannelLayer(), 'fake_channel', channel_layers['fake_channel'].routing[:], ))
def setUp(self): import channels.log self.stream = StringIO() channels.log.handler = logging.StreamHandler(self.stream) BindingMetaclass.binding_classes = [] self._old_layer = channel_layers.set( 'fake_channel', ChannelLayerWrapper( FakeChannelLayer(), 'fake_channel', channel_layers['fake_channel'].routing[:], ) )
def setUp(self): """ Initialises in memory channel layer for the duration of the test """ super(ChannelTestCase, self).setUp() self._old_layers = {} for alias in self.test_channel_aliases: # Swap in an in memory layer wrapper and keep the old one around self._old_layers[alias] = channel_layers.set( alias, ChannelLayerWrapper( InMemoryChannelLayer(), alias, channel_layers[alias].routing, ))
def setUp(self): """ Initialises in memory channel layer for the duration of the test """ super(ChannelTestCase, self).setUp() self._old_layers = {} for alias in self.test_channel_aliases: # Swap in an in memory layer wrapper and keep the old one around self._old_layers[alias] = channel_layers.set( alias, ChannelLayerWrapper( InMemoryChannelLayer(), alias, channel_layers[alias].routing, ) )
def tearDown(self): channel_layers.set('fake_channel', self._old_layer)