def test_run_multiple(self):
     result1 = AsyncResult()
     result2 = AsyncResult()
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env1.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result1, env1))
     queue.append((result2, env2))
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0.0)
     client._run()
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')}, result1.get_nowait())
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')}, result2.get_nowait())
 def test_run_multiple(self):
     result1 = self.mox.CreateMock(AsyncResult)
     result2 = self.mox.CreateMock(AsyncResult)
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env1.parse('From: [email protected]\r\n\r\ntest test\r\n')
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result1, env1))
     queue.append((result2, env2))
     self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result1.set([None])
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result2.set([None])
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0.0)
     client._run()
 def test_run_nomessages(self):
     queue = PriorityQueue()
     self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test', idle_timeout=0)
     client._run()
 def test_run_banner_failure(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn('520 Not Welcome\r\n')
     result.set_exception(IsA(PermanentRelayError))
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._run()
 def test_run_banner_failure(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn(b'520 Not Welcome\r\n')
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._run()
     with self.assertRaises(PermanentRelayError):
         result.get_nowait()
 def test_run_timeout(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndRaise(Timeout(0.0))
     result.ready().AndReturn(False)
     result.set_exception(IsA(TransientRelayError))
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._run()
 def test_run_smtperror(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope("*****@*****.**", ["*****@*****.**"])
     env.parse("From: [email protected]\r\n\r\ntest test\r\n")
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndRaise(SmtpError("test error"))
     result.ready().AndReturn(False)
     result.set_exception(IsA(TransientRelayError))
     self.sock.sendall("QUIT\r\n")
     self.sock.recv(IsA(int)).AndReturn("221 Goodbye\r\n")
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as="test")
     client._run()
 def test_run_random_exception(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndRaise(ValueError('test error'))
     result.ready().AndReturn(False)
     result.set_exception(IsA(ValueError))
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
     with assert_raises(ValueError):
         client._run()
 def test_run_random_exception(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndRaise(ValueError('test error'))
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', queue, socket_creator=self._socket_creator, ehlo_as='test')
     with self.assertRaises(ValueError):
         client._run()
     with self.assertRaises(ValueError):
         result.get_nowait()
Ejemplo n.º 10
0
 def test_run_banner_failure(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn('520 Not Welcome\r\n')
     result.set_exception(IsA(PermanentRelayError))
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None,
                              queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='test')
     client._run()
Ejemplo n.º 11
0
 def test_run_banner_failure(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn(b'520 Not Welcome\r\n')
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there')
     client._run()
     with self.assertRaises(PermanentRelayError):
         result.get_nowait()
Ejemplo n.º 12
0
 def test_run_smtperror(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndRaise(SmtpError('test error'))
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr',
                              queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='test')
     client._run()
     with self.assertRaises(TransientRelayError):
         result.get_nowait()
Ejemplo n.º 13
0
 def test_run_multiple(self):
     result1 = AsyncResult()
     result2 = AsyncResult()
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env1.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result1, env1))
     queue.append((result2, env2))
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(
         b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(
         b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(
         b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(
         b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there',
                              idle_timeout=0.0)
     client._run()
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')},
                      result1.get_nowait())
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')},
                      result2.get_nowait())
Ejemplo n.º 14
0
 def test_run(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result.set([None])
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._run()
Ejemplo n.º 15
0
 def test_run(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0), queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._run()
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')}, result.get_nowait())
 def test_run(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result, env))
     self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result.set(True)
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._run()
Ejemplo n.º 17
0
 def test_run_multiple(self):
     result1 = self.mox.CreateMock(AsyncResult)
     result2 = self.mox.CreateMock(AsyncResult)
     env1 = Envelope('*****@*****.**', ['*****@*****.**'])
     env1.parse('From: [email protected]\r\n\r\ntest test\r\n')
     env2 = Envelope('*****@*****.**', ['*****@*****.**'])
     env2.parse('From: [email protected]\r\n\r\ntest test\r\n')
     queue = BlockingDeque()
     queue.append((result1, env1))
     queue.append((result2, env2))
     self.sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(
         'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(
         'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result1.set(True)
     self.sock.sendall(
         'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(
         'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result2.set(True)
     self.sock.sendall('QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn('221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = SmtpRelayClient(None,
                              queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='test',
                              idle_timeout=0.0)
     client._run()
 def test_run_nomessages(self):
     queue = BlockingDeque()
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', queue, idle_timeout=0)
     client._run()
Ejemplo n.º 19
0
 def test_run_nomessages(self):
     queue = BlockingDeque()
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0), queue, idle_timeout=0)
     client._run()