def test_parsing_with_one_coin(self): ping('BTC') btc = Coin.get(Coin.symbol == 'BTC') btc_ticker = Ticker.get(Ticker.coin == btc) self.assertEqual(btc_ticker.price, Decimal('56.12345678')) self.assertEqual(btc_ticker.price_change_day_pct, Decimal('-2.33334567'))
def test_parsing_with_four_character_symbol(self): coin = Coin.create(name='foocoin', symbol='DASH') ping('DASH') dash = Coin.get(Coin.symbol == 'DASH') ticker = Ticker.get(Ticker.coin == dash) self.assertEqual(ticker.price, Decimal('56.12345678')) self.assertEqual(ticker.price_change_day_pct, Decimal('-1.23456789'))
def test_parsing_with_one_coin(self, check_global_timed_game, check_price_alerts_mock, mock_ticker, mock_coin): mock_coin.get.return_value = Coin(symbol='FOO', name='Foocoin') ping('FOO') mock_ticker.create.assert_called_with( coin=mock_coin.get.return_value, price=Decimal('56.12345678'), price_change_day_pct=Decimal('-1.23456789'), )
def test_parsing_with_many_coins(self): ping('BTC', 'ETH') btc = Coin.get(Coin.symbol == 'BTC') eth = Coin.get(Coin.symbol == 'ETH') btc_ticker = Ticker.get(Ticker.coin == btc) eth_ticker = Ticker.get(Ticker.coin == eth) self.assertEqual(btc_ticker.price, Decimal('56.12345678')) self.assertEqual(btc_ticker.price_change_day_pct, Decimal('-1.23456789')) self.assertEqual(eth_ticker.price, Decimal('42.98765432')) self.assertEqual(eth_ticker.price_change_day_pct, Decimal('-8.98765432'))
def test_parsing_with_many_ping_calls(self): ping('BTC') btc = Coin.get(Coin.symbol == 'BTC') btc_ticker = Ticker.get(Ticker.coin == btc) self.assertEqual(btc_ticker.price, Decimal('56.12345678')) self.assertEqual(btc_ticker.price_change_day_pct, Decimal('-2.33334567')) Ticker.delete().execute() ping('BTC') btc = Coin.get(Coin.symbol == 'BTC') btc_ticker = Ticker.get(Ticker.coin == btc) self.assertEqual(btc_ticker.price, Decimal('56.12345678')) self.assertEqual(btc_ticker.price_change_day_pct, Decimal('-2.33334567'))
def test_parsing_with_many_coins(self, check_global_timed_game, check_price_alerts_mock, mock_ticker, mock_coin): side_effect = [ Coin(symbol='FOO', name='Foocoin'), Coin(symbol='BAR', name='Barcoin'), ] mock_coin.get.side_effect = side_effect ping('FOO', 'BAR') calls = [ call( coin=side_effect[0], price=Decimal('56.12345678'), price_change_day_pct=Decimal('-1.23456789'), ), call( coin=side_effect[1], price=Decimal('42.98765432'), price_change_day_pct=Decimal('-1.23456789'), ), ] mock_ticker.create.assert_has_calls(calls, any_order=False)
def test_price_alerts(self): os.environ['NOMICS_BASE_URL'] = 'foo' profile = Profile.create(username='******', hashed_password='******') coin = Coin.create(name='foocoin', symbol='FOO') alert = PriceAlert.create( profile=profile, above=True, coin=coin, strike_price=Decimal(0.1), ) alert = PriceAlert.create( profile=profile, above=False, coin=coin, strike_price=Decimal(0.1), ) ping('FOO') self.assertEqual(1, Notification.select().count()) # ok, the line below throws an exception which causes all other tests to fail # as tearDown is not called and because db is in inconsistent state notif = Notification.get(Notification.profile == profile)
def test_parsing_with_no_coins(self, mock_ticker, mock_coin): ping() mock_ticker.assert_not_called() mock_coin.assert_not_called()
def test_crashes_with_empty_api_response(self, mock_ticker, mock_coin): with self.assertRaises(Exception): ping('FOO')
def test_parsing_with_no_coins(self): num_tickers_before = Ticker.select().count() ping() num_tickers_after = Ticker.select().count() self.assertEqual(num_tickers_before, num_tickers_after)
def test_raises_error_if_token_not_exists(self): with self.assertRaises(Exception): ping('FOO')