TestConnectEntryPoint.py 1.48 KB
import unittest
import mock

from os.path import dirname, realpath
from sys import argv, path
path.append(dirname(dirname(realpath(__file__))) + '/lib')

from Communication.ConnectEntryPoint import ConnectEntryPoint
from Transport import Transport

class TestConnectEntryPoint(unittest.TestCase):
    def setUp(self):
        self._transport  = mock.Mock()
        self._protocol   = mock.Mock()
        self._newcon     = mock.Mock()
        self._entrypoint = ConnectEntryPoint(self._transport, self._protocol)
        self._transport.bind.assert_called_once_with()

    def testAccept(self):
        self._transport.accept.return_value = None
        self.assertFalse(self._entrypoint.accept())

        self._transport.accept.side_effect = iter(
                [self._newcon, self._newcon, None])
        self.assertTrue(self._entrypoint.accept())

        self._transport.accept.side_effect = iter(
                [self._newcon, Transport.Error(1)])
        self.assertTrue(self._entrypoint.accept())

    def testPop(self):
        self.testAccept()
        self.assertEqual(self._entrypoint.pop(), self._newcon)
        self.assertEqual(self._entrypoint.pop(), self._newcon)
        self.assertEqual(self._entrypoint.pop(), self._newcon)
        self.assertEqual(self._entrypoint.pop(), None)

def suite():
    return unittest.TestLoader().loadTestsFromTestCase(TestConnectEntryPoint)

if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=2).run(suite())

# vim: set ft=python et ts=8 sw=4 sts=4: