def setUp(self): self.rp = ReceiverProtocol(Deferred())
class TestReceiverProtocol(TestCase): def setUp(self): self.rp = ReceiverProtocol(Deferred()) def test_init(self): self.assertTrue(isinstance(self.rp.finished, Deferred)) def test_dataReceivedOnce(self): data = 'some random string' self.rp.dataReceived(data) self.assertEquals(self.rp.body, data) def test_dataReceivedTwice(self): data1 = 'string1' data2 = 'string2' self.rp.dataReceived(data1) self.rp.dataReceived(data2) self.assertEquals(self.rp.body, data1 + data2) def test_connectionLostCalled(self): data = 'some random string' self.rp.dataReceived(data) self.rp.connectionLost(None) self.assertTrue(self.rp.finished.called) def test_connectionLostCalledData(self): data = 'some random string' self.rp.dataReceived(data) def called(data_received): self.assertEquals(data_received, data) self.rp.finished.addCallback(called) self.rp.connectionLost(None) return self.rp.finished