Example #1
0
 def test_update_email_missing_preferences(self):
     profile = ProfileFactory()
     self.url = create_unsubscribe_link(profile.user_object.email)
     response = self.client.get(self.url)
     self.assertContains(response, escape(email_pref_note))
     self.assertContains(response, "Email Options")
     self.assertNotContains(response, "Email:")
Example #2
0
    def send_mail(self, request, to_list):
        mail_form = AdHocEmailForm(request.POST)
        mail_form.fields['to'].choices = to_list
        if not request.user.is_superuser:
            mail_form.fields['sender'].widget = HiddenInput()
        if mail_form.is_valid():
            email_batch = []
            recipient_string = ""
            if request.user.is_superuser:
                sender = mail_form.cleaned_data['sender']
            else:
                sender = request.user.email

            for email in mail_form.cleaned_data['to']:
                if self.email_type != "individual":
                    footer = unsubscribe_text % (
                        Site.objects.get_current().domain,
                        create_unsubscribe_link(email,
                                                "send_%s" % self.email_type))
                    message = mail_form.cleaned_data['html_message'] + footer
                else:
                    message = mail_form.cleaned_data['html_message']

                # if we're in DEBUG mode, let the sender send to only self
                subject = mail_form.cleaned_data['subject']
                target = email
                if DEBUG:
                    subject = "TO: %s - %s" % (email, subject)
                    target = sender
                email_batch += [{
                    'sender': DEFAULT_FROM_EMAIL,
                    'recipients': [target],
                    'subject': subject,
                    'html_message': message,
                    'headers': {
                        'Reply-to': sender
                    },
                }]
                if len(recipient_string) > 0:
                    recipient_string = "%s, %s" % (recipient_string, email)
                else:
                    recipient_string = email

            mail.send_many(email_batch)
            user_message = UserMessage.objects.get_or_create(
                view=self.__class__.__name__,
                code="SEND_SUCCESS",
                defaults={
                    'summary': "Email Sent to Bidders",
                    'description': send_email_success_msg
                })
            messages.success(request,
                             user_message[0].description + recipient_string)
        return mail_form
Example #3
0
 def test_update_email_post_valid_form_w_bad_token(self):
     self.url = create_unsubscribe_link(
         self.profile.user_object.email
         ) + "?email_disable=send_schedule_change_notifications"
     response = self.client.post(self.url, follow=True, data={
         'token': "bad, bad token",
         'send_daily_schedule': True,
         'send_bid_notifications': False,
         'send_role_notifications': False,
         'send_schedule_change_notifications': True})
     self.assertContains(response, send_link_message)
Example #4
0
 def test_update_email_good_token(self):
     self.url = create_unsubscribe_link(
         self.profile.user_object.email
         ) + "?email_disable=send_schedule_change_notifications"
     response = self.client.get(self.url)
     self.assertContains(response, escape(email_pref_note))
     self.assertContains(response, "Email Options")
     self.assertNotContains(response, "Email:")
     self.assertContains(
         response,
         '<input type="checkbox" ' +
         'name="send_schedule_change_notifications"' +
         ' id="id_send_schedule_change_notifications" />',
         html=True)
     self.assertContains(
         response, "shadow-highlight")
Example #5
0
 def test_update_email_post_valid_form_w_no_pref(self):
     pref = ProfilePreferences.objects.get(profile=self.profile)
     pref.delete()
     self.url = create_unsubscribe_link(
         self.profile.user_object.email
         ) + "?email_disable=send_schedule_change_notifications"
     response = self.client.post(self.url, follow=True, data={
         'token': TimestampSigner().sign(self.profile.user_object.email),
         'send_daily_schedule': True,
         'send_bid_notifications': False,
         'send_role_notifications': False,
         'send_schedule_change_notifications': True})
     site = Site.objects.get_current()
     self.assertRedirects(response, "http://%s" % site.domain)
     assert_alert_exists(
         response, 'success', 'Success', default_update_profile_msg)
Example #6
0
 def test_update_email_post_valid_user_email(self):
     self.url = create_unsubscribe_link(
         self.profile.user_object.email
         )
     response = self.client.post(
         self.url,
         data={'email': self.profile.user_object.email},
         follow=True)
     assert_alert_exists(
         response, 'success', 'Success', link_sent_msg)
     queued_email = Email.objects.filter(
         status=2,
         to=self.profile.user_object.email,
         subject="Unsubscribe from GBE Mail",
         from_email=settings.DEFAULT_FROM_EMAIL,
         )
     self.assertEqual(queued_email.count(), 1)
Example #7
0
 def test_update_email_post_valid_form_logged_in(self):
     login_as(self.profile.user_object, self)
     self.url = create_unsubscribe_link(
         self.profile.user_object.email
         ) + "?email_disable=send_schedule_change_notifications"
     response = self.client.post(self.url, follow=True, data={
         'token': TimestampSigner().sign(self.profile.user_object.email),
         'send_daily_schedule': True,
         'send_bid_notifications': False,
         'send_role_notifications': False,
         'send_schedule_change_notifications': True})
     self.assertRedirects(response, reverse('home', urlconf='gbe.urls'))
     preferences = ProfilePreferences.objects.get(profile=self.profile)
     self.assertTrue(preferences.send_daily_schedule)
     self.assertFalse(preferences.send_bid_notifications)
     assert_alert_exists(
         response, 'success', 'Success', default_update_profile_msg)
Example #8
0
 def test_update_email_bad_user(self):
     self.url = create_unsubscribe_link("*****@*****.**")
     response = self.client.get(self.url)
     self.assertContains(response, bad_token_msg)
     self.assertContains(response, send_link_message)
Example #9
0
 def test_update_email_post_invalid_form_wout_token(self):
     self.url = create_unsubscribe_link(
         self.profile.user_object.email,
         disable="send_schedule_change_notifications")
     response = self.client.post(self.url, follow=True, data={},)
     self.assertContains(response, send_link_message)