Created
April 26, 2011 10:37
-
-
Save alanfranz/942093 to your computer and use it in GitHub Desktop.
Twisted Protocol unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.trial.unittest import TestCase | |
from twisted.test.proto_helpers import StringTransportWithDisconnection | |
from twisted.internet.protocol import Factory | |
from somepackage.someprotocol import SomeProtocol | |
class MockFactory(Factory): | |
pass | |
class TestSomeProtocol(TestCase): | |
def setUp(self): | |
self.sp = SomeProtocol() | |
self.transport = StringTransportWithDisconnection() | |
self.sp.makeConnection(self.transport) | |
self.transport.protocol = self.sp | |
self.sp.factory = MockFactory() | |
def test_client_sends_hello_with_its_name_server_answers_hello_with_client_name_and_its_own(self): | |
self.sp.dataReceived("Hello, I'm Donald Duck\n") | |
self.assertEquals("Hello Donald Duck, I'm SomeServer\n", self.transport.value()) | |
def test_client_doesnt_send_hello_server_drops_connection(self): | |
self.sp.dataReceived("What is this server doing\n") | |
self.assertFalse(self.transport.connected) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment