mirror of
https://github.com/django/daphne.git
synced 2025-07-12 08:52:18 +03:00
Set self.kwargs in Binding.trigger_inbound when setting self.message (#541)
Allows options passed in (like a consumer) to be accessible to further code.
This commit is contained in:
parent
863b1cebdd
commit
7ab21c4846
|
@ -214,6 +214,7 @@ class Binding(object):
|
|||
from django.contrib.auth.models import AnonymousUser
|
||||
self = cls()
|
||||
self.message = message
|
||||
self.kwargs = kwargs
|
||||
# Deserialize message
|
||||
self.action, self.pk, self.data = self.deserialize(self.message)
|
||||
self.user = getattr(self.message, "user", AnonymousUser())
|
||||
|
|
|
@ -349,3 +349,29 @@ class TestsBinding(ChannelTestCase):
|
|||
|
||||
self.assertIsNone(User.objects.filter(pk=user.pk).first())
|
||||
self.assertIsNone(client.receive())
|
||||
|
||||
def test_route_params_saved_in_kwargs(self):
|
||||
|
||||
class UserBinding(WebsocketBinding):
|
||||
model = User
|
||||
stream = 'users'
|
||||
fields = ['username', 'email', 'password', 'last_name']
|
||||
|
||||
@classmethod
|
||||
def group_names(cls, instance):
|
||||
return ['users_outbound']
|
||||
|
||||
def has_permission(self, user, action, pk):
|
||||
return True
|
||||
|
||||
class Demultiplexer(WebsocketDemultiplexer):
|
||||
consumers = {
|
||||
'users': UserBinding.consumer,
|
||||
}
|
||||
|
||||
groups = ['inbound']
|
||||
|
||||
with apply_routes([Demultiplexer.as_route(path='/path/(?P<id>\d+)')]):
|
||||
client = HttpClient()
|
||||
consumer = client.send_and_consume('websocket.connect', path='/path/789')
|
||||
self.assertEqual(consumer.kwargs['id'], '789')
|
||||
|
|
Loading…
Reference in New Issue
Block a user