Merge pull request #15724 from edx/tasawer/learner-2167/fix-lms-dashboard-errors
Fix LMS dashboard error, if HttpServerError occurs on ecommerce
This commit is contained in:
@@ -13,7 +13,6 @@ file and check it in at the same time as your model changes. To do that,
|
||||
import hashlib
|
||||
import json
|
||||
import logging
|
||||
from slumber.exceptions import HttpClientError
|
||||
import uuid
|
||||
from collections import OrderedDict, defaultdict, namedtuple
|
||||
from datetime import datetime, timedelta
|
||||
@@ -37,11 +36,14 @@ from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_noop
|
||||
from django_countries.fields import CountryField
|
||||
from edx_rest_api_client.exceptions import SlumberBaseException
|
||||
from eventtracking import tracker
|
||||
from model_utils.models import TimeStampedModel
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from pytz import UTC
|
||||
from simple_history.models import HistoricalRecords
|
||||
from slumber.exceptions import HttpClientError, HttpServerError
|
||||
|
||||
import dogstats_wrapper as dog_stats_api
|
||||
import lms.lib.comment_client as cc
|
||||
@@ -49,7 +51,6 @@ import request_cache
|
||||
from certificates.models import GeneratedCertificate
|
||||
from course_modes.models import CourseMode
|
||||
from enrollment.api import _default_course_mode
|
||||
from eventtracking import tracker
|
||||
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager
|
||||
@@ -1624,11 +1625,23 @@ class CourseEnrollment(models.Model):
|
||||
order_number = attribute.value
|
||||
try:
|
||||
order = ecommerce_api_client(self.user).orders(order_number).get()
|
||||
|
||||
except HttpClientError:
|
||||
log.warning(
|
||||
u"Encountered HttpClientError while getting order details from ecommerce. "
|
||||
u"Order={number} and user {user}".format(number=order_number, user=self.user.id))
|
||||
return None
|
||||
|
||||
except HttpServerError:
|
||||
log.warning(
|
||||
u"Encountered HttpServerError while getting order details from ecommerce. "
|
||||
u"Order={number} and user {user}".format(number=order_number, user=self.user.id))
|
||||
return None
|
||||
|
||||
except SlumberBaseException:
|
||||
log.warning(
|
||||
u"Encountered an error while getting order details from ecommerce. "
|
||||
u"Order={number} and user {user}".format(number=order_number, user=self.user.id))
|
||||
return None
|
||||
|
||||
refund_window_start_date = max(
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Tests for enrollment refund capabilities.
|
||||
"""
|
||||
import logging
|
||||
from slumber.exceptions import HttpClientError
|
||||
import unittest
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@@ -15,7 +14,9 @@ from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import Client
|
||||
from django.test.utils import override_settings
|
||||
from edx_rest_api_client.exceptions import SlumberBaseException
|
||||
from mock import patch
|
||||
from slumber.exceptions import HttpClientError, HttpServerError
|
||||
|
||||
# These imports refer to lms djangoapps.
|
||||
# Their testcases are only run under lms.
|
||||
@@ -214,15 +215,16 @@ class RefundableTest(SharedModuleStoreTestCase):
|
||||
resp = self.client.post(reverse('student.views.dashboard', args=[]))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
@ddt.data(HttpServerError, HttpClientError, SlumberBaseException)
|
||||
@override_settings(ECOMMERCE_API_URL=TEST_API_URL)
|
||||
def test_refund_cutoff_date_with_client_error(self):
|
||||
def test_refund_cutoff_date_with_api_error(self, exception):
|
||||
""" Verify that dashboard will not throw internal server error if HttpClientError
|
||||
raised while getting order detail for ecommerce.
|
||||
"""
|
||||
raised while getting order detail for ecommerce.
|
||||
"""
|
||||
# importing this after overriding value of ECOMMERCE_API_URL
|
||||
from commerce.tests.mocks import mock_order_endpoint
|
||||
|
||||
self.client.login(username=self.user.username, password=self.USER_PASSWORD)
|
||||
with mock_order_endpoint(order_number=self.ORDER_NUMBER, exception=HttpClientError):
|
||||
with mock_order_endpoint(order_number=self.ORDER_NUMBER, exception=exception, reset_on_exit=False):
|
||||
response = self.client.post(reverse('student.views.dashboard', args=[]))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
Reference in New Issue
Block a user