Merge pull request #19835 from edx/revert-19677-emma-green/REVEM-176/cache-course_runs-to-programs
Revert "WIP:Cache course runs to programs"
This commit is contained in:
@@ -695,7 +695,7 @@ def student_dashboard(request):
|
||||
for program in inverted_programs.values():
|
||||
try:
|
||||
program_uuid = program[0]['uuid']
|
||||
program_data = get_programs(uuid=program_uuid)
|
||||
program_data = get_programs(request.site, uuid=program_uuid)
|
||||
program_data = ProgramDataExtender(program_data, request.user).extend()
|
||||
skus = program_data.get('skus')
|
||||
checkout_page_url = ecommerce_service.get_checkout_page_url(*skus)
|
||||
|
||||
@@ -15,8 +15,7 @@ class StubCatalogServiceHandler(StubHttpRequestHandler):
|
||||
r'/api/v1/programs/$': self.program_list,
|
||||
r'/api/v1/programs/([0-9a-f-]+)/$': self.program_detail,
|
||||
r'/api/v1/program_types/$': self.program_types,
|
||||
r'/api/v1/pathways/$': self.pathways,
|
||||
r'/api/v1/course_runs/$': self.course_runs,
|
||||
r'/api/v1/pathways/$': self.pathways
|
||||
}
|
||||
|
||||
if self.match_pattern(pattern_handlers):
|
||||
@@ -53,10 +52,6 @@ class StubCatalogServiceHandler(StubHttpRequestHandler):
|
||||
pathways = self.server.config.get('catalog.pathways', [])
|
||||
self.send_json_response(pathways)
|
||||
|
||||
def course_runs(self):
|
||||
course_runs = self.server.config.get('catalog.course_runs', {'results': [], 'next': None})
|
||||
self.send_json_response(course_runs)
|
||||
|
||||
|
||||
class StubCatalogService(StubHttpService):
|
||||
HANDLER_CLASS = StubCatalogServiceHandler
|
||||
|
||||
@@ -13,8 +13,7 @@ class CatalogFixture(object):
|
||||
"""
|
||||
Interface to set up mock responses from the Catalog stub server.
|
||||
"""
|
||||
@classmethod
|
||||
def install_programs(cls, programs):
|
||||
def install_programs(self, programs):
|
||||
"""
|
||||
Stub the discovery service's program list and detail API endpoints.
|
||||
|
||||
@@ -41,8 +40,7 @@ class CatalogFixture(object):
|
||||
data={key: json.dumps(uuids)},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def install_pathways(cls, pathways):
|
||||
def install_pathways(self, pathways):
|
||||
"""
|
||||
Stub the discovery service's credit pathways API endpoint
|
||||
|
||||
@@ -54,8 +52,7 @@ class CatalogFixture(object):
|
||||
data={'catalog.pathways': json.dumps({'results': pathways, 'next': None})}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def install_program_types(cls, program_types):
|
||||
def install_program_types(self, program_types):
|
||||
"""
|
||||
Stub the discovery service's program type list API endpoints.
|
||||
|
||||
@@ -67,25 +64,10 @@ class CatalogFixture(object):
|
||||
data={'catalog.programs_types': json.dumps(program_types)},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def install_course_runs(cls, course_runs):
|
||||
"""
|
||||
Stub the discovery service's course run list API endpoints.
|
||||
|
||||
Arguments:
|
||||
course_runs (list): A list of course runs. List endpoint will be stubbed using data from this list.
|
||||
"""
|
||||
requests.put(
|
||||
'{}/set_config'.format(CATALOG_STUB_URL),
|
||||
data={'catalog.course_runs': json.dumps({'results': course_runs, 'next': None})}
|
||||
)
|
||||
|
||||
|
||||
class CatalogIntegrationMixin(object):
|
||||
"""Mixin providing a method used to configure the catalog integration."""
|
||||
|
||||
@classmethod
|
||||
def set_catalog_integration(cls, is_enabled=False, service_username=None):
|
||||
def set_catalog_integration(self, is_enabled=False, service_username=None):
|
||||
"""Use this to change the catalog integration config model during tests."""
|
||||
ConfigModelFixture('/config/catalog', {
|
||||
'enabled': is_enabled,
|
||||
|
||||
@@ -11,8 +11,7 @@ from openedx.core.djangoapps.catalog.tests.factories import (
|
||||
CourseRunFactory,
|
||||
PathwayFactory,
|
||||
ProgramFactory,
|
||||
ProgramTypeFactory,
|
||||
ProgramDescriptionFactory,
|
||||
ProgramTypeFactory
|
||||
)
|
||||
|
||||
|
||||
@@ -25,12 +24,6 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogIntegrationMixin, UniqueCourse
|
||||
|
||||
self.programs = ProgramFactory.create_batch(3)
|
||||
self.pathways = PathwayFactory.create_batch(3)
|
||||
self.course_runs = [
|
||||
CourseRunFactory.create(programs=[ProgramDescriptionFactory.from_program(program)], **course_run)
|
||||
for program in self.programs
|
||||
for course in program['courses']
|
||||
for course_run in course['course_runs']
|
||||
]
|
||||
for pathway in self.pathways:
|
||||
self.programs += pathway['programs']
|
||||
|
||||
@@ -58,28 +51,18 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogIntegrationMixin, UniqueCourse
|
||||
program_type = ProgramTypeFactory()
|
||||
return ProgramFactory(courses=[course], type=program_type['name'])
|
||||
|
||||
def stub_catalog_api(self, programs=None, pathways=None, course_runs=None):
|
||||
def stub_catalog_api(self, programs, pathways):
|
||||
"""
|
||||
Stub the discovery service's program list and detail API endpoints, as well as
|
||||
the credit pathway list endpoint.
|
||||
"""
|
||||
self.set_catalog_integration(is_enabled=True, service_username=self.username)
|
||||
|
||||
if programs is None:
|
||||
programs = self.programs
|
||||
|
||||
CatalogFixture.install_programs(programs)
|
||||
CatalogFixture().install_programs(programs)
|
||||
|
||||
program_types = [program['type'] for program in programs]
|
||||
CatalogFixture.install_program_types(program_types)
|
||||
CatalogFixture().install_program_types(program_types)
|
||||
|
||||
if pathways is None:
|
||||
pathways = self.pathways
|
||||
CatalogFixture.install_pathways(pathways)
|
||||
|
||||
if course_runs is None:
|
||||
course_runs = self.course_runs
|
||||
CatalogFixture.install_course_runs(course_runs)
|
||||
CatalogFixture().install_pathways(pathways)
|
||||
|
||||
def cache_programs(self):
|
||||
"""
|
||||
@@ -101,7 +84,7 @@ class ProgramListingPageTest(ProgramPageBase):
|
||||
def test_no_enrollments(self):
|
||||
"""Verify that no cards appear when the user has no enrollments."""
|
||||
self.auth(enroll=False)
|
||||
self.stub_catalog_api()
|
||||
self.stub_catalog_api(self.programs, self.pathways)
|
||||
self.cache_programs()
|
||||
|
||||
self.listing_page.visit()
|
||||
@@ -115,7 +98,7 @@ class ProgramListingPageTest(ProgramPageBase):
|
||||
but none are included in an active program.
|
||||
"""
|
||||
self.auth()
|
||||
self.stub_catalog_api()
|
||||
self.stub_catalog_api(self.programs, self.pathways)
|
||||
self.cache_programs()
|
||||
|
||||
self.listing_page.visit()
|
||||
@@ -143,15 +126,7 @@ class ProgramListingPageA11yTest(ProgramPageBase):
|
||||
]
|
||||
})
|
||||
self.auth(enroll=False)
|
||||
self.stub_catalog_api(
|
||||
programs=[self.program],
|
||||
pathways=[],
|
||||
course_runs=[
|
||||
CourseRunFactory.create(programs=[ProgramDescriptionFactory.from_program(self.program)], **course_run)
|
||||
for course in self.program['courses']
|
||||
for course_run in course['course_runs']
|
||||
]
|
||||
)
|
||||
self.stub_catalog_api(programs=[self.program], pathways=[])
|
||||
self.cache_programs()
|
||||
|
||||
self.listing_page.visit()
|
||||
@@ -168,15 +143,7 @@ class ProgramListingPageA11yTest(ProgramPageBase):
|
||||
]
|
||||
})
|
||||
self.auth()
|
||||
self.stub_catalog_api(
|
||||
programs=[self.program],
|
||||
pathways=[],
|
||||
course_runs=[
|
||||
CourseRunFactory.create(programs=[ProgramDescriptionFactory.from_program(self.program)], **course_run)
|
||||
for course in self.program['courses']
|
||||
for course_run in course['course_runs']
|
||||
]
|
||||
)
|
||||
self.stub_catalog_api(programs=[self.program], pathways=[])
|
||||
self.cache_programs()
|
||||
|
||||
self.listing_page.visit()
|
||||
@@ -206,15 +173,7 @@ class ProgramDetailsPageA11yTest(ProgramPageBase):
|
||||
]
|
||||
})
|
||||
self.auth()
|
||||
self.stub_catalog_api(
|
||||
programs=[self.program],
|
||||
pathways=[],
|
||||
course_runs=[
|
||||
CourseRunFactory.create(programs=[ProgramDescriptionFactory.from_program(self.program)], **course_run)
|
||||
for course in self.program['courses']
|
||||
for course_run in course['course_runs']
|
||||
]
|
||||
)
|
||||
self.stub_catalog_api(programs=[self.program], pathways=[])
|
||||
self.cache_programs()
|
||||
|
||||
self.details_page.visit()
|
||||
|
||||
Reference in New Issue
Block a user