Exemple #1
0
def send_course_purchase_email(sender, order=None, **kwargs):  # pylint: disable=unused-argument
    """Send course purchase notification email when a course is purchased."""
    if waffle.switch_is_active('ENABLE_NOTIFICATIONS'):
        # We do not currently support email sending for orders with more than one item.
        if len(order.lines.all()) == ORDER_LINE_COUNT:
            product = order.lines.first().product
            provider_id = getattr(product.attr, 'credit_provider', None)
            if not provider_id:
                logger.error(
                    'Failed to send credit receipt notification. Credit seat product [%s] has not provider.',
                    product.id)
                return
            elif product.get_product_class().name == 'Seat':
                provider_data = get_provider_data(provider_id)
                if provider_data:
                    send_notification(
                        order.user, 'CREDIT_RECEIPT', {
                            'course_title':
                            product.title,
                            'receipt_page_url':
                            get_lms_url(
                                '/commerce/checkout/receipt/?orderNum={}'.
                                format(order.number)),
                            'credit_hours':
                            product.attr.credit_hours,
                            'credit_provider':
                            provider_data['display_name'],
                        })

        else:
            logger.info(
                'Currently support receipt emails for order with one item.')
Exemple #2
0
def send_course_purchase_email(sender, order=None, **kwargs):  # pylint: disable=unused-argument
    """Send course purchase notification email when a course is purchased."""
    if waffle.switch_is_active('ENABLE_NOTIFICATIONS'):
        # We do not currently support email sending for orders with more than one item.
        if len(order.lines.all()) == ORDER_LINE_COUNT:
            product = order.lines.first().product
            provider_id = getattr(product.attr, 'credit_provider', None)
            if not provider_id:
                logger.error(
                    'Failed to send credit receipt notification. Credit seat product [%s] has not provider.', product.id
                )
                return
            elif product.get_product_class().name == 'Seat':
                provider_data = get_provider_data(provider_id)
                if provider_data:
                    send_notification(
                        order.user,
                        'CREDIT_RECEIPT',
                        {
                            'course_title': product.title,
                            'receipt_page_url': get_lms_url(
                                '/commerce/checkout/receipt/?basket_id={}'.format(order.basket.id)
                            ),
                            'credit_hours': product.attr.credit_hours,
                            'credit_provider': provider_data['display_name'],
                        }
                    )

        else:
            logger.info('Currently support receipt emails for order with one item.')
Exemple #3
0
 def test_get_provider_data_unavailable_request(self):
     """
     Check if None return on the bad request
     """
     httpretty.register_uri(httpretty.GET,
                            get_lms_url('api/credit/v1/providers/ABC'),
                            status=400)
     provider_data = get_provider_data('ABC')
     self.assertEqual(provider_data, None)
Exemple #4
0
 def test_get_provider_data_unavailable_request(self):
     """
     Check if None return on the bad request
     """
     httpretty.register_uri(
         httpretty.GET, get_lms_url('api/credit/v1/providers/ABC'),
         status=400
     )
     provider_data = get_provider_data('ABC')
     self.assertEqual(provider_data, None)
Exemple #5
0
 def test_get_provider_data(self):
     """
     Check if correct data returns on the full filled request.
     """
     httpretty.register_uri(
         httpretty.GET, get_lms_url('api/credit/v1/providers/ASU'),
         body='{"display_name": "Arizona State University"}',
         content_type="application/json"
     )
     provider_data = get_provider_data('ASU')
     self.assertDictEqual(provider_data, {"display_name": "Arizona State University"})
Exemple #6
0
 def test_get_provider_data(self):
     """
     Check if correct data returns on the full filled request.
     """
     httpretty.register_uri(
         httpretty.GET, get_lms_url('api/credit/v1/providers/ASU'),
         body='{"display_name": "Arizona State University"}',
         content_type="application/json"
     )
     provider_data = get_provider_data('ASU')
     self.assertDictEqual(provider_data, {"display_name": "Arizona State University"})
Exemple #7
0
def send_course_purchase_email(sender, order=None, **kwargs):  # pylint: disable=unused-argument
    """Send course purchase notification email when a course is purchased."""
    if waffle.switch_is_active('ENABLE_NOTIFICATIONS'):
        # We do not currently support email sending for orders with more than one item.
        if len(order.lines.all()) == ORDER_LINE_COUNT:
            product = order.lines.first().product
            provider_id = getattr(product.attr, 'credit_provider', None)
            if not provider_id:
                stripped_title = product.title.replace("Seat in ", "", 1)
                stripped_title = stripped_title.replace(
                    "with professional certificate", "")
                stripped_title = stripped_title.replace(
                    "with verified certificate", "")
                send_notification(
                    order.user, 'CREDIT_RECEIPT', {
                        'course_title':
                        stripped_title,
                        'receipt_page_url':
                        get_lms_url('{}?orderNum={}'.format(
                            settings.RECEIPT_PAGE_PATH, order.number)),
                        'credit_hours':
                        str(order.total_excl_tax),
                        'credit_provider':
                        'Credit provider',
                    },
                    threadlocals.get_current_request().site)
                logger.error(
                    'Failed to send credit receipt notification. Credit seat product [%s] has no provider.',
                    product.id)
                return

            elif product.get_product_class().name == 'Seat':
                provider_data = get_provider_data(provider_id)
                if provider_data:
                    send_notification(
                        order.user, 'CREDIT_RECEIPT', {
                            'course_title':
                            product.title,
                            'receipt_page_url':
                            get_lms_url('{}?orderNum={}'.format(
                                settings.RECEIPT_PAGE_PATH, order.number)),
                            'credit_hours':
                            product.attr.credit_hours,
                            'credit_provider':
                            provider_data['display_name'],
                        },
                        threadlocals.get_current_request().site)

        else:
            logger.info(
                'Currently support receipt emails for order with one item.')
Exemple #8
0
 def test_exceptions(self, exception):
     """ Verify the function returns None when a request exception is raised. """
     with mock.patch.object(requests, 'get', mock.Mock(side_effect=exception)):
         self.assertIsNone(get_provider_data('ABC'))
Exemple #9
0
 def test_exceptions(self, exception):
     """ Verify the function returns None when a request exception is raised. """
     with mock.patch.object(requests, 'get', mock.Mock(side_effect=exception)):
         self.assertIsNone(get_provider_data('ABC'))