From dcace9cb4d9510182b07ebab7be5e3a74d8d48d1 Mon Sep 17 00:00:00 2001 From: "hasnain.naveed" Date: Thu, 16 Apr 2020 13:46:40 +0500 Subject: [PATCH] ENT-2735 | Added more logging for e-commerce calculate endpoint. --- common/djangoapps/course_modes/helpers.py | 19 +++++++++++++++++-- .../course_modes/tests/test_views.py | 2 +- common/djangoapps/course_modes/views.py | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/course_modes/helpers.py b/common/djangoapps/course_modes/helpers.py index 942b4a22b4..7bca76cd21 100644 --- a/common/djangoapps/course_modes/helpers.py +++ b/common/djangoapps/course_modes/helpers.py @@ -1,6 +1,7 @@ """ Helper methods for CourseModes. """ +import logging import six from django.utils.translation import ugettext_lazy as _ @@ -16,6 +17,8 @@ DISPLAY_HONOR = "honor" DISPLAY_AUDIT = "audit" DISPLAY_PROFESSIONAL = "professional" +LOGGER = logging.getLogger(__name__) + def enrollment_mode_display(mode, verification_status, course_id): """ Select appropriate display strings and CSS classes. @@ -99,6 +102,18 @@ def get_course_final_price(user, sku, course_price): sku=[sku], username=user.username, ) - except (SlumberBaseException, ConnectionError, Timeout) as exc: # pylint: disable=unused-variable - pass + except (SlumberBaseException, ConnectionError, Timeout) as exc: + LOGGER.info( + '[e-commerce calculate endpoint] Exception raise for sku [%s] - user [%s] and exception: %s', + sku, + user.username, + str(exc) + ) + + LOGGER.info( + '[e-commerce calculate endpoint] The discounted price for sku [%s] and user [%s] is [%s]', + sku, + user.username, + price_details.get('total_incl_tax') + ) return price_details.get('total_incl_tax', course_price) diff --git a/common/djangoapps/course_modes/tests/test_views.py b/common/djangoapps/course_modes/tests/test_views.py index 8a4eac0506..366c138d02 100644 --- a/common/djangoapps/course_modes/tests/test_views.py +++ b/common/djangoapps/course_modes/tests/test_views.py @@ -222,7 +222,7 @@ class CourseModeViewTest(CatalogIntegrationMixin, UrlResetMixin, ModuleStoreTest user=self.user ) - mock_enterprise_customer_for_request.return_value = is_enterprise_enabled + mock_enterprise_customer_for_request.return_value = {'name': 'dummy'} if is_enterprise_enabled else {} mock_get_course_final_price.return_value = discounted_price url = reverse('course_modes_choose', args=[self.course.id]) response = self.client.get(url) diff --git a/common/djangoapps/course_modes/views.py b/common/djangoapps/course_modes/views.py index 2015fdeca4..4cb6d52c06 100644 --- a/common/djangoapps/course_modes/views.py +++ b/common/djangoapps/course_modes/views.py @@ -206,6 +206,11 @@ class ChooseModeView(View): price_before_discount = verified_mode.min_price course_price = price_before_discount enterprise_customer = enterprise_customer_for_request(request) + LOG.info( + '[e-commerce calculate API] Going to hit the API for user [%s] linked to [%s] enterprise', + request.user.username, + enterprise_customer.get('name') if isinstance(enterprise_customer, dict) else None # Test Purpose + ) if enterprise_customer and verified_mode.sku: course_price = get_course_final_price(request.user, verified_mode.sku, price_before_discount)