diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py index dae9f3c90..d8d42461b 100644 --- a/freqtrade/tests/test_persistence.py +++ b/freqtrade/tests/test_persistence.py @@ -1,9 +1,11 @@ # pragma pylint: disable=missing-docstring, C0103 from copy import deepcopy +from unittest.mock import MagicMock import pytest from sqlalchemy import create_engine +from freqtrade import constants from freqtrade.persistence import Trade, init, clean_dry_run_db @@ -25,18 +27,39 @@ def test_init_custom_db_url(default_conf, mocker): conf = deepcopy(default_conf) # Update path to a value other than default, but still in-memory - conf.update({'db_url': 'sqlite:///'}) + conf.update({'db_url': 'sqlite:////tmp/freqtrade2_test.sqlite'}) + create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock()) mocker.patch.dict('freqtrade.persistence._CONF', conf) - # Check if the new tradesv3.dry_run.sqlite was created init(conf) + assert create_engine_mock.call_count == 1 + assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:////tmp/freqtrade2_test.sqlite' def test_init_prod_db(default_conf, mocker): - default_conf.update({'dry_run': False}) - mocker.patch.dict('freqtrade.persistence._CONF', default_conf) + conf = deepcopy(default_conf) + conf.update({'dry_run': False}) + conf.update({'db_url': constants.DEFAULT_DB_PROD_URL}) - init(default_conf) + create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock()) + mocker.patch.dict('freqtrade.persistence._CONF', conf) + + init(conf) + assert create_engine_mock.call_count == 1 + assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite' + + +def test_init_dryrun_db(default_conf, mocker): + conf = deepcopy(default_conf) + conf.update({'dry_run': True}) + conf.update({'db_url': constants.DEFAULT_DB_DRYRUN_URL}) + + create_engine_mock = mocker.patch('freqtrade.persistence.create_engine', MagicMock()) + mocker.patch.dict('freqtrade.persistence._CONF', conf) + + init(conf) + assert create_engine_mock.call_count == 1 + assert create_engine_mock.mock_calls[0][1][0] == 'sqlite://' @pytest.mark.usefixtures("init_persistence")