Created testmode decorator & routed command decorator through it

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-11-25 21:43:22 +05:30
parent 21cb4e516d
commit 56ec5b8a03
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -304,15 +304,27 @@ class CommandHandler(type):
return result return result
class testmode(object): # pylint: disable=too-few-public-methods
"""Decorator to check testmode & route to command decorator"""
def __init__(self, *aliases):
self.aliases = aliases
def __call__(self, func):
"""Testmode call method"""
if not state.testmode:
return None
return command(self.aliases[0]).__call__(func)
class command(object): # pylint: disable=too-few-public-methods class command(object): # pylint: disable=too-few-public-methods
"""Decorator for API command method""" """Decorator for API command method"""
def __init__(self, *aliases): def __init__(self, *aliases):
self.aliases = aliases self.aliases = aliases
def __call__(self, func): def __call__(self, func):
if func.__name__ in ["HandleclearUISignalQueue", "HandleGetStatusBar"] \
and not state.testmode:
return None
if BMConfigParser().safeGet( if BMConfigParser().safeGet(
'bitmessagesettings', 'apivariant') == 'legacy': 'bitmessagesettings', 'apivariant') == 'legacy':
def wrapper(*args): def wrapper(*args):
@ -1427,7 +1439,7 @@ class BMRPCDispatcher(object):
"""Test two numeric params""" """Test two numeric params"""
return a + b return a + b
@command('clearUISignalQueue') @testmode('clearUISignalQueue')
def HandleclearUISignalQueue(self): def HandleclearUISignalQueue(self):
"""clear UISignalQueue""" """clear UISignalQueue"""
queues.UISignalQueue.queue.clear() queues.UISignalQueue.queue.clear()
@ -1438,7 +1450,7 @@ class BMRPCDispatcher(object):
"""Update GUI statusbar message""" """Update GUI statusbar message"""
queues.UISignalQueue.put(('updateStatusBar', message)) queues.UISignalQueue.put(('updateStatusBar', message))
@command('getStatusBar') @testmode('getStatusBar')
def HandleGetStatusBar(self): def HandleGetStatusBar(self):
"""Get GUI statusbar message""" """Get GUI statusbar message"""
try: try: