Retrieve marketable MicroMasters from the catalog service
Catalog-based MicroMasters need to be displayed in the LMS. However, the LMS currently retrieves all program data from the soon-to-be-retired programs service. Consuming program data exclusively from the catalog service is out of the question right now; it's too complex to confidently pull off in a week. This is a functional middle ground introduced by ECOM-5460. Cleaning up this debt is tracked by ECOM-4418.
This commit is contained in:
@@ -11,6 +11,7 @@ class StubCatalogServiceHandler(StubHttpRequestHandler): # pylint: disable=miss
|
||||
|
||||
def do_GET(self): # pylint: disable=invalid-name, missing-docstring
|
||||
pattern_handlers = {
|
||||
r'/api/v1/programs/$': self.get_programs,
|
||||
r'/api/v1/course_runs/(?P<course_id>[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)/$': self.get_course_run,
|
||||
}
|
||||
|
||||
@@ -31,9 +32,16 @@ class StubCatalogServiceHandler(StubHttpRequestHandler): # pylint: disable=miss
|
||||
return True
|
||||
return None
|
||||
|
||||
def get_programs(self):
|
||||
"""
|
||||
Stubs the catalog's programs endpoint.
|
||||
"""
|
||||
programs = self.server.config.get('catalog.programs', [])
|
||||
self.send_json_response(programs)
|
||||
|
||||
def get_course_run(self, course_id):
|
||||
"""
|
||||
Stubs a catalog course run endpoint.
|
||||
Stubs the catalog's course run endpoint.
|
||||
"""
|
||||
course_run = self.server.config.get('course_run.{}'.format(course_id), [])
|
||||
self.send_json_response(course_run)
|
||||
|
||||
@@ -13,6 +13,15 @@ class CatalogFixture(object):
|
||||
"""
|
||||
Interface to set up mock responses from the Catalog stub server.
|
||||
"""
|
||||
def install_programs(self, programs):
|
||||
"""Set response data for the catalog's course run API."""
|
||||
key = 'catalog.programs'
|
||||
|
||||
requests.put(
|
||||
'{}/set_config'.format(CATALOG_STUB_URL),
|
||||
data={key: json.dumps(programs)},
|
||||
)
|
||||
|
||||
def install_course_run(self, course_run):
|
||||
"""Set response data for the catalog's course run API."""
|
||||
key = 'catalog.{}'.format(course_run['key'])
|
||||
|
||||
@@ -17,8 +17,8 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogConfigMixin, UniqueCourseTest)
|
||||
super(ProgramPageBase, self).setUp()
|
||||
|
||||
self.set_programs_api_configuration(is_enabled=True)
|
||||
self.set_catalog_configuration(is_enabled=True)
|
||||
|
||||
self.programs = [catalog_factories.Program() for __ in range(3)]
|
||||
self.course_run = catalog_factories.CourseRun(key=self.course_id)
|
||||
self.stub_catalog_api()
|
||||
|
||||
@@ -51,7 +51,9 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogConfigMixin, UniqueCourseTest)
|
||||
ProgramsFixture().install_programs(programs, is_list=is_list)
|
||||
|
||||
def stub_catalog_api(self):
|
||||
"""Stub out the catalog API's course run endpoint."""
|
||||
"""Stub out the catalog API's program and course run endpoints."""
|
||||
self.set_catalog_configuration(is_enabled=True)
|
||||
CatalogFixture().install_programs(self.programs)
|
||||
CatalogFixture().install_course_run(self.course_run)
|
||||
|
||||
def auth(self, enroll=True):
|
||||
|
||||
@@ -6,6 +6,7 @@ from flaky import flaky
|
||||
from opaque_keys.edx.locator import LibraryLocator
|
||||
from uuid import uuid4
|
||||
|
||||
from common.test.acceptance.fixtures.catalog import CatalogFixture, CatalogConfigMixin
|
||||
from common.test.acceptance.fixtures.programs import ProgramsFixture, ProgramsConfigMixin
|
||||
from common.test.acceptance.pages.studio.auto_auth import AutoAuthPage
|
||||
from common.test.acceptance.pages.studio.library import LibraryEditPage
|
||||
@@ -68,18 +69,30 @@ class CreateLibraryTest(WebAppTest):
|
||||
self.assertTrue(self.dashboard_page.has_library(name=name, org=org, number=number))
|
||||
|
||||
|
||||
class DashboardProgramsTabTest(ProgramsConfigMixin, WebAppTest):
|
||||
class DashboardProgramsTabTest(ProgramsConfigMixin, CatalogConfigMixin, WebAppTest):
|
||||
"""
|
||||
Test the programs tab on the studio home page.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(DashboardProgramsTabTest, self).setUp()
|
||||
ProgramsFixture().install_programs([])
|
||||
self.stub_programs_api()
|
||||
self.stub_catalog_api()
|
||||
|
||||
self.auth_page = AutoAuthPage(self.browser, staff=True)
|
||||
self.dashboard_page = DashboardPageWithPrograms(self.browser)
|
||||
self.auth_page.visit()
|
||||
|
||||
def stub_programs_api(self):
|
||||
"""Stub out the programs API with fake data."""
|
||||
self.set_programs_api_configuration(is_enabled=True)
|
||||
ProgramsFixture().install_programs([])
|
||||
|
||||
def stub_catalog_api(self):
|
||||
"""Stub out the catalog API's program endpoint."""
|
||||
self.set_catalog_configuration(is_enabled=True)
|
||||
CatalogFixture().install_programs([])
|
||||
|
||||
def test_tab_is_disabled(self):
|
||||
"""
|
||||
The programs tab and "new program" button should not appear at all
|
||||
@@ -96,7 +109,6 @@ class DashboardProgramsTabTest(ProgramsConfigMixin, WebAppTest):
|
||||
via config. When the programs list is empty, a button should appear
|
||||
that allows creating a new program.
|
||||
"""
|
||||
self.set_programs_api_configuration(True)
|
||||
self.dashboard_page.visit()
|
||||
self.assertTrue(self.dashboard_page.is_programs_tab_present())
|
||||
self.assertTrue(self.dashboard_page.is_new_program_button_present())
|
||||
@@ -129,8 +141,6 @@ class DashboardProgramsTabTest(ProgramsConfigMixin, WebAppTest):
|
||||
|
||||
ProgramsFixture().install_programs(programs)
|
||||
|
||||
self.set_programs_api_configuration(True)
|
||||
|
||||
self.dashboard_page.visit()
|
||||
|
||||
self.assertTrue(self.dashboard_page.is_programs_tab_present())
|
||||
@@ -145,7 +155,6 @@ class DashboardProgramsTabTest(ProgramsConfigMixin, WebAppTest):
|
||||
The programs tab and "new program" button will not be available, even
|
||||
when enabled via config, if the user is not global staff.
|
||||
"""
|
||||
self.set_programs_api_configuration(True)
|
||||
AutoAuthPage(self.browser, staff=False).visit()
|
||||
self.dashboard_page.visit()
|
||||
self.assertFalse(self.dashboard_page.is_programs_tab_present())
|
||||
|
||||
Reference in New Issue
Block a user