def test_scheduled_default_invites(self): try: d = SMSInviteMessage.objects.get( country_calling_code = SMSInviteMessage.COUNTRY_DEFAULT_VALUE, time_delay_hours = 0) d.message_template = 'Hi ${name}. ${inviter} shared an album: ${album}' d.save(update_fields=['message_template']) except SMSInviteMessage.DoesNotExist: d = SMSInviteMessage.objects.create( country_calling_code = SMSInviteMessage.COUNTRY_DEFAULT_VALUE, time_delay_hours = 0, message_template = 'Hi ${name}. ${inviter} shared an album: ${album}') SMSInviteMessage.objects.create( country_calling_code = SMSInviteMessage.COUNTRY_DEFAULT_VALUE, message_template = 'Hi ${name}. ${inviter} has been waiting 2 hours for you to view: ${album}', time_delay_hours = 2) SMSInviteMessage.objects.create( country_calling_code = SMSInviteMessage.COUNTRY_DEFAULT_VALUE, message_template = 'An entire day has passed', time_delay_hours = 24) the_time = datetime.datetime(2000, 01, 02, tzinfo=utc) new_user = User.objects.create_user(nickname='barney') phone_number = PhoneNumber.objects.create( phone_number = '+12127182003', user = new_user, date_created = the_time, verified = False) AlbumMember.objects.create( user = new_user, album = self.party_album, added_by_user = self.amanda, datetime_added = the_time, album_admin = False) link_code = invites_manager.send_invite(self.amanda, phone_number, the_time) invite_url_prefix = 'https://i.useglance.com' link = link_code.get_invite_page(invite_url_prefix) self.assertEqual(send_sms.testing_outbox, [('+12127182003', u'Hi barney. amanda shared an album: Party\n' + link, '+12127182002')]) send_sms.testing_outbox = [] invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc))
def handle(self, *args, **options): now = timezone.now() num_sent = invites_manager.process_scheduled_invites(now) self.stdout.write('Successfully sent %d invites' % num_sent)
added_by_user = self.amanda, datetime_added = the_time, album_admin = False) link_code = invites_manager.send_invite(self.amanda, phone_number, the_time) invite_url_prefix = 'https://i.useglance.com' link = link_code.get_invite_page(invite_url_prefix) self.assertEqual(send_sms.testing_outbox, [('+12127182003', u'Hi barney. amanda shared an album: Party\n' + link, '+12127182002')]) send_sms.testing_outbox = [] invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc)) self.assertEqual(send_sms.testing_outbox, []) invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 1, 0, 0, tzinfo=utc)) self.assertEqual(send_sms.testing_outbox, []) invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 2, 0, 0, tzinfo=utc)) self.assertEqual(send_sms.testing_outbox, [(u'+12127182003', u'Hi barney. amanda has been waiting 2 hours for you to view: Party\n' + link, '+12127182002')]) send_sms.testing_outbox = [] invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 3, 0, 0, tzinfo=utc)) self.assertEqual(send_sms.testing_outbox, []) send_sms.testing_outbox = [] invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 23, 0, 0, tzinfo=utc)) self.assertEqual(send_sms.testing_outbox, []) send_sms.testing_outbox = [] invites_manager.process_scheduled_invites(datetime.datetime(2000, 01, 02, 23, 59, 0, tzinfo=utc))