Exemple #1
0
    def test_send_custom_reminder_email(self, send_message):
        now = timezone.now()
        sg = StudyGroup.objects.get(pk=1)
        sg.timezone = now.strftime("%Z")
        sg.start_date = now - datetime.timedelta(days=5)
        sg.meeting_time = sg.start_date.time()
        sg.end_date = sg.start_date + datetime.timedelta(weeks=5)
        sg.save()
        sg = StudyGroup.objects.get(pk=1)

        data = self.APPLICATION_DATA
        data['study_group'] = sg
        application = Application(**data)
        accept_application(application)
        application.save()
        mail.outbox = []
        generate_all_meetings(sg)

        reminder = Reminder(
            study_group=sg,
            email_subject='Custom reminder',
            email_body='Test for extra reminders sent by facilitators',
            sms_body='Nothing to say here')
        reminder.save()
        self.assertEqual(Reminder.objects.all().count(), 1)
        reminder = Reminder.objects.all()[0]
        self.assertEqual(len(mail.outbox), 0)
        send_reminder(reminder)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(len(mail.outbox[0].bcc), 2)
        self.assertEqual(mail.outbox[0].bcc[0], data['email'])
        self.assertFalse(send_message.called)
Exemple #2
0
 def test_facilitator_reminder_email_links(self, send_message):
     now = timezone.now()
     sg = StudyGroup.objects.get(pk=1)
     sg.timezone = now.strftime("%Z")
     sg.start_date = now - datetime.timedelta(days=5)
     sg.meeting_time = sg.start_date.time()
     sg.end_date = sg.start_date + datetime.timedelta(weeks=5)
     sg.save()
     sg = StudyGroup.objects.get(pk=1)
     data = self.APPLICATION_DATA
     data['study_group'] = sg
     application = Application(**data)
     accept_application(application)
     application.save()
     generate_all_meetings(sg)
     self.assertEqual(Reminder.objects.all().count(), 5)
     reminder = Reminder.objects.all()[0]
     mail.outbox = []
     send_reminder(reminder)
     self.assertEqual(len(mail.outbox),
                      2)  # should be sent to facilitator & application
     self.assertEqual(mail.outbox[0].to[0], data['email'])
     self.assertEqual(mail.outbox[1].to[0], sg.facilitator.email)
     self.assertFalse(send_message.called)
     self.assertNotIn(
         '{0}/{1}/rsvp/'.format(settings.DOMAIN, get_language()),
         mail.outbox[1].alternatives[0][0])
     self.assertIn('{0}/{1}/'.format(settings.DOMAIN, get_language()),
                   mail.outbox[1].alternatives[0][0])
     self.assertNotIn(
         '{0}/{1}/optout/confirm/?user='.format(settings.DOMAIN,
                                                get_language()),
         mail.outbox[1].alternatives[0][0])
