【发布时间】:2017-08-26 02:48:34
【问题描述】:
我正在尝试使用 django 频道中的测试框架测试我的消费者,但即使是基本测试似乎也不起作用
这是我的测试用例的样子:
from channels import Channel
from channels.test import ChannelTestCase, HttpClient, apply_routes
from rci.consumers import Demultiplexer
from rosbridge.consumers import OtherWebSocketConsumer
class ChannelTestCase(ChannelTestCase):
def test_channel(self):
client = HttpClient()
client.send_and_consume('websocket.connect', '/new/') # <--- here's the error
self.assertIsNone(client.receive())
这是我的路线:
http_routing = [
route("http.request", admin.site.urls, path=r"^/admin/", method=r"^$"),
#...and so on
]
channel_routing = [Demultiplexer.as_route(path=r"^/sock/")]
这是我的消费者:
class Demultiplexer(WebsocketDemultiplexer):
channel_session_user = True
consumers = {
"rosbridge": ROSWebSocketConsumer,
"setting": SettingsConsumer,
}
这给了我以下错误:
错误:test_ros_channel (robot_configuration_interface.tests.unit.test_channels.ROSChannelTestCase) -------------------------------------------------- -------------------- Traceback(最近一次调用最后一次):文件 “/home/cjds/development/robot_configuration_interface/robot_configuration_interface/tests/unit/test_channels.py”,第 36 行,在 test_ros_channel client.send_and_consume('websocket.connect', '/new/') 文件 "/usr/local/lib/python2.7/dist-packages/channels/test/http.py", 行 94,在 send_and_consume self.send(channel, content, text, path) 文件“/usr/local/lib/python2.7/dist-packages/channels/test/http.py”,行 79、在发送 content.setdefault('reply_channel', self.reply_channel) AttributeError: 'str' object has no attribute 'setdefault'
我正在尝试在这里学习本教程:
http://channels.readthedocs.io/en/stable/testing.html#clients
【问题讨论】:
标签: python django unit-testing django-channels