Commit bc45f82f by Clinton Blackburn Committed by Clinton Blackburn

Updated program filter for learner dashboard

Learners will now see both active and retired programs on their
dashboards.

ECOM-7625
parent 15ab2b6b
"""Tests covering utilities for integrating with the catalog service.""" """Tests covering utilities for integrating with the catalog service."""
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
import uuid
import copy import copy
import uuid
import mock
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.test import TestCase from django.test import TestCase
import mock from waffle.models import Switch
from openedx.core.djangoapps.catalog.models import CatalogIntegration from openedx.core.djangoapps.catalog.models import CatalogIntegration
from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory, ProgramFactory, ProgramTypeFactory from openedx.core.djangoapps.catalog.tests.factories import CourseRunFactory, ProgramFactory, ProgramTypeFactory
...@@ -19,7 +20,6 @@ from openedx.core.djangoapps.catalog.utils import ( ...@@ -19,7 +20,6 @@ from openedx.core.djangoapps.catalog.utils import (
from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.djangolib.testing.utils import skip_unless_lms
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
UTILS_MODULE = 'openedx.core.djangoapps.catalog.utils' UTILS_MODULE = 'openedx.core.djangoapps.catalog.utils'
User = get_user_model() # pylint: disable=invalid-name User = get_user_model() # pylint: disable=invalid-name
...@@ -37,7 +37,7 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase): ...@@ -37,7 +37,7 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase):
UserFactory(username=self.catalog_integration.service_username) UserFactory(username=self.catalog_integration.service_username)
def assert_contract(self, call_args, program_uuid=None, types=None): # pylint: disable=redefined-builtin def assert_contract(self, call_args, program_uuid=None, types=None, expected_querystring=None):
"""Verify that API data retrieval utility is used correctly.""" """Verify that API data retrieval utility is used correctly."""
args, kwargs = call_args args, kwargs = call_args
...@@ -58,20 +58,24 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase): ...@@ -58,20 +58,24 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase):
self.assertEqual(kwargs['api']._store['base_url'], self.catalog_integration.internal_api_url) # pylint: disable=protected-access self.assertEqual(kwargs['api']._store['base_url'], self.catalog_integration.internal_api_url) # pylint: disable=protected-access
querystring = { if expected_querystring:
'marketable': 1, querystring = expected_querystring
'exclude_utm': 1, else:
} querystring = {
if program_uuid: 'marketable': 1,
querystring['use_full_course_serializer'] = 1 'exclude_utm': 1,
if types: }
querystring['types'] = types_param if program_uuid:
querystring['use_full_course_serializer'] = 1
if types:
querystring['types'] = types_param
self.assertEqual(kwargs['querystring'], querystring) self.assertEqual(kwargs['querystring'], querystring)
return args, kwargs return args, kwargs
def test_get_programs(self, mock_get_edx_api_data): def test_get_programs(self, mock_get_edx_api_data):
programs = [ProgramFactory() for __ in range(3)] programs = ProgramFactory.create_batch(3)
mock_get_edx_api_data.return_value = programs mock_get_edx_api_data.return_value = programs
data = get_programs() data = get_programs()
...@@ -79,6 +83,21 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase): ...@@ -79,6 +83,21 @@ class TestGetPrograms(CatalogIntegrationMixin, TestCase):
self.assert_contract(mock_get_edx_api_data.call_args) self.assert_contract(mock_get_edx_api_data.call_args)
self.assertEqual(data, programs) self.assertEqual(data, programs)
def test_get_programs_with_status_filtering(self, mock_get_edx_api_data):
""" The function should request active and retired programs when the Waffle switch is enabled. """
programs = ProgramFactory.create_batch(3)
mock_get_edx_api_data.return_value = programs
Switch.objects.get_or_create(name='display_retired_programs_on_learner_dashboard', defaults={'active': True})
data = get_programs()
expected_querystring = {
'exclude_utm': 1,
'status': ('active', 'retired',)
}
self.assert_contract(mock_get_edx_api_data.call_args, expected_querystring=expected_querystring)
self.assertEqual(data, programs)
def test_get_one_program(self, mock_get_edx_api_data): def test_get_one_program(self, mock_get_edx_api_data):
program = ProgramFactory() program = ProgramFactory()
mock_get_edx_api_data.return_value = program mock_get_edx_api_data.return_value = program
...@@ -240,7 +259,7 @@ class TestGetCourseRuns(CatalogIntegrationMixin, TestCase): ...@@ -240,7 +259,7 @@ class TestGetCourseRuns(CatalogIntegrationMixin, TestCase):
""" """
Test retrieval of course runs. Test retrieval of course runs.
""" """
catalog_course_runs = [CourseRunFactory() for __ in xrange(10)] catalog_course_runs = CourseRunFactory.create_batch(10)
mock_get_edx_api_data.return_value = catalog_course_runs mock_get_edx_api_data.return_value = catalog_course_runs
data = get_course_runs() data = get_course_runs()
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import copy import copy
import logging import logging
import waffle
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from edx_rest_api_client.client import EdxRestApiClient from edx_rest_api_client.client import EdxRestApiClient
...@@ -54,11 +55,18 @@ def get_programs(uuid=None, types=None): # pylint: disable=redefined-builtin ...@@ -54,11 +55,18 @@ def get_programs(uuid=None, types=None): # pylint: disable=redefined-builtin
) )
querystring = { querystring = {
'marketable': 1,
'exclude_utm': 1, 'exclude_utm': 1,
} }
# TODO ECOM-7650: Remove this after https://github.com/edx/course-discovery/pull/805 is merged and released.
if waffle.switch_is_active('display_retired_programs_on_learner_dashboard'):
querystring['status'] = ('active', 'retired',)
else:
querystring['marketable'] = 1
if uuid: if uuid:
querystring['use_full_course_serializer'] = 1 querystring['use_full_course_serializer'] = 1
if types_param: if types_param:
querystring['types'] = types_param querystring['types'] = types_param
......
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