def testBuffer(self): output = StringIOWithoutClosing() a = self.serverClass() class fooFactory: domain = 'foo.com' a.factory = fooFactory() a.makeConnection(protocol.FileWrapper(output)) for (send, expect, msg, msgexpect) in self.data: if send: a.dataReceived(send) data = output.getvalue() output.truncate(0) if not re.match(expect, data): raise AssertionError, (send, expect, data) if data[:3] == '354': for line in msg.splitlines(): if line and line[0] == '.': line = '.' + line a.dataReceived(line + '\r\n') a.dataReceived('.\r\n') # Special case for DATA. Now we want a 250, and then # we compare the messages data = output.getvalue() output.truncate() resp, msgdata = msgexpect if not re.match(resp, data): raise AssertionError, (resp, data) self.assertEquals(a.message, msgdata) # a.transport.loseConnection() # reactor.iterate() a.timeoutID.cancel()
def testBuffer(self): output = StringIOWithoutClosing() a = self.serverClass() class fooFactory: domain = 'foo.com' a.factory = fooFactory() a.makeConnection(protocol.FileWrapper(output)) for (send, expect, msg, msgexpect) in self.data: if send: a.dataReceived(send) data = output.getvalue() output.truncate(0) if not re.match(expect, data): raise AssertionError, (send, expect, data) if data[:3] == '354': for line in msg.splitlines(): if line and line[0] == '.': line = '.' + line a.dataReceived(line + '\r\n') a.dataReceived('.\r\n') # Special case for DATA. Now we want a 250, and then # we compare the messages data = output.getvalue() output.truncate() resp, msgdata = msgexpect if not re.match(resp, data): raise AssertionError, (resp, data) for recip in msgdata[2]: expected = list(msgdata[:]) expected[2] = [recip] self.assertEquals(a.message[(recip, )], tuple(expected)) a.setTimeout(None)
def testDeferredChat(self): factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data) output = StringIOWithoutClosing() transport = internet.protocol.FileWrapper(output) protocol = postfix.PostfixTCPMapServer() protocol.service = factory protocol.factory = factory protocol.makeConnection(transport) for input, expected_output in self.chat: protocol.lineReceived(input) self.assertEquals(output.getvalue(), expected_output, 'For %r, expected %r but got %r' % ( input, expected_output, output.getvalue() )) output.truncate(0) protocol.setTimeout(None)
def testDeferredChat(self): factory = postfix.PostfixTCPMapDeferringDictServerFactory(self.data) output = StringIOWithoutClosing() transport = internet.protocol.FileWrapper(output) protocol = postfix.PostfixTCPMapServer() protocol.service = factory protocol.factory = factory protocol.makeConnection(transport) for input, expected_output in self.chat: protocol.lineReceived(input) # self.runReactor(1) self.assertEquals(output.getvalue(), expected_output, 'For %r, expected %r but got %r' % ( input, expected_output, output.getvalue() )) output.truncate(0) protocol.setTimeout(None)
def testBuffer(self): output = StringIOWithoutClosing() a = self.serverClass() class fooFactory: domain = 'foo.com' a.factory = fooFactory() a.makeConnection(protocol.FileWrapper(output)) for (send, expect, msg, msgexpect) in self.data: if send: a.dataReceived(send) data = output.getvalue() output.truncate(0) if not re.match(expect, data): raise AssertionError, (send, expect, data) if data[:3] == '354': for line in msg.splitlines(): if line and line[0] == '.': line = '.' + line a.dataReceived(line + '\r\n') a.dataReceived('.\r\n') # Special case for DATA. Now we want a 250, and then # we compare the messages data = output.getvalue() output.truncate() resp, msgdata = msgexpect if not re.match(resp, data): raise AssertionError, (resp, data) for recip in msgdata[2]: expected = list(msgdata[:]) expected[2] = [recip] self.assertEquals( a.message[(recip,)], tuple(expected) ) a.setTimeout(None)