def test_set_rpcuser(bitcoin_configuration: BitcoinConfiguration): bitcoin_configuration.file.rpcuser = '******' changed = ConfigurationFile(bitcoin_configuration.file.path) assert changed.rpcuser == 'test_user' bitcoin_configuration.file.rpcuser = '******' changed_again = ConfigurationFile(bitcoin_configuration.file.path) assert changed_again.rpcuser == 'test_user_2'
def test_setattr_bool(self, configuration_file: ConfigurationFile): configuration_file.test_bool_false = False configuration_file.test_bool_true = True with open(configuration_file.path, 'r') as f: text = f.read() assert 'test_bool_false=0' in text assert 'test_bool_true=1' in text
def test_set_prune(bitcoin_configuration: BitcoinConfiguration): bitcoin_configuration.set_prune(True) pruned = ConfigurationFile(bitcoin_configuration.file.path) assert pruned.prune assert not pruned.txindex bitcoin_configuration.set_prune(False) unpruned = ConfigurationFile(bitcoin_configuration.file.path) assert not unpruned.prune assert unpruned.txindex
def __init__(self, configuration_path: str = None): if configuration_path is None: configuration_path = os.path.join( BITCOIN_DATA_PATH[OPERATING_SYSTEM], 'bitcoin.conf') self.file = ConfigurationFile(configuration_path) self.hard_drives = HardDrives() if self.file.rpcuser is None: self.file.rpcuser = '******' if self.file.rpcpassword is None: self.file.rpcpassword = get_random_password() if self.file.datadir is None: self.autoconfigure_datadir() if self.file.prune is None: self.set_prune( self.hard_drives.should_prune(self.file.datadir, True))
def configuration_file(): with NamedTemporaryFile(suffix='.conf', delete=True) as f: name = f.name configuration_file = ConfigurationFile(name) return configuration_file
def test_getattr_bool(self, configuration_file: ConfigurationFile): configuration_file.test_bool_true = True configuration_file.test_bool_false = False new_object = ConfigurationFile(configuration_file.path) assert new_object.test_bool_true assert not new_object.test_bool_false
def test_getattr(self, configuration_file: ConfigurationFile): configuration_file.test_attribute = test_value new_object = ConfigurationFile(configuration_file.path) assert new_object.test_attribute == test_value
def test_setattr(self, configuration_file: ConfigurationFile): configuration_file.test_attribute = test_value with open(configuration_file.path, 'r') as f: text = f.read() assert test_value in text