MA-2536: get 'course_about' url in enrollment

This commit is contained in:
wajeeha-khalid
2016-07-28 19:13:18 +05:00
parent cad10c2302
commit 986dcff626
28 changed files with 197 additions and 109 deletions

View File

@@ -0,0 +1,42 @@
"""
Common Functions to Validate Configurations
"""
def validate_lms_config(settings):
"""
Validates configurations for lms and raise ValueError if not valid
"""
validate_common_config(settings)
# validate feature based configurations
validate_marketing_site_config(settings)
def validate_cms_config(settings):
"""
Validates configurations for lms and raise ValueError if not valid
"""
validate_common_config(settings)
# validate feature based configurations
validate_marketing_site_config(settings)
def validate_common_config(settings):
"""
Validates configurations common for all apps
"""
if not getattr(settings, 'LMS_ROOT_URL', None):
raise ValueError("'LMS_ROOT_URL' is not defined.")
def validate_marketing_site_config(settings):
"""
Validates 'marketing site' related configurations
"""
if settings.FEATURES.get('ENABLE_MKTG_SITE'):
if not hasattr(settings, 'MKTG_URLS'):
raise ValueError("'ENABLE_MKTG_SITE' is True, but 'MKTG_URLS' is not defined.")
if not settings.MKTG_URLS.get('ROOT'):
raise ValueError("There is no 'ROOT' defined in 'MKTG_URLS'.")

View File

@@ -0,0 +1,28 @@
"""
Utility methods related to course
"""
import logging
from django.conf import settings
from opaque_keys.edx.keys import CourseKey
log = logging.getLogger(__name__)
def get_lms_link_for_about_page(course_key):
"""
Returns the url to the course about page.
"""
assert isinstance(course_key, CourseKey)
if settings.FEATURES.get('ENABLE_MKTG_SITE'):
# Root will be "https://www.edx.org". The complete URL will still not be exactly correct,
# but redirects exist from www.edx.org to get to the Drupal course about page URL.
about_base = settings.MKTG_URLS['ROOT']
else:
about_base = settings.LMS_ROOT_URL
return u"{about_base_url}/courses/{course_key}/about".format(
about_base_url=about_base,
course_key=course_key.to_deprecated_string()
)

View File

@@ -0,0 +1,36 @@
"""
Tests for course utils.
"""
from django.test import TestCase, override_settings
import mock
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from util.course import get_lms_link_for_about_page
class LmsLinksTestCase(TestCase):
""" Tests for LMS links. """
def test_about_page(self):
""" Get URL for about page, no marketing site """
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
self.assertEquals(self.get_about_page_link(), "http://localhost:8000/courses/mitX/101/test/about")
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root'})
def test_about_page_marketing_site(self):
""" Get URL for about page, marketing root present. """
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
self.assertEquals(self.get_about_page_link(), "https://dummy-root/courses/mitX/101/test/about")
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': False}):
self.assertEquals(self.get_about_page_link(), "http://localhost:8000/courses/mitX/101/test/about")
@override_settings(MKTG_URLS={'ROOT': 'https://www.dummyhttps://x'})
def test_about_page_marketing_site_https__edge(self):
""" Get URL for about page """
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
self.assertEquals(self.get_about_page_link(), "https://www.dummyhttps://x/courses/mitX/101/test/about")
def get_about_page_link(self):
""" create mock course and return the about page link."""
course_key = SlashSeparatedCourseKey('mitX', '101', 'test')
return get_lms_link_for_about_page(course_key)