def message_send(request, study_group_id):
    # TODO - this piggy backs of Reminder, won't work of Reminder is coupled to Meeting
    study_group = get_object_or_404(StudyGroup, pk=study_group_id)
    form_class =  modelform_factory(Reminder, exclude=['study_group_meeting', 'created_at', 'sent_at', 'sms_body'], widgets={'study_group': HiddenInput})

    needs_mobile = study_group.application_set.active().exclude(mobile='').count() > 0
    if needs_mobile:
        form_class = modelform_factory(Reminder, exclude=['study_group_meeting', 'created_at', 'sent_at'], widgets={'study_group': HiddenInput})

    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            reminder = form.save()
            send_reminder(reminder)
            messages.success(request, 'Email successfully sent')
            url = reverse('studygroups_facilitator')
            return http.HttpResponseRedirect(url)
    else:
        form = form_class(initial={'study_group': study_group})

    context = {
        'study_group': study_group,
        'course': study_group.course,
        'form': form
    }
    return render(request, 'studygroups/email.html', context)
    def test_edit_reminder(self):
        c = Client()
        c.login(username='******', password='******')
        signup_data = self.APPLICATION_DATA.copy()
        resp = c.post('/en/signup/foo-bob-1/', signup_data)
        self.assertRedirects(resp, '/en/signup/1/success/')
        self.assertEqual(Application.objects.active().count(), 1)
        mail.outbox = []
        study_group = StudyGroup.objects.get(pk=1)
        study_group.start_date = datetime.date(2021, 3, 1)
        study_group.end_date = study_group.start_date + datetime.timedelta(
            weeks=5)
        study_group.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.assertEqual(Application.objects.active().count(), 1)

        generate_all_meetings(study_group)
        self.assertEqual(study_group.meeting_set.active().count(), 6)
        self.assertEqual(study_group.reminder_set.count(), 6)
        meeting = study_group.meeting_set.active().first()
        reminder = meeting.reminder_set.first()

        url = '/en/studygroup/{0}/message/edit/{1}/'.format(
            signup_data['study_group'], reminder.id)

        email_body = '<p>hi, here is a link <a href="https://www.p2pu.org">p2pu</a></p><script>alert("MUHAHAHA")</script>'
        mail_data = {
            'study_group':
            study_group.id,
            'email_subject':
            'GED® Prep Math study group meeting Thursday 7 May 6:00 PM at Edgewater',
            'email_body':
            email_body,
            'sms_body':
            'The first study group for GED® Prep Math will meet next Thursday, May 7th, from 6:00 pm-7:45 pm at Edgewater on the 2nd floor. Feel free to bring a study buddy!'
        }
        resp = c.post(url, mail_data)
        self.assertRedirects(resp, '/en/studygroup/1/')
        reminder.refresh_from_db()
        self.assertIn('&lt;script&gt;alert("MUHAHAHA")&lt;/script&gt;',
                      reminder.email_body)
        self.assertIn('<a href="https://www.p2pu.org">p2pu</a>',
                      reminder.email_body)
        self.assertTrue(reminder.edited_by_facilitator)

        mail.outbox = []
        send_reminder(reminder)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].to[0], signup_data['email'])
        self.assertEqual(mail.outbox[1].to[0], '*****@*****.**')
        self.assertIn('/optout/confirm/?user='******'&lt;script&gt;alert("MUHAHAHA")&lt;/script&gt;',
                      mail.outbox[0].alternatives[0][0])
        self.assertIn('<a href="https://www.p2pu.org">p2pu</a>',
                      mail.outbox[0].alternatives[0][0])
Exemple #5
0
 def test_send_malicious_reminder_email(self, send_message):
     now = timezone.now()
     sg = StudyGroup.objects.get(pk=1)
     sg.timezone = now.strftime("%Z")
     sg.start_date = now - datetime.timedelta(days=5)
     sg.meeting_time = sg.start_date.time()
     sg.end_date = sg.start_date + datetime.timedelta(weeks=2)
     sg.save()
     sg = StudyGroup.objects.get(pk=1)
     data = self.APPLICATION_DATA
     data['study_group'] = sg
     application = Application(**data)
     accept_application(application)
     application.save()
     mail.outbox = []
     generate_all_meetings(sg)
     meeting = sg.meeting_set.filter(meeting_date__lte=now).last()
     feedback = Feedback.objects.create(
         study_group_meeting=meeting,
         feedback='<a href="https://evil.ink/">this awesome link</a>',
         attendance=3,
         rating='3')
     generate_reminder(sg)
     self.assertEqual(Reminder.objects.all().count(), 1)
     reminder = Reminder.objects.all()[0]
     self.assertEqual(len(mail.outbox), 1)
     send_reminder(reminder)
     self.assertEqual(len(mail.outbox),
                      3)  # should be sent to facilitator & application
     self.assertEqual(mail.outbox[1].to[0], data['email'])
     self.assertFalse(send_message.called)
     self.assertIn(
         '{0}/{1}/rsvp/?user=test%40mail.com&study_group=1&meeting_date={2}&attending=yes&sig='
         .format(
             settings.DOMAIN, get_language(),
             urllib.parse.quote(
                 sg.next_meeting().meeting_datetime().isoformat())),
         mail.outbox[1].alternatives[0][0])
     self.assertIn(
         '{0}/{1}/rsvp/?user=test%40mail.com&study_group=1&meeting_date={2}&attending=no&sig='
         .format(
             settings.DOMAIN, get_language(),
             urllib.parse.quote(
                 sg.next_meeting().meeting_datetime().isoformat())),
         mail.outbox[1].alternatives[0][0])
     self.assertIn(
         '{0}/{1}/optout/confirm/?user='******'&lt;a href="https://evil.ink/"&gt;this awesome link&lt;/a&gt;',
         mail.outbox[1].alternatives[0][0])
