Skip to content

Instantly share code, notes, and snippets.

@danslimmon
Last active December 29, 2015 06:59
Show Gist options
  • Save danslimmon/7633178 to your computer and use it in GitHub Desktop.
Save danslimmon/7633178 to your computer and use it in GitHub Desktop.
Test of barcode learning opp creation and notification for https://github.com/danslimmon/oscar/issues/13
#!/usr/bin/python
import os
os.chdir('/var/oscar')
import sys
sys.path.append('.')
print 'sys.path: '
print sys.path
from datetime import datetime
import trello
from lib import trellodb
from lib import conf
from twilio.rest import TwilioRestClient
def create_barcode_opp(trello_db, barcode):
"""Creates a learning opportunity for the given barcode and writes it to Trello.
Returns the dict."""
opp = {
'type': 'barcode',
'opp_id': 'testabc123',
'barcode': barcode,
'created_dt': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
}
trello_db.insert('learning_opportunities', opp)
return opp
def publish_barcode_opp(opp):
client = TwilioRestClient(conf.get()['twilio_sid'], conf.get()['twilio_token'])
message = client.sms.messages.create(body='''Test for https://github.com/danslimmon/oscar/issues/13''',
to='+{0}'.format(conf.get()['twilio_dest']),
from_='+{0}'.format(conf.get()['twilio_src']))
trello_api = trello.TrelloApi(conf.get()['trello_app_key'])
trello_api.set_token(conf.get()['trello_token'])
trello_db = trellodb.TrelloDB(trello_api, conf.get()['trello_db_board'])
# First we test the creation of a barcode learning opportunity
print 'Before creating barcode opp, the contents of learning_opportunities is:'
print
print trello_db.get_all('learning_opportunities')
opp = create_barcode_opp(trello_db, '01234567890')
print
print 'After creating barcode opp, the contents of learning_opportunities is:'
print trello_db.get_all('learning_opportunities')
# Now we test the notification system
print
print 'Testing notification'
publish_barcode_opp(opp)
print
print 'You should receive a text via Twilio now...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment