Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion lms/djangoapps/branding/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import six
from django.conf import settings
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.test import TestCase
from django.test import override_settings, TestCase
from django.urls import reverse

from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.branding.models import BrandingApiConfig

from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
from openedx.core.djangoapps.lang_pref.api import released_languages
from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin
Expand Down Expand Up @@ -249,6 +250,7 @@ def _verify_language_selector(self, response, selected_language):
assert f'<option value="{language.code}">' in content


@ddt.ddt
class TestIndex(SiteMixin, TestCase):
""" Test the index view """

Expand Down Expand Up @@ -286,3 +288,66 @@ def test_header_logo_links_to_marketing_site_with_site_override(self):
self.client.login(username=self.user.username, password="password")
response = self.client.get(reverse("dashboard"))
assert self.site_configuration_other.site_values['MKTG_URLS']['ROOT'] in response.content.decode('utf-8')

@ddt.data(
(True, True),
(True, False),
(False, False),
(False, False),
)
@ddt.unpack
def test_index_redirects_to_mfe(self, catalog_mfe_enabled, expected_redirect):
"""Test that index view redirects to MFE when both flags are enabled."""
new_settings = {
"ENABLE_CATALOG_MICROFRONTEND": catalog_mfe_enabled,
"CATALOG_MICROFRONTEND_URL": "http://example.com/catalog",
}
with override_settings(**new_settings):
response = self.client.get(reverse("root"))

if expected_redirect:
expected_url = f'{settings.CATALOG_MICROFRONTEND_URL}/'
self.assertRedirects(
response,
expected_url,
status_code=301,
fetch_redirect_response=False
)
else:
assert response.status_code in [200, 301, 302]


@ddt.ddt
class TestCourses(SiteMixin, TestCase):
"""Test the courses view"""

def setUp(self):
super().setUp()
self.courses_url = reverse("courses")

@ddt.data(
(True, True),
(True, False),
(False, False),
(False, False),
)
@ddt.unpack
def test_courses_redirect_to_mfe(self, catalog_mfe_enabled, expected_redirect):
"""Test that courses view redirects to MFE when both flags are enabled"""
new_settings = {
"ENABLE_CATALOG_MICROFRONTEND": catalog_mfe_enabled,
"CATALOG_MICROFRONTEND_URL": "http://example.com/catalog",
}
with override_settings(**new_settings):
response = self.client.get(self.courses_url)

if expected_redirect:
expected_url = f'{settings.CATALOG_MICROFRONTEND_URL}/courses'
self.assertRedirects(
response,
expected_url,
status_code=301,
fetch_redirect_response=False
)
else:
assert response.status_code in [200, 301, 302]
7 changes: 7 additions & 0 deletions lms/djangoapps/branding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.views.decorators.csrf import ensure_csrf_cookie

import lms.djangoapps.branding.api as branding_api
from lms.djangoapps.branding.toggles import use_catalog_mfe
import lms.djangoapps.courseware.views.views as courseware_views
from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response
from common.djangoapps.student import views as student_views
Expand Down Expand Up @@ -44,6 +45,9 @@ def index(request):
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)):
return redirect('dashboard')

if use_catalog_mfe():
return redirect(f'{settings.CATALOG_MICROFRONTEND_URL}/', permanent=True)

enable_mktg_site = configuration_helpers.get_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
Expand Down Expand Up @@ -87,6 +91,9 @@ def courses(request):
to that. Otherwise, if subdomain branding is on, this is the university
profile page. Otherwise, it's the edX courseware.views.views.courses page
"""
if use_catalog_mfe():
return redirect(f'{settings.CATALOG_MICROFRONTEND_URL}/courses', permanent=True)

enable_mktg_site = configuration_helpers.get_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
Expand Down
35 changes: 33 additions & 2 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
from django.contrib.auth.models import AnonymousUser
from django.http import Http404, HttpResponse, HttpResponseBadRequest
from django.http.request import QueryDict
from django.test import RequestFactory, TestCase
from django.test import override_settings, RequestFactory, TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.urls import reverse, reverse_lazy
from edx_django_utils.cache.utils import RequestCache
from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch
Expand Down Expand Up @@ -3390,3 +3389,35 @@ def test_courseware_mfe_navigation_sidebar_toggles_disabled_completion_track_ena
"enable_completion_tracking": True,
},
)


@ddt.ddt
class CourseAboutViewTests(ModuleStoreTestCase):
"""
Tests for the CourseAboutView.
"""

def setUp(self):
super().setUp()
self.course = CourseFactory.create()

@ddt.data(
(True, True),
(False, False),
)
@ddt.unpack
def test_course_about_redirect_to_mfe(self, catalog_mfe_enabled, expected_redirect):
"""
Test that the CourseAboutView redirects to the MFE when appropriate.
"""
new_settings = {
"ENABLE_CATALOG_MICROFRONTEND": catalog_mfe_enabled,
"CATALOG_MICROFRONTEND_URL": "http://example.com/catalog",
}
with override_settings(**new_settings):
response = self.client.get(reverse('about_course', args=[str(self.course.id)]))
if expected_redirect:
assert response.status_code == 301
assert response.url == "http://example.com/catalog/courses/{}/about".format(self.course.id)
else:
assert response.status_code == 200
8 changes: 7 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.models import CourseEnrollment, UserTestGroup
from common.djangoapps.util.cache import cache, cache_if_anonymous
from common.djangoapps.util.course import course_location_from_key
from common.djangoapps.util.course import course_location_from_key, get_link_for_about_page
from common.djangoapps.util.db import outer_atomic
from common.djangoapps.util.milestones_helpers import get_prerequisite_courses_display
from common.djangoapps.util.views import ensure_valid_course_key, ensure_valid_usage_key
from lms.djangoapps.branding import toggles as branding_toggles
from lms.djangoapps.ccx.custom_exception import CCXLocatorValidationException
from lms.djangoapps.certificates import api as certs_api
from lms.djangoapps.certificates.data import CertificateStatuses
Expand Down Expand Up @@ -817,6 +818,11 @@ def course_about(request, course_id): # pylint: disable=too-many-statements
if _course_home_redirect_enabled():
return redirect(course_home_url(course_key))

# If the course about page is being rendered in the MFE, redirect to the MFE.
if branding_toggles.use_catalog_mfe():
course_overview = CourseOverview.get_from_id(course_key)
return redirect(get_link_for_about_page(course_overview), permanent=True)

with modulestore().bulk_operations(course_key):
permission = get_permission_for_course_about()
course = get_course_with_access(request.user, permission, course_key)
Expand Down
Loading