Esempio n. 1
0
 def test_sms_reply_comment(self):
     if not settings.TEST_SMS: return
     
     user, event, smsuser = self.prep_for_response_sms()
     
     comment = 'This is a comment'
     
     response = self.post('/extras/SMS/', args={'From': smsuser[u'number'],
                                                'To': settings.TWILIO_NUMBERS[0],
                                                'Body': comment})
     self.assertEqual(response.status, 200)
     
     db_comment = Comment.get({'event': event[u'id']})
     
     self.assertNotEqual(db_comment, None, 'Comment exists')
     self.assertEqual(comment, db_comment[u'comment'], 'comment body matches')
Esempio n. 2
0
 def post(self, event_id):
     #make sure the event exists
     event = Event.get(event_id)
     if not event: raise HTTPError(404)
     
     #grab the data
     body = self.body_dict()
     #comment body is required, and must have content
     if not u'comment' in body or len(body[u'comment']) == 0:
         raise HTTPError(400)
     
     #nonce is optional
     if u'nonce' in body:
         #if another comment exists with this nonce, it's a double-post
         if Comment.get({u'nonce': body[u'nonce'],
                         u'event': event[u'id'], 
                         u'user': self.get_session()[u'username']}):
             raise HTTPError(409)
     
     commenter = self.get_session()[u'username']
     
     #create the comment
     Comment(**{
         u'comment': body[u'comment'],
         u'event': event[u'id'],
         u'username': commenter,
     }).save()
     
     #Send out the comment notifications
     usernames = Attendant.to_notify(event, skip=[commenter])
     for username in usernames:
         notifications.send(username, {u'type': 'comment',
                                       u'event_revision': event[u'revision'],
                                       u'event_id': event[u'id'],
                                       u'comment': body[u'comment'],
                                       u'commenter': commenter})