def test_connect(self): check = SmtpHealthCheck() self.mox.StubOutWithMock(socket, 'socket') sock = self.mox.CreateMockAnything() socket.socket(1, 2, 3).AndReturn(sock) sock.connect(('test', 13)) self.mox.ReplayAll() check._connect([(1, 2, 3, '', ('test', 13))]) self.assertIn('Connect-Elapsed', check.results)
def test_run_exception(self): check = SmtpHealthCheck() check.sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(check, '_lookup') self.mox.StubOutWithMock(check, '_connect') self.mox.StubOutWithMock(check, '_get_banner') self.mox.StubOutWithMock(check, '_check_banner') check._lookup('test', 13).AndReturn('beep') check._connect('beep').AndRaise(Exception('test test')) check.sock.close() self.mox.ReplayAll() check.run('test', 13) self.assertEqual('Exception', check.results['Exception-Type']) self.assertEqual('test test', check.results['Exception-Value'])
def test_run(self): check = SmtpHealthCheck() check.sock = self.mox.CreateMockAnything() self.mox.StubOutWithMock(check, '_lookup') self.mox.StubOutWithMock(check, '_connect') self.mox.StubOutWithMock(check, '_get_banner') self.mox.StubOutWithMock(check, '_check_banner') check._lookup('test', 13).AndReturn('beep') check._connect('beep') check._get_banner().AndReturn('beep beep') check._check_banner('beep beep') check.sock.close() self.mox.ReplayAll() check.run('test', 13)
def test_connect_bad_dns(self): check = SmtpHealthCheck() with self.assertRaises(DNSError): check._connect([])