ENT-2735 | Added more logging for e-commerce calculate endpoint.

This commit is contained in:
hasnain.naveed
2020-04-16 13:46:40 +05:00
parent e25723b2de
commit dcace9cb4d
3 changed files with 23 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)