updated dashboard with providers text
ECOM-2935
This commit is contained in:
@@ -4,9 +4,9 @@ Tests for credit courses on the student dashboard.
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import ddt
|
||||
from mock import patch
|
||||
import pytz
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.utils import override_settings
|
||||
@@ -28,6 +28,7 @@ TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6"
|
||||
"hogwarts": TEST_CREDIT_PROVIDER_SECRET_KEY,
|
||||
})
|
||||
@patch.dict(settings.FEATURES, {"ENABLE_CREDIT_ELIGIBILITY": True})
|
||||
@ddt.ddt
|
||||
class CreditCourseDashboardTest(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests for credit courses on the student dashboard.
|
||||
@@ -106,9 +107,12 @@ class CreditCourseDashboardTest(ModuleStoreTestCase):
|
||||
|
||||
# The user should still have the option to purchase credit,
|
||||
# but there should also be a message urging the user to purchase soon.
|
||||
|
||||
response = self._load_dashboard()
|
||||
|
||||
self.assertContains(response, "credit-eligibility-msg")
|
||||
self.assertContains(response, "purchase-credit-btn")
|
||||
self.assertContains(response, "You have completed this course and are eligible")
|
||||
|
||||
def test_purchased_credit(self):
|
||||
# Simulate that the user has purchased credit, but has not
|
||||
@@ -206,3 +210,35 @@ class CreditCourseDashboardTest(ModuleStoreTestCase):
|
||||
def _set_request_status(self, uuid, status):
|
||||
"""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)
|
||||
|
||||
@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
|
||||
|
||||
# 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.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.programs.utils import get_programs_for_dashboard
|
||||
|
||||
@@ -926,12 +927,13 @@ def _credit_statuses(user, course_enrollments):
|
||||
statuses = {}
|
||||
for eligibility in credit_api.get_eligibilities_for_user(user.username):
|
||||
course_key = CourseKey.from_string(unicode(eligibility["course_key"]))
|
||||
providers_names = get_credit_provider_display_names(course_key)
|
||||
status = {
|
||||
"course_key": unicode(course_key),
|
||||
"eligible": True,
|
||||
"deadline": eligibility["deadline"],
|
||||
"purchased": course_key in credit_enrollments,
|
||||
"provider_name": None,
|
||||
"provider_name": make_providers_strings(providers_names),
|
||||
"provider_status_url": None,
|
||||
"provider_id": None,
|
||||
"request_status": request_status_by_course.get(course_key),
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
|
||||
# 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.")
|
||||
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_btn_class = "purchase-credit-btn"
|
||||
credit_btn_label = _("Get Credit")
|
||||
|
||||
@@ -68,26 +68,8 @@ def send_credit_notifications(username, course_key):
|
||||
# strip enclosing angle brackets from 'logo_image' cache 'Content-ID'
|
||||
logo_image_id = logo_image.get('Content-ID', '')[1:-1]
|
||||
|
||||
providers = get_credit_provider_display_names(course_key)
|
||||
providers_string = None
|
||||
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]
|
||||
|
||||
providers_names = get_credit_provider_display_names(course_key)
|
||||
providers_string = make_providers_strings(providers_names)
|
||||
context = {
|
||||
'full_name': user.get_full_name(),
|
||||
'platform_name': settings.PLATFORM_NAME,
|
||||
@@ -107,7 +89,8 @@ def send_credit_notifications(username, course_key):
|
||||
notification_msg.attach(msg_alternative)
|
||||
# render the credit notification templates
|
||||
subject = _(u'Course Credit Eligibility')
|
||||
if providers:
|
||||
|
||||
if providers_string:
|
||||
subject = _(u'You are eligible for credit from {providers_string}').format(
|
||||
providers_string=providers_string
|
||||
)
|
||||
@@ -259,3 +242,35 @@ def get_credit_provider_display_names(course_key):
|
||||
cache.set(cache_key, provider_names, credit_config.cache_ttl)
|
||||
|
||||
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
|
||||
import pytz
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
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 (
|
||||
InvalidCreditRequirements,
|
||||
InvalidCreditCourse,
|
||||
@@ -1204,3 +1204,21 @@ class CourseApiTests(CreditApiTestBase):
|
||||
self._mock_ecommerce_courses_api(self.course_key, self.COURSE_API_RESPONSE)
|
||||
CreditProvider.objects.all().update(active=False)
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user