Commit 3e3f5361 by tasawernawaz

Merge pull request #11870 from edx/tasawer/story/ecom-2935-update-dashboard-for-multi-provider

Updated dashboard with providers text
parents 1dff9d45 05898df1
...@@ -4,9 +4,9 @@ Tests for credit courses on the student dashboard. ...@@ -4,9 +4,9 @@ Tests for credit courses on the student dashboard.
import unittest import unittest
import datetime import datetime
import ddt
from mock import patch from mock import patch
import pytz import pytz
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
...@@ -28,6 +28,7 @@ TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6" ...@@ -28,6 +28,7 @@ TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6"
"hogwarts": TEST_CREDIT_PROVIDER_SECRET_KEY, "hogwarts": TEST_CREDIT_PROVIDER_SECRET_KEY,
}) })
@patch.dict(settings.FEATURES, {"ENABLE_CREDIT_ELIGIBILITY": True}) @patch.dict(settings.FEATURES, {"ENABLE_CREDIT_ELIGIBILITY": True})
@ddt.ddt
class CreditCourseDashboardTest(ModuleStoreTestCase): class CreditCourseDashboardTest(ModuleStoreTestCase):
""" """
Tests for credit courses on the student dashboard. Tests for credit courses on the student dashboard.
...@@ -106,9 +107,12 @@ class CreditCourseDashboardTest(ModuleStoreTestCase): ...@@ -106,9 +107,12 @@ class CreditCourseDashboardTest(ModuleStoreTestCase):
# The user should still have the option to purchase credit, # The user should still have the option to purchase credit,
# but there should also be a message urging the user to purchase soon. # but there should also be a message urging the user to purchase soon.
response = self._load_dashboard() response = self._load_dashboard()
self.assertContains(response, "credit-eligibility-msg") self.assertContains(response, "credit-eligibility-msg")
self.assertContains(response, "purchase-credit-btn") self.assertContains(response, "purchase-credit-btn")
self.assertContains(response, "You have completed this course and are eligible")
def test_purchased_credit(self): def test_purchased_credit(self):
# Simulate that the user has purchased credit, but has not # Simulate that the user has purchased credit, but has not
...@@ -206,3 +210,35 @@ class CreditCourseDashboardTest(ModuleStoreTestCase): ...@@ -206,3 +210,35 @@ class CreditCourseDashboardTest(ModuleStoreTestCase):
def _set_request_status(self, uuid, status): def _set_request_status(self, uuid, status):
"""Set the status of a request for credit, simulating the notification from the provider. """ """Set the status of a request for credit, simulating the notification from the provider. """
credit_api.update_credit_request_status(uuid, self.PROVIDER_ID, status) credit_api.update_credit_request_status(uuid, self.PROVIDER_ID, status)
@ddt.data(
(
[u'Arizona State University'],
'You are now eligible for credit from Arizona State University'),
(
[u'Arizona State University', u'Hogwarts School of Witchcraft'],
'You are now eligible for credit from Arizona State University and Hogwarts School of Witchcraft'
),
(
[u'Arizona State University', u'Hogwarts School of Witchcraft and Wizardry', u'Charter Oak'],
'You are now eligible for credit from Arizona State University, Hogwarts School'
' of Witchcraft and Wizardry, and Charter Oak'
),
([], 'You have completed this course and are eligible'),
(None, 'You have completed this course and are eligible')
)
@ddt.unpack
def test_eligible_for_credit_with_providers_names(self, providers_list, credit_string):
"""Verify the message on dashboard with different number of providers."""
# Simulate that the user has completed the only requirement in the course
# so the user is eligible for credit.
self._make_eligible()
# The user should have the option to purchase credit
with patch('student.views.get_credit_provider_display_names') as mock_method:
mock_method.return_value = providers_list
response = self._load_dashboard()
self.assertContains(response, "credit-eligibility-msg")
self.assertContains(response, "purchase-credit-btn")
self.assertContains(response, credit_string)
...@@ -124,6 +124,7 @@ from notification_prefs.views import enable_notifications ...@@ -124,6 +124,7 @@ from notification_prefs.views import enable_notifications
# Note that this lives in openedx, so this dependency should be refactored. # Note that this lives in openedx, so this dependency should be refactored.
from openedx.core.djangoapps.credentials.utils import get_user_program_credentials from openedx.core.djangoapps.credentials.utils import get_user_program_credentials
from openedx.core.djangoapps.credit.email_utils import get_credit_provider_display_names, make_providers_strings
from openedx.core.djangoapps.user_api.preferences import api as preferences_api from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.djangoapps.programs.utils import get_programs_for_dashboard from openedx.core.djangoapps.programs.utils import get_programs_for_dashboard
...@@ -926,12 +927,13 @@ def _credit_statuses(user, course_enrollments): ...@@ -926,12 +927,13 @@ def _credit_statuses(user, course_enrollments):
statuses = {} statuses = {}
for eligibility in credit_api.get_eligibilities_for_user(user.username): for eligibility in credit_api.get_eligibilities_for_user(user.username):
course_key = CourseKey.from_string(unicode(eligibility["course_key"])) course_key = CourseKey.from_string(unicode(eligibility["course_key"]))
providers_names = get_credit_provider_display_names(course_key)
status = { status = {
"course_key": unicode(course_key), "course_key": unicode(course_key),
"eligible": True, "eligible": True,
"deadline": eligibility["deadline"], "deadline": eligibility["deadline"],
"purchased": course_key in credit_enrollments, "purchased": course_key in credit_enrollments,
"provider_name": None, "provider_name": make_providers_strings(providers_names),
"provider_status_url": None, "provider_status_url": None,
"provider_id": None, "provider_id": None,
"request_status": request_status_by_course.get(course_key), "request_status": request_status_by_course.get(course_key),
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
# Translators: provider_name is the name of a credit provider or university (e.g. State University) # Translators: provider_name is the name of a credit provider or university (e.g. State University)
credit_msg = _("You have completed this course and are eligible to purchase course credit. Select <strong>Get Credit</strong> to get started.") credit_msg = _("You have completed this course and are eligible to purchase course credit. Select <strong>Get Credit</strong> to get started.")
if credit_status['provider_name']:
credit_msg = _("You are now eligible for credit from {provider}. Congratulations!").format(provider=credit_status['provider_name'])
credit_msg_class = "credit-eligibility-msg" credit_msg_class = "credit-eligibility-msg"
credit_btn_class = "purchase-credit-btn" credit_btn_class = "purchase-credit-btn"
credit_btn_label = _("Get Credit") credit_btn_label = _("Get Credit")
......
...@@ -68,26 +68,8 @@ def send_credit_notifications(username, course_key): ...@@ -68,26 +68,8 @@ def send_credit_notifications(username, course_key):
# strip enclosing angle brackets from 'logo_image' cache 'Content-ID' # strip enclosing angle brackets from 'logo_image' cache 'Content-ID'
logo_image_id = logo_image.get('Content-ID', '')[1:-1] logo_image_id = logo_image.get('Content-ID', '')[1:-1]
providers = get_credit_provider_display_names(course_key) providers_names = get_credit_provider_display_names(course_key)
providers_string = None providers_string = make_providers_strings(providers_names)
if providers:
if len(providers) > 1:
if len(providers) > 2:
# Translators: The join of three or more university names. The first of these formatting strings
# represents a comma-separated list of names (e.g., MIT, Harvard, Dartmouth).
providers_string = _("{first_providers}, and {last_provider}").format(
first_providers=u", ".join(providers[:-1]),
last_provider=providers[-1]
)
else:
# Translators: The join of two university names (e.g., Harvard and MIT).
providers_string = _("{first_provider} and {second_provider}").format(
first_provider=providers[0],
second_provider=providers[1]
)
else:
providers_string = providers[0]
context = { context = {
'full_name': user.get_full_name(), 'full_name': user.get_full_name(),
'platform_name': settings.PLATFORM_NAME, 'platform_name': settings.PLATFORM_NAME,
...@@ -107,7 +89,8 @@ def send_credit_notifications(username, course_key): ...@@ -107,7 +89,8 @@ def send_credit_notifications(username, course_key):
notification_msg.attach(msg_alternative) notification_msg.attach(msg_alternative)
# render the credit notification templates # render the credit notification templates
subject = _(u'Course Credit Eligibility') subject = _(u'Course Credit Eligibility')
if providers:
if providers_string:
subject = _(u'You are eligible for credit from {providers_string}').format( subject = _(u'You are eligible for credit from {providers_string}').format(
providers_string=providers_string providers_string=providers_string
) )
...@@ -259,3 +242,35 @@ def get_credit_provider_display_names(course_key): ...@@ -259,3 +242,35 @@ def get_credit_provider_display_names(course_key):
cache.set(cache_key, provider_names, credit_config.cache_ttl) cache.set(cache_key, provider_names, credit_config.cache_ttl)
return provider_names return provider_names
def make_providers_strings(providers):
"""Get the list of course providers and make them comma seperated string.
Arguments:
providers : List containing the providers names
Returns:
strings containing providers names in readable way .
"""
if not providers:
return None
if len(providers) == 1:
providers_string = providers[0]
elif len(providers) == 2:
# Translators: The join of two university names (e.g., Harvard and MIT).
providers_string = _("{first_provider} and {second_provider}").format(
first_provider=providers[0],
second_provider=providers[1]
)
else:
# Translators: The join of three or more university names. The first of these formatting strings
# represents a comma-separated list of names (e.g., MIT, Harvard, Dartmouth).
providers_string = _("{first_providers}, and {last_provider}").format(
first_providers=u", ".join(providers[:-1]),
last_provider=providers[-1]
)
return providers_string
...@@ -18,7 +18,7 @@ import mock ...@@ -18,7 +18,7 @@ import mock
import pytz import pytz
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.credit import api from openedx.core.djangoapps.credit import api
from openedx.core.djangoapps.credit.email_utils import get_credit_provider_display_names from openedx.core.djangoapps.credit.email_utils import get_credit_provider_display_names, make_providers_strings
from openedx.core.djangoapps.credit.exceptions import ( from openedx.core.djangoapps.credit.exceptions import (
InvalidCreditRequirements, InvalidCreditRequirements,
InvalidCreditCourse, InvalidCreditCourse,
...@@ -1204,3 +1204,21 @@ class CourseApiTests(CreditApiTestBase): ...@@ -1204,3 +1204,21 @@ class CourseApiTests(CreditApiTestBase):
self._mock_ecommerce_courses_api(self.course_key, self.COURSE_API_RESPONSE) self._mock_ecommerce_courses_api(self.course_key, self.COURSE_API_RESPONSE)
CreditProvider.objects.all().update(active=False) CreditProvider.objects.all().update(active=False)
self.assertEqual(get_credit_provider_display_names(self.course_key), []) self.assertEqual(get_credit_provider_display_names(self.course_key), [])
@ddt.data(None, ['asu'], ['asu', 'co'], ['asu', 'co', 'mit'])
def test_make_providers_strings(self, providers):
""" Verify that method returns given provider list as comma separated string. """
provider_string = make_providers_strings(providers)
if not providers:
self.assertEqual(provider_string, None)
elif len(providers) == 1:
self.assertEqual(provider_string, providers[0])
elif len(providers) == 2:
self.assertEqual(provider_string, 'asu and co')
else:
self.assertEqual(provider_string, 'asu, co, and mit')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment