Ejemplo n.º 1
0
class TestJsonRpc(unittest.TestCase):
    def setUp(self):
        def noop():
            return None

        mock_conf_settings(self)
        test_utils.reset_time(self)
        self.test_daemon = get_test_daemon()
        self.test_daemon.wallet_manager.is_first_run = False
        self.test_daemon.wallet_manager.get_best_blockhash = noop

    def test_status(self):
        d = defer.maybeDeferred(self.test_daemon.jsonrpc_status)
        d.addCallback(lambda status: self.assertDictContainsSubset(
            {'is_running': False}, status))

    def test_help(self):
        d = defer.maybeDeferred(self.test_daemon.jsonrpc_help,
                                command='status')
        d.addCallback(lambda result: self.assertSubstring(
            'daemon status', result['help']))
        # self.assertSubstring('daemon status', d.result)

    if is_android():
        test_help.skip = "Test cannot pass on Android because PYTHONOPTIMIZE removes the docstrings."
Ejemplo n.º 2
0
class TestLogger(unittest.TestCase):
    def raiseError(self):
        raise Exception('terrible things happened')

    def triggerErrback(self, callback=None):
        d = defer.Deferred()
        d.addCallback(lambda _: self.raiseError())
        d.addErrback(self.log.fail(callback), 'My message')
        d.callback(None)
        return d

    def setUp(self):
        self.log = custom_logger.Logger('test')
        self.stream = StringIO()
        handler = logging.StreamHandler(self.stream)
        handler.setFormatter(
            logging.Formatter("%(filename)s:%(lineno)d - %(message)s"))
        self.log.addHandler(handler)

    @skipIf(
        is_android(),
        'Test cannot pass on Android because the tests package is compiled '
        'which results in a different method call stack')
    def test_can_log_failure(self):
        def output_lines():
            return self.stream.getvalue().split('\n')

        # the line number could change if this file gets refactored
        expected_first_line = 'test_customLogger.py:18 - My message: terrible things happened'

        # testing the entirety of the message is futile as the
        # traceback will depend on the system the test is being run on
        # but hopefully these two tests are good enough
        d = self.triggerErrback()
        d.addCallback(lambda _: self.assertEquals(expected_first_line,
                                                  output_lines()[0]))
        d.addCallback(lambda _: self.assertEqual(10, len(output_lines())))
        return d

    def test_can_log_failure_with_callback(self):
        callback = mock.Mock()
        d = self.triggerErrback(callback)
        d.addCallback(lambda _: callback.assert_called_once_with(mock.ANY))
        return d
Ejemplo n.º 3
0
class TestJsonRpc(unittest.TestCase):
    def setUp(self):
        async def noop():
            return None

        test_utils.reset_time(self)
        self.test_daemon = get_test_daemon(Config())
        self.test_daemon.wallet_manager.get_best_blockhash = noop

    def test_status(self):
        status = yield f2d(self.test_daemon.jsonrpc_status())
        self.assertDictContainsSubset({'is_running': False}, status)

    def test_help(self):
        result = self.test_daemon.jsonrpc_help(command='status')
        self.assertSubstring('daemon status', result['help'])

    if is_android():
        test_help.skip = "Test cannot pass on Android because PYTHONOPTIMIZE removes the docstrings."