本文整理汇总了Python中channels.tests.HttpClient.join_group方法的典型用法代码示例。如果您正苦于以下问题:Python HttpClient.join_group方法的具体用法?Python HttpClient.join_group怎么用?Python HttpClient.join_group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类channels.tests.HttpClient
的用法示例。
在下文中一共展示了HttpClient.join_group方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_trigger_outbound_delete
# 需要导入模块: from channels.tests import HttpClient [as 别名]
# 或者: from channels.tests.HttpClient import join_group [as 别名]
def test_trigger_outbound_delete(self):
class TestBinding(WebsocketBinding):
model = User
stream = 'test'
fields = ['username']
def group_names(self, instance, action):
return ["users3"]
def has_permission(self, user, action, pk):
return True
user = User.objects.create(username='test', email='[email protected]')
with apply_routes([route('test', TestBinding.consumer)]):
client = HttpClient()
client.join_group('users3')
user.delete()
received = client.receive()
self.assertTrue('payload' in received)
self.assertTrue('action' in received['payload'])
self.assertTrue('data' in received['payload'])
self.assertTrue('username' in received['payload']['data'])
self.assertTrue('model' in received['payload'])
self.assertTrue('pk' in received['payload'])
self.assertEqual(received['payload']['action'], 'delete')
self.assertEqual(received['payload']['model'], 'auth.user')
self.assertEqual(received['payload']['pk'], 1)
self.assertEqual(received['payload']['data']['username'], 'test')
received = client.receive()
self.assertIsNone(received)
示例2: test_trigger_outbound_update
# 需要导入模块: from channels.tests import HttpClient [as 别名]
# 或者: from channels.tests.HttpClient import join_group [as 别名]
def test_trigger_outbound_update(self):
class TestBinding(WebsocketBinding):
model = User
stream = 'test'
fields = ['__all__']
@classmethod
def group_names(cls, instance, action):
return ["users2"]
def has_permission(self, user, action, pk):
return True
# Make model and clear out pending sends
user = User.objects.create(username='test', email='[email protected]')
consumer_finished.send(sender=None)
with apply_routes([route('test', TestBinding.consumer)]):
client = HttpClient()
client.join_group('users2')
user.username = 'test_new'
user.save()
consumer_finished.send(sender=None)
received = client.receive()
self.assertTrue('payload' in received)
self.assertTrue('action' in received['payload'])
self.assertTrue('data' in received['payload'])
self.assertTrue('username' in received['payload']['data'])
self.assertTrue('email' in received['payload']['data'])
self.assertTrue('password' in received['payload']['data'])
self.assertTrue('last_name' in received['payload']['data'])
self.assertTrue('model' in received['payload'])
self.assertTrue('pk' in received['payload'])
self.assertEqual(received['payload']['action'], 'update')
self.assertEqual(received['payload']['model'], 'auth.user')
self.assertEqual(received['payload']['pk'], user.pk)
self.assertEqual(received['payload']['data']['email'], '[email protected]')
self.assertEqual(received['payload']['data']['username'], 'test_new')
self.assertEqual(received['payload']['data']['password'], '')
self.assertEqual(received['payload']['data']['last_name'], '')
received = client.receive()
self.assertIsNone(received)