def test_6_strategies(self): self.assertEqual(pyfirebasestockscli.app(['-s']), 0) store = firestore.client() strategy_docs = list( map(lambda x: x.to_dict(), store.collection('strategies').stream())) self.assertEqual(len(strategy_docs), 1) self.assertEqual(strategy_docs[0]['name'], 'test strategy')
def test_4_update_missing_stocks(self): self.assertEqual(pyfirebasestockscli.app(['-p']), 0) store = firestore.client() stocks_doc = list( map(lambda x: x.to_dict(), store.collection('stocks').stream())) for stock in stocks_doc: is_ok = all([ price_sym is not None for key in ['last_price_usd', 'last_price_eur'] for price_sym in stock[key] ]) self.assertTrue(is_ok, f'Stock has incorrect prices: {stock}')
def test_5_tag_export(self): self.assertEqual(pyfirebasestockscli.app(['-t']), 0) json_file = os.path.join(root_dir, 'tags.json') self.assertTrue(os.path.exists(json_file)) with open(json_file) as json_file: data = json.load(json_file) # check for all types self.assertTrue( all( map( lambda x: x in data, ['indices', 'countries', 'industries'], ))) data['indices'].sort() self.assertEqual(len(data['indices']), 2) self.assertEqual(data['indices'][0], 'DAX') self.assertEqual(data['indices'][1], 'OMX Helsinki 15')
def test_2_create_fastmode(self): self.assertEqual(pyfirebasestockscli.app(['-c']), 0) store = firestore.client() tag_docs = list( map(lambda x: x.to_dict(), store.collection('tags').stream())) self.assertEqual(len(tag_docs), 3) # check for all keys self.assertTrue( all(map(lambda x: 'tags' in x and 'type' in x, tag_docs))) # check for all types self.assertTrue( all( map( lambda x: any(map(lambda y: x == y['type'], tag_docs)), ['indices', 'countries', 'industries'], ))) indices = next(filter(lambda x: x['type'] == 'indices', tag_docs)) self.assertIsNotNone(indices) self.assertEqual(len(indices['tags']), 1) self.assertEqual(indices['tags'][0], 'DAX') stocks_doc = list( map(lambda x: x.to_dict(), store.collection('stocks').stream())) self.assertEqual(len(stocks_doc), 30) # check all stock attributes self.assertTrue( all( map( lambda x: all(map(lambda y: y in x, STOCK_ATTR)), stocks_doc, ))) # check if all prices null self.assertTrue( all( map( lambda y: y['last_price_eur'] is None and y[ 'last_price_usd'] is None, stocks_doc, )))
def test_7_updates(self): self.assertEqual(pyfirebasestockscli.app(['-u']), 0) store = firestore.client() stocks_docs = list( map(lambda x: x.to_dict(), store.collection('stocks').stream())) filter_names = [ 'StockIsHot2Month', 'StockIsHot3Month', 'StockIsHot6Month', 'SecureHotH2Month', 'SecureHotH3Month', 'SecureHotH6Month', 'SecureHot2Month', 'SecureHot3Month', 'SecureHot6Month', 'AdxP14', 'AdxP5', 'RsiP14', 'RsiP5', 'DividendKings', # 'LevermannScore', # 'PiotroskiScore', # 'PriceTargetScore', ] # check if custom filter exists for stock in filter(lambda x: 'name' in x and x['name'] == 'adidas AG', stocks_docs): is_ok = all( map( lambda x, s=stock: f'{x}_status' in s and f'{x}_value' in s, filter_names, )) self.assertTrue(is_ok, f'Stock has not all filter: {stock}')
#!/usr/bin/env python # -*- coding: utf-8 -*- """ pyfirebasestockscli Copyright 2019 Slash Gordon Use of this source code is governed by an MIT-style license that can be found in the LICENSE file. """ import sys from pyfirebasestockscli import app if __name__ == "__main__": sys.exit(app())
def test_0_cli(self): self.assertEqual(pyfirebasestockscli.app([]), 0)