def test_has_manager_loader(self): coin = Coin(symbol='TESTCOIN') ch.add_handler_coin('Bitcoin', coin) ch.enable_handler('Bitcoin') ch.reload_handlers() self.assertTrue(ch.has_loader('TESTCOIN')) self.assertTrue(ch.has_manager('TESTCOIN'))
def setup_handler(name: str, symbol: str = 'EXTESTCOIN', enabled: bool = True): if enabled: ch.enable_handler(name) else: ch.disable_handler(name) coin = Coin(symbol=symbol) ch.add_handler_coin(name, coin) ch.reload_handlers()
def init_privex_handler(name: str): """ Attempt to import a :py:mod:`privex.coin_handlers` handler module, adapting it for SteemEngine's older Coin Handler system. * Extracts the handler type and description for injection into ``settings.COIN_TYPES`` (since privex handlers are framework independent and cannot auto-inject into ``settings.COIN_TYPE``) * Configures the Privex coin_handlers coin object based on a database :class:`.Coin` row * Detects coins which are mapped to a Privex coin handler and registers the handler's manager/loader into the global handlers dictionary :param str name: The name of a :py:mod:`privex.coin_handlers` handler module, e.g. ``Golos`` """ from payments.models import Coin modpath = name if '.' in name else f'privex.coin_handlers.{name}' i = import_module(modpath) ctype, cdesc = i.COIN_TYPE, i.HANDLER_DESC # Inject the handler type + description into settings.COIN_TYPE if it's not already there, so it can be used # in the admin panel and other areas. if ctype not in dict(settings.COIN_TYPES): log.debug('(Privex) %s not in COIN_TYPES, adding it.', ctype) settings.COIN_TYPES += (( ctype, cdesc, ), ) # Find any coins which are already configured to use this handler, then register the Privex coin handler with # the global handler storage hcoins = Coin.objects.filter(coin_type=ctype) for coin in hcoins: # type: Coin ch.configure_coin(coin.symbol_id, our_account=coin.our_account, display_name=coin.display_name, **coin.settings, **coin.settings['json']) ch.add_handler_coin(name, coin.symbol_id) if coin.symbol not in handlers: handlers[coin.symbol] = dict(loaders=[], managers=[]) # After re-configuring each coin, we need to reload Privex's coin handlers before getting the manager/loader ch.reload_handlers() # We hand off to privex.coin_handlers.get_manager/loader to initialise the handler's classes, rather than # trying to do it ourselves. Then we register them with the global handler store. handlers[coin.symbol]['managers'].append(ch.get_manager( coin.symbol_id)) handlers[coin.symbol]['loaders'].append(ch.get_loader(coin.symbol_id))
def test_get_loader(self): coin = Coin(symbol='TESTCOIN') ch.add_handler_coin('Bitcoin', coin) ch.enable_handler('Bitcoin') ch.reload_handlers()
def clear_handler(name: str): ch.COIN_HANDLERS[name] = dict(enabled=False, coins=[], kwargs={}) ch.reload_handlers()