class DispatcherTest(unittest.TestCase): def setUp(self): self.dispatcher = Dispatcher() def test_dispatch_with_valid_command(self): self.dispatcher.route(ValidCommand, EchoAction) response = self.dispatcher.dispatch('data') self.assertEqual('data', response) response = self.dispatcher.dispatch('other data') self.assertEqual('other data', response) def test_dispatch_without_valid_command(self): self.dispatcher.route(InvalidCommand, EchoAction) self.assertRaises(NoRouteError, self.dispatcher.dispatch, 'no action') def test_dispatch_multiple_valid_commands(self): self.dispatcher.route(ValidCommand, EchoAction) self.dispatcher.route(ValidCommand, EchoAction) self.assertRaises(MultipleRouteError, self.dispatcher.dispatch, 'no action')
from app.model.sms_request import SmsRequest from app.model.user import User from app.util.flask_common import enable_json_error, log_request app = Flask(__name__) enable_json_error(app) @app.before_request def log(): log_request(app) dispatcher = Dispatcher() dispatcher.route(PlantCommand, PlantAction) dispatcher.route(HarvestCommand, HarvestAction) dispatcher.route(SellCommand, SellAction) dispatcher.route(QueryCommand, QueryAction) dispatcher.route(BroadcastCommand, BroadcastAction) @app.route("/v1/sms/twilio", methods=["POST"]) def incoming_twilio_sms(): sms = SmsRequest( id=SmsRequest.id(), from_number=request.form.get("From"), to_number=request.form.get("To"), body=request.form.get("Body"), twilio_message_id=request.form.get("MessageSid"), from_city=request.form.get("FromCity"),
from app.model.config import Config from app.model.sms_request import SmsRequest from app.model.user import User from app.util.flask_common import enable_json_error, log_request app = Flask(__name__) enable_json_error(app) @app.before_request def log(): log_request(app) dispatcher = Dispatcher() dispatcher.route(PlantCommand, PlantAction) dispatcher.route(HarvestCommand, HarvestAction) dispatcher.route(SellCommand, SellAction) dispatcher.route(QueryCommand, QueryAction) dispatcher.route(BroadcastCommand, BroadcastAction) @app.route('/v1/sms/twilio', methods=['POST']) def incoming_twilio_sms(): sms = SmsRequest(id=SmsRequest.id(), from_number=request.form.get('From'), to_number=request.form.get('To'), body=request.form.get('Body'), twilio_message_id=request.form.get('MessageSid'), from_city=request.form.get('FromCity'), from_state=request.form.get('FromState'),