def restore(): DB.drop() with open('data/portfolios.json', 'r') as f: portfolios = json.load(f) for portfolio in portfolios: try: Portfolio.new(portfolio) except Exception as e: return Result(success=False, message=str(e), severity='ERROR') with open('data/trades.json', 'r') as f: trades = json.load(f) trades.sort(key=lambda i: (i['port'], i['trade']['TradeDate'])) [TradeLog.commit_raw_trade(Raw.new(trade['trade']._id), trade['port']) for trade in trades] with open('data/raw.json', 'r') as f: raw = json.load(f) [Raw.new(r) for r in raw] return Result(success=True, message=f'Successfully restored {len(portfolios)} portfolios, {len(trades)} trades and \ {len(raw)} raw trades', severity='SUCCESS')
def setUpClass(cls): DB.connect(testing.DB_URL, db) DB.drop(db) print(f'\nSetting up test suite by deleting {db} database\n')