def test_rsvp_view(self):
        # Setup data for RSVP -> StudyGroup + Signup + Meeting in future

        c = Client()
        study_group = StudyGroup.objects.get(pk=1)
        meeting_time = timezone.now() + datetime.timedelta(days=2)
        study_group_meeting = StudyGroupMeeting(
            study_group=study_group,
            meeting_time=meeting_time.time(),
            meeting_date=meeting_time.date())
        study_group_meeting.save()

        signup_data = self.APPLICATION_DATA.copy()
        resp = c.post('/en/signup/foo-bob-1/', signup_data)
        self.assertRedirects(resp, '/en/signup/1/success/')
        self.assertEquals(Application.objects.active().count(), 1)

        qs = gen_rsvp_querystring(signup_data['email'], study_group.pk,
                                  study_group_meeting.meeting_datetime(),
                                  'yes')
        url = '/en/rsvp/?{0}'.format(qs)

        # Generate RSVP link
        # visit link
        self.assertEqual(0, Rsvp.objects.count())
        resp = c.get(url)
        self.assertEqual(1, Rsvp.objects.count())
        self.assertTrue(Rsvp.objects.first().attending)

        qs = gen_rsvp_querystring(signup_data['email'], study_group.pk,
                                  study_group_meeting.meeting_datetime(), 'no')
        url = '/en/rsvp/?{0}'.format(qs)
        self.assertEqual(1, Rsvp.objects.count())
        resp = c.get(url)
        self.assertEqual(1, Rsvp.objects.count())
        self.assertFalse(Rsvp.objects.first().attending)

        # Test RSVP with mobile number
        signup_data = self.APPLICATION_DATA.copy()
        del signup_data['email']
        signup_data['mobile'] = '+12812347890'

        resp = c.post('/en/signup/foo-bob-1/', signup_data)
        self.assertRedirects(resp, '/en/signup/1/success/')
        self.assertEquals(Application.objects.active().count(), 2)

        qs = gen_rsvp_querystring(signup_data['mobile'], study_group.pk,
                                  study_group_meeting.meeting_datetime(),
                                  'yes')
        url = '/en/rsvp/?{0}'.format(qs)

        # Generate RSVP link
        # visit link
        c = Client()
        Rsvp.objects.all().delete()
        self.assertEqual(0, Rsvp.objects.count())
        resp = c.get(url)
        self.assertEqual(1, Rsvp.objects.count())
        self.assertTrue(Rsvp.objects.first().attending)
Exemplo n.º 2
0
def send_reminder(reminder):
    to = [su.email for su in reminder.study_group.application_set.filter(accepted_at__isnull=False, contact_method=Application.EMAIL)]
    if reminder.study_group_meeting:
        # this is a reminder and we need RSVP links
        for email in to:
            # TODO hardcoded domain
            domain = 'https://chicago.p2pu.org'
            url = reverse('studygroups_rsvp')
            yes_qs = rsvp.gen_rsvp_querystring(
                email,
                reminder.study_group.pk,
                reminder.study_group_meeting.meeting_time,
                'yes'
            )
            yes_link = '{0}{1}?{2}'.format(domain,url,yes_qs)
            no_qs = rsvp.gen_rsvp_querystring(
                email,
                reminder.study_group.pk,
                reminder.study_group_meeting.meeting_time,
                'no'
            )
            no_link = '{0}{1}?{2}'.format(domain,url,no_qs)
            email_body = reminder.email_body
            email_body = re.sub(r'<!--RSVP:YES.*-->', yes_link, email_body)
            email_body = re.sub(r'<!--RSVP:NO.*-->', no_link, email_body)
            send_mail(
                    reminder.email_subject.strip('\n'),
                    email_body,
                    settings.DEFAULT_FROM_EMAIL,
                    [email],
                    fail_silently=False
            )
    else:
        send_mail(reminder.email_subject.strip('\n'), reminder.email_body, settings.DEFAULT_FROM_EMAIL, to, fail_silently=False)

    # send SMS
    tos = [su.mobile for su in reminder.study_group.application_set.filter(accepted_at__isnull=False, contact_method=Application.TEXT)]
    errors = []
    for to in tos:
        if reminder.study_group_meeting:
            #TODO - insert RSVP link
            send_message(to, reminder.sms_body)
        try:
            send_message(to, reminder.sms_body)
        except twilio.TwilioRestException as e:
            errors.push[e]
    if len(errors):
        #TODO: log errors
        raise Exception(errors)

    reminder.sent_at = timezone.now()
    reminder.save()
Exemplo n.º 3
0
 def test_rsvp_signing(self):
     meeting_date = timezone.datetime(2015,
                                      9,
                                      17,
                                      17,
                                      0,
                                      tzinfo=timezone.utc)
     qs = gen_rsvp_querystring('*****@*****.**', '1', meeting_date, 'yes')
     sig = urllib.parse.parse_qs(qs).get('sig')[0]
     self.assertTrue(
         check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes',
                              sig))
     self.assertFalse(
         check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes',
                              sig))
     self.assertFalse(
         check_rsvp_signature('*****@*****.**', '2', meeting_date, 'yes',
                              sig))
     self.assertFalse(
         check_rsvp_signature('*****@*****.**', '1', meeting_date, 'no',
                              sig))
     meeting_date = timezone.datetime(2015,
                                      9,
                                      18,
                                      17,
                                      0,
                                      tzinfo=timezone.utc)
     self.assertFalse(
         check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes',
                              sig))
Exemplo n.º 4
0
 def test_rsvp_signing(self):
     meeting_date = timezone.datetime(2015,9,17,17,0, tzinfo=timezone.utc)
     qs = gen_rsvp_querystring('*****@*****.**', '1', meeting_date, 'yes')
     sig = urlparse.parse_qs(qs).get('sig')[0]
     self.assertTrue(check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes', sig))
     self.assertFalse(check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes', sig))
     self.assertFalse(check_rsvp_signature('*****@*****.**', '2', meeting_date, 'yes', sig))
     self.assertFalse(check_rsvp_signature('*****@*****.**', '1', meeting_date, 'no', sig))
     meeting_date = timezone.datetime(2015,9,18,17,0, tzinfo=timezone.utc)
     self.assertFalse(check_rsvp_signature('*****@*****.**', '1', meeting_date, 'yes', sig))
Exemplo n.º 5
0
 def rsvp_no_link(self, email):
     domain = 'https://{0}'.format(settings.DOMAIN)
     url = reverse('studygroups_rsvp')
     no_qs = rsvp.gen_rsvp_querystring(email, self.study_group.pk,
                                       self.meeting_datetime(), 'no')
     return '{0}{1}?{2}'.format(domain, url, no_qs)