def test_sms_notification_comment(self):
     if not settings.TEST_SMS: return
     
     event = Event(**{
         u'where': 'test',
         u'when': timestamp(),
         u'what': 'test',
         u'broadcast': False,
         u'posted_from': [37.422834216666665, -122.08536667833332],
         u'creator': self.get_user()[u'username'],
     })
     event.save()
     
     number = '+16475551234'
     name = 'Testy Smoth'
     
     reg, out, is_user = SMS.register(event, [{u'number':number, 
                                               u'name':name}])
     self.assertEqual(len(reg), 1, 'correct ammout registered')
     
     result = notifications.send(reg[0][u'id'], 
                                 {u'type': 'comment', 
                                  u'event_revision': event[u'revision'],
                                  u'event_id': event[u'id'],
                                  u'comment': 'my awesome comment',
                                  u'commenter': self.make_user()})
     
     self.assertEqual(len(result), 1, 'the correct number of notifications '
                                      'were sent')
     self.assertTrue(result[0], 'the notification was sent correctly')
示例#2
0
 def invite(self, usernames=None, contacts=None, tz=None):
     if usernames is not None:
         #prevent people from inviting themselves
         if self[u'creator'] in usernames:
             usernames.remove(self[u'creator'])
         # convert usernames to user objects
         users = list(User.find({u'username': {'$in': usernames}}))
     else:
         users = list()
     ret = None
     if contacts is not None:
         registered, out_of_numbers, has_username = SMS.register(self, 
                 contacts, tz=tz)
         users += has_username
         users += [reg for reg in registered if reg not in users]
         if len(out_of_numbers) > 0:
             ret = out_of_numbers
     
     for user in users:
         Attendant(user=user[u'id'], event=self[u'id']).save()
         #send the invite notification
         if user[u'username'] is not None: name = user[u'username']
         else: name = user[u'id']
         
         notifications.send(name, {u'type': 'invite', 
                                   u'event_revision': self[u'revision'],
                                   u'event_id': self[u'id']})
     return ret
 def test_sms_notification_creation(self):
     if not settings.TEST_SMS: return
     
     user = User(username='******',
                 password='******',
                 number='+16666666666')
     user.save()
     
     event = Event(**{
         u'where': 'test',
         u'when': timestamp(),
         u'what': 'test',
         u'broadcast': False,
         u'posted_from': [37.422834216666665, -122.08536667833332],
         u'creator': user[u'username'],
     })
     event.save()
     
     number = '+16475551234'
     name = 'Testy Smoth'
     
     reg, out, is_user = SMS.register(event, [{u'number':number, u'name':name},
                                              {u'number':user[u'number'], 
                                               u'name':name}])
     
     self.assertEqual(len(reg), 1, 'correct ammout registered')
     self.assertEqual(len(out), 0, 'correct ammout out of numbers')
     self.assertEqual(len(is_user), 1, 'correct ammout are already users')
     
     reged = reg[0]
     
     self.assertEqual(reged.__class__, User)
     self.assertTrue(u'id' in reged)
     
     result = notifications.send(reged[u'id'], 
                                 {u'type': 'invite', 
                                  u'event_revision': event[u'revision'],
                                  u'event_id': event[u'id']})
     
     self.assertEqual(len(result), 1, 'the correct number of notifications '
                                      'were sent')
     self.assertTrue(result[0], 'the notification was sent correctly')