multitenant Program cache.

Fetched Programs and Program details from Course Discovery service for all sites and stored the uuids in cache with site-specfic keys.
Learner-1146
This commit is contained in:
Afzal Wali
2017-06-14 15:13:16 +05:00
parent 51fc7b73bf
commit 383208c4c8
11 changed files with 205 additions and 95 deletions

View File

@@ -36,7 +36,6 @@ from django.utils.translation import get_language, ungettext
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
from django.views.decorators.http import require_GET, require_POST
from django.views.generic import TemplateView
from eventtracking import tracker
from ipware.ip import get_ip
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
@@ -46,9 +45,9 @@ from provider.oauth2.models import Client
from pytz import UTC
from ratelimitbackend.exceptions import RateLimitException
from requests import HTTPError
from social_django import utils as social_utils
from social_core.backends import oauth as social_oauth
from social_core.exceptions import AuthAlreadyAssociated, AuthException
from social_django import utils as social_utils
import dogstats_wrapper as dog_stats_api
import openedx.core.djangoapps.external_auth.views
@@ -66,6 +65,7 @@ from courseware.access import has_access
from courseware.courses import get_courses, sort_by_announcement, sort_by_start_date # pylint: disable=import-error
from django_comment_common.models import assign_role
from edxmako.shortcuts import render_to_response, render_to_string
from eventtracking import tracker
from lms.djangoapps.commerce.utils import EcommerceService # pylint: disable=import-error
from lms.djangoapps.grades.new.course_grade_factory import CourseGradeFactory
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification # pylint: disable=import-error
@@ -174,7 +174,6 @@ def index(request, extra_context=None, user=AnonymousUser()):
if extra_context is None:
extra_context = {}
programs_list = []
courses = get_courses(user)
if configuration_helpers.get_value(
@@ -208,17 +207,7 @@ def index(request, extra_context=None, user=AnonymousUser()):
# Insert additional context for use in the template
context.update(extra_context)
# Get the active programs of the type configured for the current site from the catalog service. The programs_list
# is being added to the context but it's not being used currently in courseware/courses.html. To use this list,
# you need to create a custom theme that overrides courses.html. The modifications to courses.html to display the
# programs will be done after the support for edx-pattern-library is added.
program_types = configuration_helpers.get_value('ENABLED_PROGRAM_TYPES')
# Do not add programs to the context if there are no program types enabled for the site.
if program_types:
programs_list = get_programs_with_type(program_types, include_hidden=False)
context["programs_list"] = programs_list
context['programs_list'] = get_programs_with_type(include_hidden=False)
return render_to_response('index.html', context)

View File

@@ -14,6 +14,7 @@ class StubCatalogServiceHandler(StubHttpRequestHandler):
pattern_handlers = {
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,
}
if self.match_pattern(pattern_handlers):
@@ -42,6 +43,10 @@ class StubCatalogServiceHandler(StubHttpRequestHandler):
program = self.server.config.get('catalog.programs.' + program_uuid)
self.send_json_response(program)
def program_types(self):
program_types = self.server.config.get('catalog.programs_types', [])
self.send_json_response(program_types)
class StubCatalogService(StubHttpService):
HANDLER_CLASS = StubCatalogServiceHandler

View File

@@ -29,7 +29,6 @@ class CatalogFixture(object):
uuids.append(uuid)
program_key = '{base}.{uuid}'.format(base=key, uuid=uuid)
requests.put(
'{}/set_config'.format(CATALOG_STUB_URL),
data={program_key: json.dumps(program)},
@@ -41,6 +40,18 @@ class CatalogFixture(object):
data={key: json.dumps(uuids)},
)
def install_program_types(self, program_types):
"""
Stub the discovery service's program type list API endpoints.
Arguments:
program_types (list): A list of program types. List endpoint will be stubbed using data from this list.
"""
requests.put(
'{}/set_config'.format(CATALOG_STUB_URL),
data={'catalog.programs_types': json.dumps(program_types)},
)
class CatalogIntegrationMixin(object):
"""Mixin providing a method used to configure the catalog integration."""

View File

@@ -8,7 +8,12 @@ from common.test.acceptance.pages.common.auto_auth import AutoAuthPage
from common.test.acceptance.pages.lms.catalog import CacheProgramsPage
from common.test.acceptance.pages.lms.programs import ProgramDetailsPage, ProgramListingPage
from common.test.acceptance.tests.helpers import UniqueCourseTest
from openedx.core.djangoapps.catalog.tests.factories import CourseFactory, CourseRunFactory, ProgramFactory
from openedx.core.djangoapps.catalog.tests.factories import (
CourseFactory,
CourseRunFactory,
ProgramFactory,
ProgramTypeFactory
)
class ProgramPageBase(ProgramsConfigMixin, CatalogIntegrationMixin, UniqueCourseTest):
@@ -36,7 +41,8 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogIntegrationMixin, UniqueCourse
course_run = CourseRunFactory(key=self.course_id)
course = CourseFactory(course_runs=[course_run])
return ProgramFactory(courses=[course])
program_type = ProgramTypeFactory()
return ProgramFactory(courses=[course], type=program_type['name'])
def stub_catalog_api(self, programs):
"""
@@ -45,6 +51,9 @@ class ProgramPageBase(ProgramsConfigMixin, CatalogIntegrationMixin, UniqueCourse
self.set_catalog_integration(is_enabled=True, service_username=self.username)
CatalogFixture().install_programs(programs)
program_types = [program['type'] for program in programs]
CatalogFixture().install_program_types(program_types)
def cache_programs(self):
"""
Populate the LMS' cache of program data.