Source

txMysql / txmysql / test / test_server.py

from twisted.python import failure, log
from twisted.trial import unittest

from txmysql import server

class TestTxmysqlServer(unittest.TestCase):
    def setUp(self):
        portNumber = 6666
        self.server = server.TxmysqlServer(portNumber)
        
    def test_serverName(self):
        self.assertEqual(None, self.server.name
                         )

class TestTxmysqlServerStart(unittest.TestCase):
    def setUp(self):
        portNumber = 6666
        self.server = server.TxmysqlServer(portNumber)
        def _fakeServiceCallback(result):
            return result
        self.server._cbStarted = _fakeServiceCallback

    def tearDown(self):
        d = self.server.stopService()
        return d

    def _startSuccess(self, result):
        log.msg("test_server._startSuccess: %s"%(result,))
        self.assertEqual(True, result, "Expect server start to return true result")
        return result

    def _startShouldNotFail(self, failure):
        print failure
        self.fail("start should succeed!")
        return failure

    def _startShouldNotSucceed(self, result):
        self.fail("Start shouldn't succeed!")

    def _startShouldFail(self, failure):
        self.assertTrue(failure is not None)

    def test_startService(self):
        d = self.server.startService()
        d.addCallbacks(callback=self._startSuccess,
                       errback=self._startShouldNotFail)
        return d

    def test_startServiceFails(self):
        def fakeStart(d):
            d.errback(failure.Failure(Exception("Some exception occured while starting the service")))
        self.server.startupHook = fakeStart
        d = self.server.startService()
        d.addCallbacks(callback=self._startShouldNotSucceed,
                       errback=self._startShouldFail)
        return d
        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.