예제 #1
0
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')
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')
예제 #3
0
 def setUp(self):
     self.dispatcher = Dispatcher()
예제 #4
0
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"),
 def setUp(self):
     self.dispatcher = Dispatcher()
예제 #6
0
from app.i18n import _
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'),