Skip to content

Commit

Permalink
1) Changed test examples to conform better to Twilio python client API.
Browse files Browse the repository at this point in the history
2) Moved configuration error checking to base template.
3) Added fudging to base CSS.
  • Loading branch information
RobSpectre committed Sep 23, 2012
1 parent e9981fa commit ba50ab6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 64 deletions.
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ def client():
capability.allow_client_incoming("joey_ramone")
capability.allow_client_outgoing(app.config['TWILIO_APP_SID'])
token = capability.generate()
return render_template('client.html', token=token,
params = {'token': token}
return render_template('client.html', params=params,
configuration_error=configuration_error)


# Installation success page
@app.route('/')
def index():
params = {
'voice_request_url': url_for('.voice', _external=True),
'sms_request_url': url_for('.sms', _external=True),
'client_url': url_for('.client', _external=True)}
'Voice Request URL': url_for('.voice', _external=True),
'SMS Request URL': url_for('.sms', _external=True),
'Client URL': url_for('.client', _external=True)}
return render_template('index.html', params=params)


Expand Down
1 change: 1 addition & 0 deletions static/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ body, html {

#content {
width: 960px;
height: 250px;
margin: 0 auto;
padding: 70px 0 0 0;
}
Expand Down
51 changes: 49 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<title>{% block title %}{% endblock %}
- Twilio Hackpack for Heroku and Flask</title>
{% block head %}{% endblock %}
<link rel="stylesheet" type="text/css"
href="http://static1.twilio.com/packages/base.css"/>
<link rel="stylesheet" type="text/css"
href="http://static0.twilio.com/packages/buttons.css" />
<link rel="stylesheet" type="text/css"
href="/static/styles/index.css" />
<link rel="shortcut icon" href="/static/images/favicon.ico" />
<link rel="apple-touch-icon"
href="http://static1.twilio.com/packages/favicons/img/Twilio_57.png" />
Expand All @@ -13,6 +19,47 @@
href="http://static0.twilio.com/packages/favicons/img/Twilio_114.png" />
</head>
<body>
{% block content %}{% endblock %}
</body>
<div id="container">
<header>
<div id="header">
{% if params['config_errors'] %}
<h1 class="section-heading">Configuration Error</h1>
{% else %}
<h1 class="section-heading">{% block header %}{% endblock %}</h1>
{% endif %}
</div>
</header>
<section>
<div id="content">
{% if configuration_error %}
<h2 class="section-heading">We just need to set a few more
configuration options.</h2>
<p class="blurb">Check your local_settings.py to set these missing
options:</p>
<dl id="url_list">
<dt>Error</dt>
<dd>{{ configuration_error }}</dd>
</dl>
{% else %}
<h2 class="section-heading">{% block message %}{% endblock %}</h2>
<p class="blurb">{% block blurb %}{% endblock %}</p>
{% block content %}{% endblock %}
{% endif %}
</div>
</section>
<footer>
<p class="footer">
Source on <a
href="https://github.com/RobSpectre/Mobile-App-Distribution-with-SMS">Github</a>.
Released under <a
href="http://www.opensource.org/licenses/mit-license.html">
MIT license</a>.
Lovingly crafted by <a id="twiliocon-2011-link"
href="http://www.meetup.com/Twilio/New-York-NY/">
Twilio New York</a>.
</p>
</footer>
</div>
{% block footer_js %}{% endblock %}
</body>
</html>
2 changes: 1 addition & 1 deletion templates/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</script>
<script type="text/javascript">

Twilio.Device.setup("{{ token }}");
Twilio.Device.setup("{{ params['token'] }}");

