Improve tests to work with new sqlalchemy version
This commit is contained in:
parent
ea3012e94d
commit
b7702a1e9f
@ -2798,7 +2798,7 @@ def test_execute_sell_sloe_cancel_exception(mocker, default_conf, ticker, fee, c
|
|||||||
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order',
|
mocker.patch('freqtrade.exchange.Exchange.cancel_stoploss_order',
|
||||||
side_effect=InvalidOrderException())
|
side_effect=InvalidOrderException())
|
||||||
mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock(return_value=300))
|
mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock(return_value=300))
|
||||||
sellmock = MagicMock()
|
sellmock = MagicMock(return_value={'id': '12345555'})
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from pathlib import Path
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
@ -21,14 +22,15 @@ def test_init_create_session(default_conf):
|
|||||||
assert 'scoped_session' in type(Trade.session).__name__
|
assert 'scoped_session' in type(Trade.session).__name__
|
||||||
|
|
||||||
|
|
||||||
def test_init_custom_db_url(default_conf, mocker):
|
def test_init_custom_db_url(default_conf, tmpdir):
|
||||||
# Update path to a value other than default, but still in-memory
|
# Update path to a value other than default, but still in-memory
|
||||||
default_conf.update({'db_url': 'sqlite:///tmp/freqtrade2_test.sqlite'})
|
filename = f"{tmpdir}/freqtrade2_test.sqlite"
|
||||||
create_engine_mock = mocker.patch('freqtrade.persistence.models.create_engine', MagicMock())
|
assert not Path(filename).is_file()
|
||||||
|
|
||||||
|
default_conf.update({'db_url': f'sqlite:///{filename}'})
|
||||||
|
|
||||||
init_db(default_conf['db_url'], default_conf['dry_run'])
|
init_db(default_conf['db_url'], default_conf['dry_run'])
|
||||||
assert create_engine_mock.call_count == 1
|
assert Path(filename).is_file()
|
||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tmp/freqtrade2_test.sqlite'
|
|
||||||
|
|
||||||
|
|
||||||
def test_init_invalid_db_url(default_conf):
|
def test_init_invalid_db_url(default_conf):
|
||||||
@ -49,15 +51,16 @@ def test_init_prod_db(default_conf, mocker):
|
|||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite'
|
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.sqlite'
|
||||||
|
|
||||||
|
|
||||||
def test_init_dryrun_db(default_conf, mocker):
|
def test_init_dryrun_db(default_conf, tmpdir):
|
||||||
default_conf.update({'dry_run': True})
|
filename = f"{tmpdir}/freqtrade2_prod.sqlite"
|
||||||
default_conf.update({'db_url': constants.DEFAULT_DB_DRYRUN_URL})
|
assert not Path(filename).is_file()
|
||||||
|
default_conf.update({
|
||||||
create_engine_mock = mocker.patch('freqtrade.persistence.models.create_engine', MagicMock())
|
'dry_run': True,
|
||||||
|
'db_url': f'sqlite:///{filename}'
|
||||||
|
})
|
||||||
|
|
||||||
init_db(default_conf['db_url'], default_conf['dry_run'])
|
init_db(default_conf['db_url'], default_conf['dry_run'])
|
||||||
assert create_engine_mock.call_count == 1
|
assert Path(filename).is_file()
|
||||||
assert create_engine_mock.mock_calls[0][1][0] == 'sqlite:///tradesv3.dryrun.sqlite'
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
|
Loading…
Reference in New Issue
Block a user