Esempio n. 1
0
 def test_notification_themed_site(self, mock_is_request_in_themed_site):  # pylint: disable=unused-argument
     """
     Ensure the notification function raises an Exception if used in the
     context of themed site.
     """
     with self.assertRaises(NotImplementedError):
         send_refund_notification(self.course_enrollment, [1, 2, 3])
 def test_notification_themed_site(self, mock_is_request_in_themed_site):  # pylint: disable=unused-argument
     """
     Ensure the notification function raises an Exception if used in the
     context of themed site.
     """
     with self.assertRaises(NotImplementedError):
         send_refund_notification(self.course_enrollment, [1, 2, 3])
Esempio n. 3
0
    def test_notification_content(self, mock_email_class):
        """
        Ensure the email sender, recipient, subject, content type, and content
        are all correct.
        """
        # mock_email_class is the email message class/constructor.
        # mock_message is the instance returned by the constructor.
        # we need to make assertions regarding both.
        mock_message = mock.MagicMock()
        mock_email_class.return_value = mock_message

        refund_ids = [1, 2, 3]
        send_refund_notification(self.course_enrollment, refund_ids)

        # check headers and text content
        self.assertEqual(
            mock_email_class.call_args[0],
            ("[Refund] User-Requested Refund", mock.ANY, self.student.email, ['*****@*****.**']),
        )
        text_body = mock_email_class.call_args[0][1]
        # check for a URL for each refund
        for exp in [r'{0}/dashboard/refunds/{1}/'.format(TEST_PUBLIC_URL_ROOT, refund_id)
                    for refund_id in refund_ids]:
            self.assertRegexpMatches(text_body, exp)

        # check HTML content
        self.assertEqual(mock_message.attach_alternative.call_args[0], (mock.ANY, "text/html"))
        html_body = mock_message.attach_alternative.call_args[0][0]
        # check for a link to each refund
        for exp in [r'a href="{0}/dashboard/refunds/{1}/"'.format(TEST_PUBLIC_URL_ROOT, refund_id)
                    for refund_id in refund_ids]:
            self.assertRegexpMatches(html_body, exp)

        # make sure we actually SEND the message too.
        self.assertTrue(mock_message.send.called)
Esempio n. 4
0
    def test_notification_content(self, mock_email_class):
        """
        Ensure the email sender, recipient, subject, content type, and content
        are all correct.
        """
        # mock_email_class is the email message class/constructor.
        # mock_message is the instance returned by the constructor.
        # we need to make assertions regarding both.
        mock_message = mock.MagicMock()
        mock_email_class.return_value = mock_message

        refund_ids = [1, 2, 3]
        send_refund_notification(self.course_enrollment, refund_ids)

        # check headers and text content
        self.assertEqual(
            mock_email_class.call_args[0],
            ("[Refund] User-Requested Refund", mock.ANY, self.student.email, ['*****@*****.**']),
        )
        text_body = mock_email_class.call_args[0][1]
        # check for a URL for each refund
        for exp in [r'{0}/dashboard/refunds/{1}/'.format(TEST_BASE_URL, refund_id) for refund_id in refund_ids]:
            self.assertRegexpMatches(text_body, exp)

        # check HTML content
        self.assertEqual(mock_message.attach_alternative.call_args[0], (mock.ANY, "text/html"))
        html_body = mock_message.attach_alternative.call_args[0][0]
        # check for a link to each refund
        for exp in [r'a href="{0}/dashboard/refunds/{1}/"'.format(TEST_BASE_URL, refund_id)
                    for refund_id in refund_ids]:
            self.assertRegexpMatches(html_body, exp)

        # make sure we actually SEND the message too.
        self.assertTrue(mock_message.send.called)
Esempio n. 5
0
    def test_send_refund_notification(self):
        """ Verify the support team is notified of the refund request. """

        with mock.patch('commerce.signals.create_zendesk_ticket') as mock_zendesk:
            refund_ids = [1, 2, 3]
            send_refund_notification(self.course_enrollment, refund_ids)
            body = generate_refund_notification_body(self.student, refund_ids)
            mock_zendesk.assert_called_with(self.student.profile.name, self.student.email,
                                            "[Refund] User-Requested Refund", body, ['auto_refund'])
Esempio n. 6
0
    def test_send_refund_notification(self, student_email, mock_zendesk):
        """ Verify the support team is notified of the refund request. """
        refund_ids = [1, 2, 3]

        # pass a student with unicode and ascii email to ensure that
        # generate_refund_notification_body can handle formatting a unicode
        # message
        self.student.email = student_email
        send_refund_notification(self.course_enrollment, refund_ids)
        body = generate_refund_notification_body(self.student, refund_ids)
        mock_zendesk.assert_called_with(self.student.profile.name,
                                        self.student.email,
                                        "[Refund] User-Requested Refund", body,
                                        ['auto_refund'])
Esempio n. 7
0
    def test_send_refund_notification(self, student_email, mock_zendesk):
        """ Verify the support team is notified of the refund request. """
        refund_ids = [1, 2, 3]

        # pass a student with unicode and ascii email to ensure that
        # generate_refund_notification_body can handle formatting a unicode
        # message
        self.student.email = student_email
        send_refund_notification(self.course_enrollment, refund_ids)
        body = generate_refund_notification_body(self.student, refund_ids)
        mock_zendesk.assert_called_with(
            self.student.profile.name,
            self.student.email,
            "[Refund] User-Requested Refund",
            body,
            ['auto_refund']
        )