feat: learner home enterprise dash data (#30939)

* feat: learner home enterprise dash data
This commit is contained in:
Jansen Kantor
2022-09-06 14:29:19 -04:00
committed by GitHub
parent d9073e99b0
commit 2f84f71c03
4 changed files with 22 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
"""
Serializers for the Learner Dashboard
"""
from urllib.parse import urljoin
from django.conf import settings
from django.urls import reverse
@@ -356,8 +357,11 @@ class EmailConfirmationSerializer(serializers.Serializer):
class EnterpriseDashboardSerializer(serializers.Serializer):
"""Serializer for individual enterprise dashboard data"""
label = serializers.CharField()
url = serializers.URLField()
label = serializers.CharField(source='name')
url = serializers.SerializerMethodField()
def get_url(self, instance):
return urljoin(settings.ENTERPRISE_LEARNER_PORTAL_BASE_URL, instance['uuid'])
class LearnerDashboardSerializer(serializers.Serializer):

View File

@@ -840,8 +840,8 @@ class TestEnterpriseDashboardSerializer(TestCase):
@classmethod
def generate_test_data(cls):
return {
"label": f"{uuid4()}",
"url": random_url(),
"uuid": str(uuid4()),
"name": str(uuid4()),
}
def test_structure(self):
@@ -866,8 +866,8 @@ class TestEnterpriseDashboardSerializer(TestCase):
self.assertDictEqual(
output_data,
{
"label": input_data["label"],
"url": input_data["url"],
"label": input_data["name"],
"url": settings.ENTERPRISE_LEARNER_PORTAL_BASE_URL + '/' + input_data["uuid"],
},
)

View File

@@ -6,6 +6,7 @@ from unittest.mock import patch
from uuid import uuid4
import ddt
from django.conf import settings
from django.urls import reverse
from rest_framework.test import APITestCase
@@ -30,6 +31,9 @@ from xmodule.modulestore.tests.django_utils import (
from xmodule.modulestore.tests.factories import CourseFactory
ENTERPRISE_ENABLED = 'ENABLE_ENTERPRISE_INTEGRATION'
class TestGetPlatformSettings(TestCase):
"""Tests for get_platform_settings"""
@@ -216,6 +220,7 @@ class TestDashboardView(SharedModuleStoreTestCase, APITestCase):
super().setUp()
self.log_in()
@patch.dict(settings.FEATURES, ENTERPRISE_ENABLED=False)
def test_response_structure(self):
"""Basic test for correct response structure"""
@@ -241,6 +246,7 @@ class TestDashboardView(SharedModuleStoreTestCase, APITestCase):
assert expected_keys == response_data.keys()
@patch.dict(settings.FEATURES, ENTERPRISE_ENABLED=False)
@patch("lms.djangoapps.learner_home.views.get_user_account_confirmation_info")
def test_email_confirmation(self, mock_user_conf_info):
"""Test that email confirmation info passes through correctly"""
@@ -269,6 +275,7 @@ class TestDashboardView(SharedModuleStoreTestCase, APITestCase):
},
)
@patch.dict(settings.FEATURES, ENTERPRISE_ENABLED=False)
@patch("lms.djangoapps.learner_home.views.cert_info")
def test_get_cert_statuses(self, mock_get_cert_info):
"""Test that cert information gets loaded correctly"""

View File

@@ -26,6 +26,7 @@ from lms.djangoapps.courseware.access_utils import (
)
from lms.djangoapps.learner_home.serializers import LearnerDashboardSerializer
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.features.enterprise_support.api import enterprise_customer_from_session_or_learner_data
def get_platform_settings():
@@ -196,6 +197,9 @@ class InitializeView(RetrieveAPIView): # pylint: disable=unused-argument
user = request.user
email_confirmation = get_user_account_confirmation_info(user)
# Gather info for enterprise dashboard
enterprise_customer = enterprise_customer_from_session_or_learner_data(request)
# Get the org whitelist or the org blacklist for the current site
site_org_whitelist, site_org_blacklist = get_org_black_and_whitelist_for_site()
@@ -228,7 +232,7 @@ class InitializeView(RetrieveAPIView): # pylint: disable=unused-argument
learner_dash_data = {
"emailConfirmation": email_confirmation,
"enterpriseDashboards": None,
"enterpriseDashboard": enterprise_customer,
"platformSettings": get_platform_settings(),
"enrollments": course_enrollments,
"unfulfilledEntitlements": [],