From 49266fc4b8a9478700ec7040d7fb153035951fdc Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Sat, 12 May 2018 10:29:26 +0200 Subject: [PATCH] Add migration test --- freqtrade/tests/test_persistence.py | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py index db8a5e9bd..8c3ffeb6a 100644 --- a/freqtrade/tests/test_persistence.py +++ b/freqtrade/tests/test_persistence.py @@ -4,7 +4,7 @@ import os import pytest from sqlalchemy import create_engine -from freqtrade.persistence import Trade, init, clean_dry_run_db +from freqtrade.persistence import Trade, init, clean_dry_run_db, check_migrate @pytest.fixture(scope='function') @@ -375,3 +375,40 @@ def test_clean_dry_run_db(default_conf, fee): # We have now only the prod assert len(Trade.query.filter(Trade.open_order_id.isnot(None)).all()) == 1 + + +def test_migrate(default_conf, fee): + create_table_old = """CREATE TABLE IF NOT EXISTS "trades" ( + id INTEGER NOT NULL, + exchange VARCHAR NOT NULL, + pair VARCHAR NOT NULL, + is_open BOOLEAN NOT NULL, + fee FLOAT NOT NULL, + open_rate FLOAT, + close_rate FLOAT, + close_profit FLOAT, + stake_amount FLOAT NOT NULL, + amount FLOAT, + open_date DATETIME NOT NULL, + close_date DATETIME, + open_order_id VARCHAR, + PRIMARY KEY (id), + CHECK (is_open IN (0, 1)) + );""" + insert_table_old = """INSERT INTO trades (exchange, pair, is_open, fee, + open_rate, stake_amount, amount, open_date) + VALUES ('BITTREX', 'BTC_ETC', 1, {}, + 0.00258580, 0.002, 0.7715262081, + '2017-11-28 12:44:24.000000')""".format(fee.return_value) + engine = create_engine('sqlite://') + engine.execute(create_table_old) + engine.execute(insert_table_old) + init(default_conf, engine) + assert len(Trade.query.filter(Trade.id == 1).all()) == 1 + trade = Trade.query.filter(Trade.id == 1).first() + assert trade.fee_open == fee.return_value + assert trade.fee_close == fee.return_value + assert trade.open_rate_requested is None + assert trade.close_rate_requested is None + +