Example #1
0
    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)
Example #2
0
 def testBuffer(self):
     b = StringIOWithoutClosing()
     a = http.HTTPChannel()
     a.requestFactory = DummyHTTPHandler
     a.makeConnection(protocol.FileWrapper(b))
     # one byte at a time, to stress it.
     for byte in self.requests:
         a.dataReceived(byte)
     a.connectionLost(IOError("all one"))
     value = b.getvalue()
     if value != self.expected_response:
         for i in range(len(value)):
             if len(self.expected_response) <= i:
                 print ` value[i - 5:i +
                               10] `, ` self.expected_response[i - 5:i +
                                                               10] `
             elif value[i] != self.expected_response[i]:
                 print ` value[i - 5:i +
                               10] `, ` self.expected_response[i - 5:i +
                                                               10] `
                 break
         print '---VALUE---'
         print repr(value)
         print '---EXPECTED---'
         print repr(self.expected_response)
         raise AssertionError
Example #3
0
    def testEmptyLineSyntaxError(self):
        proto = smtp.SMTP()
        output = StringIOWithoutClosing()
        transport = internet.protocol.FileWrapper(output)
        proto.makeConnection(transport)
        proto.lineReceived('')
        proto.setTimeout(None)

        out = output.getvalue().splitlines()
        self.assertEquals(len(out), 2)
        self.failUnless(out[0].startswith('220'))
        self.assertEquals(out[1], "500 Error: bad syntax")
Example #4
0
 def test_buffer(self):
     """
     Send requests over a channel and check responses match what is expected.
     """
     b = StringIOWithoutClosing()
     a = http.HTTPChannel()
     a.requestFactory = DummyHTTPHandler
     a.makeConnection(protocol.FileWrapper(b))
     # one byte at a time, to stress it.
     for byte in self.requests:
         a.dataReceived(byte)
     a.connectionLost(IOError("all one"))
     value = b.getvalue()
     self.assertEquals(value, self.expected_response)
Example #5
0
 def testMessages(self):
     self.output = StringIOWithoutClosing()
     self.transport = protocols.protocol.FileWrapper(self.output)
     protocol =  MyVirtualPOP3()
     protocol.makeConnection(self.transport)
     protocol.factory = self.factory
     protocol.lineReceived('APOP [email protected] world')
     protocol.lineReceived('UIDL')
     protocol.lineReceived('RETR 1')
     protocol.lineReceived('QUIT')
     if self.output.getvalue() != self.expectedOutput:
         print `self.output.getvalue()`
         print `self.expectedOutput`
         raise AssertionError(self.output.getvalue(), self.expectedOutput)
Example #6
0
 def runRequest(self, httpRequest, requestClass, success=1):
     httpRequest = httpRequest.replace("\n", "\r\n")
     b = StringIOWithoutClosing()
     a = http.HTTPChannel()
     a.requestFactory = requestClass
     a.makeConnection(protocol.FileWrapper(b))
     # one byte at a time, to stress it.
     for byte in httpRequest:
         if a.transport.closed:
             break
         a.dataReceived(byte)
     a.connectionLost(IOError("all done"))
     if success:
         self.assertEquals(self.didRequest, 1)
         del self.didRequest
     else:
         self.assert_(not hasattr(self, "didRequest"))
Example #7
0
    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)
Example #8
0
 def setUp(self):
     self.factory = smtp.SMTPFactory()
     self.factory.domains = {}
     self.factory.domains['baz.com'] = DummyDomain(['foo'])
     self.output = StringIOWithoutClosing()
     self.transport = internet.protocol.FileWrapper(self.output)
Example #9
0
 def setUp(self):
     self.output = StringIOWithoutClosing()
     self.transport = protocols.protocol.FileWrapper(self.output)