本文整理汇总了Python中twisted.test.proto_helpers.StringTransportWithDisconnection.getHost方法的典型用法代码示例。如果您正苦于以下问题:Python StringTransportWithDisconnection.getHost方法的具体用法?Python StringTransportWithDisconnection.getHost怎么用?Python StringTransportWithDisconnection.getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.test.proto_helpers.StringTransportWithDisconnection
的用法示例。
在下文中一共展示了StringTransportWithDisconnection.getHost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WebSocketsProtocolWrapperTest
# 需要导入模块: from twisted.test.proto_helpers import StringTransportWithDisconnection [as 别名]
# 或者: from twisted.test.proto_helpers.StringTransportWithDisconnection import getHost [as 别名]
class WebSocketsProtocolWrapperTest(TestCase):
"""
Tests for L{WebSocketsProtocolWrapper}.
"""
def setUp(self):
self.accumulatingProtocol = AccumulatingProtocol()
self.protocol = WebSocketsProtocolWrapper(self.accumulatingProtocol)
self.transport = StringTransportWithDisconnection()
self.protocol.makeConnection(self.transport)
self.transport.protocol = self.protocol
def test_dataReceived(self):
"""
L{WebSocketsProtocolWrapper.dataReceived} forwards frame content to the
underlying protocol.
"""
self.protocol.dataReceived(
_makeFrame("Hello", CONTROLS.TEXT, True, mask="abcd"))
self.assertEqual("Hello", self.accumulatingProtocol.data)
def test_controlFrames(self):
"""
L{WebSocketsProtocolWrapper} doesn't forward data from control frames
to the underlying protocol.
"""
self.protocol.dataReceived(
_makeFrame("Hello", CONTROLS.PING, True, mask="abcd"))
self.protocol.dataReceived(
_makeFrame("Hello", CONTROLS.PONG, True, mask="abcd"))
self.protocol.dataReceived(
_makeFrame("", CONTROLS.CLOSE, True, mask="abcd"))
self.assertEqual("", self.accumulatingProtocol.data)
def test_loseConnection(self):
"""
L{WebSocketsProtocolWrapper.loseConnection} sends a close frame and
disconnects the transport.
"""
self.protocol.loseConnection()
self.assertFalse(self.transport.connected)
self.assertEqual("\x88\x02\x03\xe8", self.transport.value())
def test_write(self):
"""
L{WebSocketsProtocolWrapper.write} creates and writes a frame from the
payload passed.
"""
self.accumulatingProtocol.transport.write("Hello")
self.assertEqual("\x81\x05Hello", self.transport.value())
def test_writeSequence(self):
"""
L{WebSocketsProtocolWrapper.writeSequence} writes a frame for every
chunk passed.
"""
self.accumulatingProtocol.transport.writeSequence(["Hello", "World"])
self.assertEqual("\x81\x05Hello\x81\x05World", self.transport.value())
def test_getHost(self):
"""
L{WebSocketsProtocolWrapper.getHost} returns the transport C{getHost}.
"""
self.assertEqual(self.transport.getHost(),
self.accumulatingProtocol.transport.getHost())
def test_getPeer(self):
"""
L{WebSocketsProtocolWrapper.getPeer} returns the transport C{getPeer}.
"""
self.assertEqual(self.transport.getPeer(),
self.accumulatingProtocol.transport.getPeer())
def test_connectionLost(self):
"""
L{WebSocketsProtocolWrapper.connectionLost} forwards the connection
lost call to the underlying protocol.
"""
self.transport.loseConnection()
self.assertTrue(self.accumulatingProtocol.closed)