Revert "Merge pull request #13235 from edx/jia/MA-2684"
This reverts commitbde0f7b2a7, reversing changes made to71693c3a12.
This commit is contained in:
@@ -2,30 +2,27 @@
|
||||
Utility methods related to course
|
||||
"""
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from openedx.core.djangoapps.catalog.utils import get_run_marketing_url
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_link_for_about_page(course_key, user, catalog_course_run=None):
|
||||
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'):
|
||||
if catalog_course_run:
|
||||
marketing_url = catalog_course_run.get('marketing_url')
|
||||
else:
|
||||
marketing_url = get_run_marketing_url(course_key, user)
|
||||
if marketing_url:
|
||||
return marketing_url
|
||||
# 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=settings.LMS_ROOT_URL,
|
||||
course_key=unicode(course_key)
|
||||
about_base_url=about_base,
|
||||
course_key=course_key.to_deprecated_string()
|
||||
)
|
||||
|
||||
@@ -1,73 +1,36 @@
|
||||
"""
|
||||
Tests for course utils.
|
||||
"""
|
||||
from django.core.cache import cache
|
||||
import httpretty
|
||||
|
||||
from django.test import TestCase, override_settings
|
||||
import mock
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from openedx.core.djangoapps.catalog.tests import factories
|
||||
from openedx.core.djangoapps.catalog.utils import CatalogCacheUtility
|
||||
from openedx.core.djangoapps.catalog.tests.mixins import CatalogIntegrationMixin
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from student.tests.factories import UserFactory
|
||||
from util.course import get_link_for_about_page
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from util.course import get_lms_link_for_about_page
|
||||
|
||||
|
||||
@httpretty.activate
|
||||
class CourseAboutLinkTestCase(CatalogIntegrationMixin, CacheIsolationTestCase):
|
||||
"""
|
||||
Tests for Course About link.
|
||||
"""
|
||||
class LmsLinksTestCase(TestCase):
|
||||
""" Tests for LMS links. """
|
||||
|
||||
ENABLED_CACHES = ['default']
|
||||
|
||||
def setUp(self):
|
||||
super(CourseAboutLinkTestCase, self).setUp()
|
||||
self.user = UserFactory.create(password="password")
|
||||
|
||||
self.course_key_string = "foo/bar/baz"
|
||||
self.course_key = CourseKey.from_string("foo/bar/baz")
|
||||
self.course_run = factories.CourseRun(key=self.course_key_string)
|
||||
self.lms_course_about_url = "http://localhost:8000/courses/foo/bar/baz/about"
|
||||
|
||||
self.catalog_integration = self.create_catalog_integration(
|
||||
internal_api_url="http://catalog.example.com:443/api/v1",
|
||||
cache_ttl=1
|
||||
)
|
||||
self.course_cache_key = "{}{}".format(CatalogCacheUtility.CACHE_KEY_PREFIX, self.course_key_string)
|
||||
|
||||
def test_about_page_lms(self):
|
||||
"""
|
||||
Get URL for about page, no marketing site.
|
||||
"""
|
||||
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(
|
||||
get_link_for_about_page(self.course_key, self.user), self.lms_course_about_url
|
||||
)
|
||||
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True}):
|
||||
self.register_catalog_course_run_response(
|
||||
[self.course_key_string], [{"key": self.course_key_string, "marketing_url": None}]
|
||||
)
|
||||
self.assertEquals(get_link_for_about_page(self.course_key, self.user), self.lms_course_about_url)
|
||||
self.assertEquals(self.get_about_page_link(), "http://localhost:8000/courses/mitX/101/test/about")
|
||||
|
||||
@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
|
||||
@override_settings(MKTG_URLS={'ROOT': 'https://dummy-root'})
|
||||
def test_about_page_marketing_site(self):
|
||||
"""
|
||||
Get URL for about page, marketing site enabled.
|
||||
"""
|
||||
self.register_catalog_course_run_response([self.course_key_string], [self.course_run])
|
||||
self.assertEquals(get_link_for_about_page(self.course_key, self.user), self.course_run["marketing_url"])
|
||||
cached_data = cache.get_many([self.course_cache_key])
|
||||
self.assertIn(self.course_cache_key, cached_data.keys())
|
||||
""" 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")
|
||||
|
||||
with mock.patch('openedx.core.djangoapps.catalog.utils.get_edx_api_data') as mock_method:
|
||||
self.assertEquals(get_link_for_about_page(self.course_key, self.user), self.course_run["marketing_url"])
|
||||
self.assertEqual(0, mock_method.call_count)
|
||||
@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")
|
||||
|
||||
@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
|
||||
def test_about_page_marketing_url_cached(self):
|
||||
self.assertEquals(
|
||||
get_link_for_about_page(self.course_key, self.user, self.course_run),
|
||||
self.course_run["marketing_url"]
|
||||
)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user