Add an obvious test for the 'statusBar' command
and remove some junk introduced in 9a194f0
.
This commit is contained in:
parent
a16a0cea5c
commit
2c2a41d105
18
src/api.py
18
src/api.py
|
@ -68,7 +68,7 @@ import time
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
|
|
||||||
from six.moves import configparser, http_client, queue, xmlrpc_server
|
from six.moves import configparser, http_client, xmlrpc_server
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
|
@ -1502,25 +1502,11 @@ class BMRPCDispatcher(object):
|
||||||
"""Test two numeric params"""
|
"""Test two numeric params"""
|
||||||
return a + b
|
return a + b
|
||||||
|
|
||||||
@testmode('clearUISignalQueue')
|
|
||||||
def HandleclearUISignalQueue(self):
|
|
||||||
"""clear UISignalQueue"""
|
|
||||||
queues.UISignalQueue.queue.clear()
|
|
||||||
return "success"
|
|
||||||
|
|
||||||
@command('statusBar')
|
@command('statusBar')
|
||||||
def HandleStatusBar(self, message):
|
def HandleStatusBar(self, message):
|
||||||
"""Update GUI statusbar message"""
|
"""Update GUI statusbar message"""
|
||||||
queues.UISignalQueue.put(('updateStatusBar', message))
|
queues.UISignalQueue.put(('updateStatusBar', message))
|
||||||
|
return "success"
|
||||||
@testmode('getStatusBar')
|
|
||||||
def HandleGetStatusBar(self):
|
|
||||||
"""Get GUI statusbar message"""
|
|
||||||
try:
|
|
||||||
_, data = queues.UISignalQueue.get(block=False)
|
|
||||||
except queue.Empty:
|
|
||||||
return None
|
|
||||||
return data
|
|
||||||
|
|
||||||
@testmode('undeleteMessage')
|
@testmode('undeleteMessage')
|
||||||
def HandleUndeleteMessage(self, msgid):
|
def HandleUndeleteMessage(self, msgid):
|
||||||
|
|
|
@ -13,7 +13,7 @@ import psutil
|
||||||
|
|
||||||
from .samples import (
|
from .samples import (
|
||||||
sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
|
sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
|
||||||
sample_inbox_msg_ids, sample_statusbar_msg,
|
sample_inbox_msg_ids,
|
||||||
sample_subscription_addresses, sample_subscription_name
|
sample_subscription_addresses, sample_subscription_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,18 +88,6 @@ class TestAPI(TestAPIProto):
|
||||||
'API Error 0020: Invalid method: test'
|
'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):
|
def test_message_inbox(self):
|
||||||
"""Test message inbox methods"""
|
"""Test message inbox methods"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from six.moves import xmlrpc_client
|
from six.moves import queue, xmlrpc_client
|
||||||
|
|
||||||
from pybitmessage import pathmagic
|
from pybitmessage import pathmagic
|
||||||
|
|
||||||
|
from .samples import sample_statusbar_msg # any
|
||||||
|
|
||||||
|
|
||||||
class TestAPIThread(unittest.TestCase):
|
class TestAPIThread(unittest.TestCase):
|
||||||
"""Test case running the API thread"""
|
"""Test case running the API thread"""
|
||||||
|
@ -15,16 +17,22 @@ class TestAPIThread(unittest.TestCase):
|
||||||
|
|
||||||
import helper_sql
|
import helper_sql
|
||||||
import helper_startup
|
import helper_startup
|
||||||
|
import queues
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
class SqlReadyMock(object):
|
class SqlReadyMock(object):
|
||||||
|
"""Mock helper_sql.sql_ready event with dummy class"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def wait():
|
def wait():
|
||||||
|
"""Don't wait, return immediately"""
|
||||||
return
|
return
|
||||||
|
|
||||||
helper_sql.sql_ready = SqlReadyMock
|
helper_sql.sql_ready = SqlReadyMock
|
||||||
cls.state = state
|
cls.state = state
|
||||||
|
cls.queues = queues
|
||||||
|
|
||||||
helper_startup.loadConfig()
|
helper_startup.loadConfig()
|
||||||
# helper_startup.fixSocket()
|
# helper_startup.fixSocket()
|
||||||
config = BMConfigParser()
|
config = BMConfigParser()
|
||||||
|
@ -46,6 +54,19 @@ class TestAPIThread(unittest.TestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.api.helloWorld('hello', 'world'), 'hello-world')
|
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
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
cls.state.shutdown = 1
|
cls.state.shutdown = 1
|
||||||
|
|
Reference in New Issue
Block a user