From 22d93879430eba5a3e26c2e35c0312501d88ffc8 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 11 Dec 2021 20:01:10 +0200 Subject: [PATCH] Add an obvious test for the 'statusBar' command and remove some junk introduced in 9a194f0. --- src/api.py | 18 ++---------------- src/tests/test_api.py | 14 +------------- src/tests/test_api_thread.py | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/api.py b/src/api.py index 7eff52ef..3f128adc 100644 --- a/src/api.py +++ b/src/api.py @@ -67,7 +67,7 @@ import time from binascii import hexlify, unhexlify from struct import pack -from six.moves import configparser, http_client, queue, xmlrpc_server +from six.moves import configparser, http_client, xmlrpc_server import defaults import helper_inbox @@ -1455,25 +1455,11 @@ class BMRPCDispatcher(object): """Test two numeric params""" return a + b - @testmode('clearUISignalQueue') - def HandleclearUISignalQueue(self): - """clear UISignalQueue""" - queues.UISignalQueue.queue.clear() - return "success" - @command('statusBar') def HandleStatusBar(self, message): """Update GUI statusbar message""" queues.UISignalQueue.put(('updateStatusBar', message)) - - @testmode('getStatusBar') - def HandleGetStatusBar(self): - """Get GUI statusbar message""" - try: - _, data = queues.UISignalQueue.get(block=False) - except queue.Empty: - return None - return data + return "success" @testmode('undeleteMessage') def HandleUndeleteMessage(self, msgid): diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 835b4afb..220a1c1a 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -12,7 +12,7 @@ from six.moves import xmlrpc_client # nosec import psutil from .samples import ( - sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_statusbar_msg, + sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_inbox_msg_ids, sample_test_subscription_address, sample_subscription_name) from .test_process import TestProcessProto @@ -86,18 +86,6 @@ class TestAPI(TestAPIProto): 'API Error 0020: Invalid method: test' ) - def test_statusbar_method(self): - """Test statusbar method""" - self.api.clearUISignalQueue() - self.assertEqual( - self.api.statusBar(sample_statusbar_msg), - 'null' - ) - self.assertEqual( - self.api.getStatusBar(), - sample_statusbar_msg - ) - def test_message_inbox(self): """Test message inbox methods""" self.assertEqual( diff --git a/src/tests/test_api_thread.py b/src/tests/test_api_thread.py index c5bd6576..f118330f 100644 --- a/src/tests/test_api_thread.py +++ b/src/tests/test_api_thread.py @@ -1,10 +1,12 @@ import time import unittest -from six.moves import xmlrpc_client +from six.moves import queue, xmlrpc_client from pybitmessage import pathmagic +from .samples import sample_statusbar_msg # any + class TestAPIThread(unittest.TestCase): """Test case running the API thread""" @@ -15,16 +17,22 @@ class TestAPIThread(unittest.TestCase): import helper_sql import helper_startup + import queues import state from bmconfigparser import BMConfigParser + # pylint: disable=too-few-public-methods class SqlReadyMock(object): + """Mock helper_sql.sql_ready event with dummy class""" @staticmethod def wait(): + """Don't wait, return immediately""" return helper_sql.sql_ready = SqlReadyMock cls.state = state + cls.queues = queues + helper_startup.loadConfig() # helper_startup.fixSocket() config = BMConfigParser() @@ -48,6 +56,19 @@ class TestAPIThread(unittest.TestCase): self.assertEqual( self.api.helloWorld('hello', 'world'), 'hello-world') + def test_statusbar(self): + """Check UISignalQueue after issuing the 'statusBar' command""" + self.queues.UISignalQueue.queue.clear() + self.assertEqual( + self.api.statusBar(sample_statusbar_msg), 'success') + try: + cmd, data = self.queues.UISignalQueue.get(block=False) + except queue.Empty: + self.fail('UISignalQueue is empty!') + + self.assertEqual(cmd, 'updateStatusBar') + self.assertEqual(data, sample_statusbar_msg) + @classmethod def tearDownClass(cls): cls.state.shutdown = 1