def test_empty_text_loop(): price_tracker = price_tracker_fake("45") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) texter.check_alerts() assert len(twilio.messages) == 0 assert len(twilio.to) == 0
def test_invalid_number_below(capsys): price_tracker = price_tracker_fake("45") send_message = Mock() send_message.side_effect = (twilio.base.exceptions.TwilioRestException( Mock(), Mock())) texter = Texter() texter.set_clients(price_tracker, send_message) alert = Alert(symbol='BTC', price=100.0, condition=0, phone_number='5555') db.session.add(alert) db.session.commit() texter.check_alerts() out, err = capsys.readouterr() assert "Invalid number" in out
def test_single_entry_no_text(): price_tracker = price_tracker_fake("45") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alert = Alert(symbol='BTC', price=100.0, condition=1, phone_number='555-555-5555') db.session.add(alert) db.session.commit() texter.check_alerts() assert len(twilio.messages) == 0 assert len(twilio.to) == 0
def test_LTC(): price_tracker = price_tracker_fake("45") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alerts = [ Alert(symbol='LTC', price=1.0, condition=1, phone_number='555-555-5555') ] texter.text_greater_than(alerts, 3.0) assert len(twilio.messages) == 1 assert 'LTC' in twilio.messages[0]
def test_less_than_text(): price_tracker = price_tracker_fake("45") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alerts = [ Alert(symbol='BTC', price=50.0, condition=0, phone_number='555-555-5555') ] texter.text_less_than(alerts, 3.0) assert len(twilio.messages) == 1 assert "below" in twilio.messages[0] assert 'BTC' in twilio.messages[0] assert len(twilio.to) == 1 assert twilio.to[0] == '555-555-5555'
def test_single_text_loop_below(): price_tracker = price_tracker_fake("5") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alert = Alert(symbol='BTC', price=10.0, condition=0, phone_number='555-555-5555') db.session.add(alert) db.session.commit() texter.check_alerts() assert len(twilio.messages) == 1 assert len(twilio.to) == 1 assert 'below' in twilio.messages[0] assert 'BTC' in twilio.messages[0] assert twilio.to[0] == '555-555-5555'
def test_include_market_above(): price_tracker = price_tracker_fake("5") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alert = Alert(symbol='ETH', price=2, condition=1, phone_number='1234567890', market='coinbase') db.session.add(alert) db.session.commit() texter.check_alerts() assert len(twilio.messages) == 1 assert len(twilio.to) == 1 assert 'above' in twilio.messages[0] assert 'ETH' in twilio.messages[0] assert twilio.to[0] == '1234567890'
def test_percent_decrease_text(): price_tracker = price_tracker_fake("45", "-5") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alerts = [ Alert(symbol='BTC', percent=4.0, percent_duration=86400, condition=3, phone_number='555-555-5555') ] texter.text_percent_decrease(alerts, 5.0) assert len(twilio.messages) == 1 assert "decreased by 5.00%" in twilio.messages[0] assert "24 hours" in twilio.messages[0] assert 'BTC' in twilio.messages[0] assert len(twilio.to) == 1 assert twilio.to[0] == '555-555-5555'
def test_single_text_loop_decrease(): price_tracker = price_tracker_fake("5", "-5") twilio = twilio_fake() texter = Texter() texter.set_clients(price_tracker, twilio.send_message) alert = Alert(symbol='BTC', percent=4.0, percent_duration=86400, condition=3, phone_number='555-555-5555') db.session.add(alert) db.session.commit() texter.check_alerts() assert len(twilio.messages) == 1 assert len(twilio.to) == 1 assert 'decreased by' in twilio.messages[0] assert '24 hours' in twilio.messages[0] assert 'BTC' in twilio.messages[0] assert twilio.to[0] == '555-555-5555'