Twilio.Device.ready(function (device) {
$("#log").text("Ready");
Expand Down
65 changes: 17 additions & 48 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,23 @@
{% extends "base.html" %}

{% block title %}Installation Success!{% endblock %}
{% block title %}Successfully Deployed{% endblock %}

{% block head %}
<link rel="stylesheet" type="text/css"
href="http://static1.twilio.com/packages/base.css"/>
<link rel="stylesheet" type="text/css"
href="http://static0.twilio.com/packages/buttons.css" />
<link rel="stylesheet" type="text/css"
href="/static/styles/index.css" />
{% endblock %}
{% block header %}Success!{% endblock %}

{% block message %}You deployed Twilio Hackpack for Heroku and Flask{% endblock %}

{% block blurb %}Here are some helpful links to get you started:{% endblock
%}

{% block content %}
<div id="container">
<header>
<div id="header">
<h1 class="section-heading">Success!</h1>
</div>
</header>
<section>
<div id="content">
<h2 class="section-heading">You deployed Twilio Hackpack
for Heroku and Flask.</h2>
<p class="blurb">Here are some important links:</p>
<a href="https://www.twilio.com/user/account/apps"
class="button">Configure Twilio</a>
<dl id="url_list">
<dt>Voice Request URL</dt>
<dd><a href="{{params['voice_request_url'] }}">
{{params['voice_request_url'] }}</a></dd>
<dt>SMS Request URL</dt>
<dd><a href="{{params['sms_request_url'] }}">
{{params['sms_request_url'] }}</a></dd>
<dt>Client URL</dt>
<dd><a href="{{params['client_url'] }}">
{{params['client_url'] }}</a></dd>
</dl>
</div>
</section>
<footer>
<p class="footer">
Source on <a
href="https://github.com/RobSpectre/Twilio-Hackpack-for-Heroku-and-Flask">Github</a>.
Released under <a
href="http://www.opensource.org/licenses/mit-license.html">
MIT license</a>.
Lovingly crafted by <a id="twiliocon-2011-link"
href="http://www.meetup.com/Twilio/New-York-NY/">
Twilio New York</a>.
</p>
</footer>
</div>
<a href="https://www.twilio.com/user/account/phone-numbers/incoming"
class="button">Configure Twilio</a>

<dl id="url_list">
{% for key, value in params.iteritems() %}
<dt>{{key}}</dt>
<dd>{{value}}</dd>
{% endfor %}
</dl>

{% endblock %}
22 changes: 13 additions & 9 deletions tests/test_twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from .context import app


app.config['TWILIO_ACCOUNT_SID'] = 'ACxxxxxx'
app.config['TWILIO_AUTH_TOKEN'] = 'yyyyyyyyy'
app.config['TWILIO_ACCOUNT_SID'] = 'ACxxxxxx'
app.config['TWILIO_AUTH_TOKEN'] = 'yyyyyyyyy'
app.config['TWILIO_CALLER_ID'] = '+15558675309'


Expand All @@ -18,22 +18,24 @@ def assertTwiML(self, response):
"</Response>: %s" % response.data)
self.assertEqual("200 OK", response.status)

def sms(self, body, path='/sms', to=app.config['TWILIO_CALLER_ID'],
from_='+15558675309'):
def sms(self, body, url='/sms', to=app.config['TWILIO_CALLER_ID'],
from_='+15558675309', extra_params=None):
params = {
'SmsSid': 'SMtesting',
'AccountSid': app.config['TWILIO_ACCOUNT_SID'],
'To': to,
'To': to,
'From': from_,
'Body': body,
'FromCity': 'BROOKLYN',
'FromState': 'NY',
'FromCountry': 'US',
'FromZip': '55555'}
return self.app.post(path, data=params)
if extra_params:
params = dict(params.items() + extra_params.items())
return self.app.post(url, data=params)

def call(self, path='/voice', to=app.config['TWILIO_CALLER_ID'],
from_='+15558675309', digits=None):
def call(self, url='/voice', to=app.config['TWILIO_CALLER_ID'],
from_='+15558675309', digits=None, extra_params=None):
params = {
'CallSid': 'CAtesting',
'AccountSid': app.config['TWILIO_ACCOUNT_SID'],
Expand All @@ -47,7 +49,9 @@ def call(self, path='/voice', to=app.config['TWILIO_CALLER_ID'],
'FromZip': '55555'}
if digits:
params['Digits'] = digits
return self.app.post(path, data=params)
if extra_params:
params = dict(params.items() + extra_params.items())
return self.app.post(url, data=params)


class ExampleTests(TwiMLTest):
Expand Down

0 comments on commit ba50ab6

Please sign in to comment.