From 8bdbfbf19487263f2e41730e4e50af31ec47d0d5 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Thu, 11 Apr 2019 18:07:51 +0300 Subject: [PATCH] tests for options added --- freqtrade/tests/conftest.py | 65 +++++++++++++++++++++ freqtrade/tests/test_configuration.py | 83 +++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index 0bff1d5e9..b19518ee7 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -197,6 +197,71 @@ def default_conf(): return configuration +@pytest.fixture(scope="function") +def all_conf(): + """ Returns validated configuration with all options """ + configuration = { + "max_open_trades": 1, + "stake_currency": "BTC", + "stake_amount": 0.001, + "fiat_display_currency": "USD", + "ticker_interval": '5m', + "dry_run": True, + "minimal_roi": { + "40": 0.0, + "30": 0.01, + "20": 0.02, + "0": 0.04 + }, + "stoploss": -0.10, + "unfilledtimeout": { + "buy": 10, + "sell": 30 + }, + "bid_strategy": { + "ask_last_balance": 0.0, + "use_order_book": False, + "order_book_top": 1, + "check_depth_of_market": { + "enabled": False, + "bids_to_ask_delta": 1 + } + }, + "ask_strategy": { + "use_order_book": False, + "order_book_min": 1, + "order_book_max": 1 + }, + "exchange": { + "name": "bittrex", + "sandbox": False, + "enabled": True, + "key": "key", + "secret": "secret", + "password": "password", + "pair_whitelist": [ + "ETH/BTC", + "LTC/BTC", + "XRP/BTC", + "NEO/BTC" + ], + "pair_blacklist": [ + "DOGE/BTC", + "HOT/BTC", + ] + }, + "telegram": { + "enabled": True, + "token": "token", + "chat_id": "0" + }, + "initial_state": "running", + "db_url": "sqlite://", + "loglevel": logging.DEBUG, + } + return configuration + + @pytest.fixture def update(): _update = Update(0) diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 45e539c2f..edc6111da 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -617,3 +617,86 @@ def test_validate_tsl(default_conf): default_conf['trailing_stop_positive_offset'] = 0.015 Configuration(Namespace()) configuration._validate_config_consistency(default_conf) + + +# config['exchange'] subtree has required options in it +# so it cannot be omitted in the config +def test_load_config_default_exchange(all_conf) -> None: + del all_conf['exchange'] + + assert 'exchange' not in all_conf + + with pytest.raises(ValidationError, + match=r'\'exchange\' is a required property'): + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) +### assert 'exchange' in all_conf + + +# config['exchange']['name'] option is required +# so it cannot be omitted in the config +def test_load_config_default_exchange_name(all_conf) -> None: + del all_conf['exchange']['name'] + + assert 'name' not in all_conf['exchange'] + + with pytest.raises(ValidationError, + match=r'\'name\' is a required property'): + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) + + +# config['exchange']['sandbox'] option has default value: False +# so it can be omitted in the config and the default value +# should be present in the config as the option value +def test_load_config_default_exchange_sandbox(all_conf) -> None: + del all_conf['exchange']['sandbox'] + + assert 'sandbox' not in all_conf['exchange'] + + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) + assert 'sandbox' in all_conf['exchange'] + assert all_conf['exchange']['sandbox'] is False + + +# config['exchange']['key'] option has default value: '' +# so it can be omitted in the config and the default value +# should be present in the config as the option value +def test_load_config_default_exchange_key(all_conf) -> None: + del all_conf['exchange']['key'] + + assert 'key' not in all_conf['exchange'] + + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) + assert 'key' in all_conf['exchange'] + assert all_conf['exchange']['key'] == '' + + +# config['exchange']['secret'] option has default value: '' +# so it can be omitted in the config and the default value +# should be present in the config as the option value +def test_load_config_default_exchange_secret(all_conf) -> None: + del all_conf['exchange']['secret'] + + assert 'secret' not in all_conf['exchange'] + + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) + assert 'secret' in all_conf['exchange'] + assert all_conf['exchange']['secret'] == '' + + +# config['exchange']['password'] option has default value: '' +# so it can be omitted in the config and the default value +# should be present in the config as the option value +def test_load_config_default_exchange_password(all_conf) -> None: + del all_conf['exchange']['password'] + + assert 'password' not in all_conf['exchange'] + + configuration = Configuration(Namespace()) + configuration._validate_config_schema(all_conf) + assert 'password' in all_conf['exchange'] + assert all_conf['exchange']['password'] == ''