def test_write_configuration_file_is_ok(mocked_bnc_config_path): mocked_bnc_config_path.patch('bnc.utils.config.read_json_config_file', return_value={ "is_testnet": False, "bnc_config_path": ".bnc", "bnc_api_endpoint": "https://api.binance.com" }) write_configuration_file() assert os.path.isfile(get_bnc_config_filename_path('configuration')) config_parser = get_config_parser() config_parser.read(get_bnc_config_filename_path('configuration')) assert config_parser.has_section(GENERAL_CONFIG_SECTION) assert config_parser.has_option(GENERAL_CONFIG_SECTION, 'IS_TESTNET') assert config_parser.has_option(GENERAL_CONFIG_SECTION, 'BNC_CONFIG_PATH') assert config_parser.has_section(API_INFO_SECTION) assert config_parser.has_option(API_INFO_SECTION, 'BNC_API_ENDPOINT') section = config_parser[GENERAL_CONFIG_SECTION] assert section.getboolean('IS_TESTNET') is False assert section['BNC_CONFIG_PATH'] == '.bnc' section = config_parser[API_INFO_SECTION] assert section['BNC_API_ENDPOINT'] == "https://api.binance.com" remove_configuration_file()
def test_write_configuration_file_bnc_api_endpoint_missing(mocker): mocker.patch('bnc.utils.config.read_json_config_file', return_value={ "is_testnet": False, "bnc_config_path": ".bnc" }) with pytest.raises(ConfigException, match='You must set bnc_api_endpoint in config.json'): write_configuration_file()
def test_write_configuration_file_is_testnet_missing(mocker): mocker.patch('bnc.utils.config.read_json_config_file', return_value={ "bnc_config_path": ".bnc", "bnc_api_endpoint": "https://api.binance.com" }) with pytest.raises(ConfigException, match='You must set is_testnet in config.json'): write_configuration_file()
def test_write_configuration_file_bnc_api_endpoint_empty(mocker): mocker.patch('bnc.utils.config.read_json_config_file', return_value={ "is_testnet": False, "bnc_config_path": ".bnc", "bnc_api_endpoint": "" }) with pytest.raises(ConfigException, match='bnc_api_endpoint cannot be null or empty in config.json'): write_configuration_file()
def test_read_configuration_file_is_ok(mocked_bnc_config_path): mocked_bnc_config_path.patch('bnc.utils.config.read_json_config_file', return_value={ "is_testnet": False, "bnc_config_path": ".bnc", "bnc_api_endpoint": "https://api.binance.com" }) write_configuration_file() config = read_configuration() assert config['is_testnet'] is False assert config['bnc_config_path'] == '.bnc' assert config['bnc_api_endpoint'] == 'https://api.binance.com' remove_configuration_file()