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_price_tracker_integration(): price_tracker = PriceTracker() 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', market='coinbase') db.session.add(alert) db.session.commit() texter.check_alerts()
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'
"""Module for creating the Flask app. More information provided in the create_app() docstring. """ from flask import Flask from moontracker.extensions import scheduler, bcrypt, login_manager, db from moontracker.extensions import socketio from moontracker.last_prices import broadcast_last_prices from moontracker.texter import Texter from moontracker.views.home.views import home_blueprint from moontracker.views.users.views import users_blueprint texter = Texter() def create_app(config): """Create app with specified config.""" app = Flask(__name__) app.config.from_object(config) register_extensions(app) register_blueprints(app) texter.set_clients() scheduler.start() return app def register_extensions(app):