Exemple #6
0
 def test_send_learner_reminder_ics(self, send_message):
     now = timezone.now()
     sg = StudyGroup.objects.get(pk=1)
     sg.timezone = now.strftime("%Z")
     sg.start_date = now - datetime.timedelta(days=5)
     sg.meeting_time = sg.start_date.time()
     sg.end_date = sg.start_date + datetime.timedelta(weeks=5)
     sg.attach_ics = True
     sg.save()
     sg = StudyGroup.objects.get(pk=1)
     data = self.APPLICATION_DATA
     data['study_group'] = sg
     application = Application(**data)
     accept_application(application)
     application.save()
     mail.outbox = []
     generate_all_meetings(sg)
     generate_reminder(sg)
     self.assertEqual(Reminder.objects.all().count(), 1)
     reminder = Reminder.objects.all()[0]
     self.assertEqual(len(mail.outbox), 1)
     send_reminder(reminder)
     self.assertEqual(len(mail.outbox),
                      3)  # should be sent to facilitator & application
     self.assertEqual(mail.outbox[1].to[0], data['email'])
     self.assertFalse(send_message.called)
     self.assertIn(
         '{0}/{1}/rsvp/?user=test%40mail.com&study_group=1&meeting_date={2}&attending=yes&sig='
         .format(
             settings.DOMAIN, get_language(),
             urllib.parse.quote(
                 sg.next_meeting().meeting_datetime().isoformat())),
         mail.outbox[1].alternatives[0][0])
     self.assertIn(
         '{0}/{1}/rsvp/?user=test%40mail.com&study_group=1&meeting_date={2}&attending=no&sig='
         .format(
             settings.DOMAIN, get_language(),
             urllib.parse.quote(
                 sg.next_meeting().meeting_datetime().isoformat())),
         mail.outbox[1].alternatives[0][0])
     self.assertIn(
         '{0}/{1}/optout/confirm/?user='******'VEVENT', mail.outbox[1].attachments[0].get_payload())
Exemple #7
0
 def test_send_reminder_sms(self, send_message):
     now = timezone.now()
     sg = StudyGroup.objects.get(pk=1)
     sg.timezone = now.strftime("%Z")
     sg.start_date = now - datetime.timedelta(days=5)
     sg.meeting_time = sg.start_date.time()
     sg.end_date = sg.start_date + datetime.timedelta(weeks=5)
     sg.save()
     sg = StudyGroup.objects.get(pk=1)
     data = self.APPLICATION_DATA
     data['study_group'] = sg
     application = Application(**data)
     application.save()
     mail.outbox = []
     generate_all_meetings(sg)
     generate_reminder(sg)
     self.assertEqual(Reminder.objects.all().count(), 1)
     reminder = Reminder.objects.all()[0]
     send_reminder(reminder)
     self.assertEqual(len(mail.outbox), 2)
     #self.assertEqual(mail.outbox[0].subject, mail_data['email_subject'])
     self.assertFalse(send_message.called)