Skip to content

Commit

Permalink
Merge pull request #450 from ucsd-ets/release-candidate
Browse files Browse the repository at this point in the history
release-2021-04-03
  • Loading branch information
sheralim012 authored Mar 4, 2021
2 parents 43d1dd4 + a02924e commit 876d19e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
24 changes: 24 additions & 0 deletions lms/djangoapps/branding/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8
"""Tests of Branding API views. """
from copy import deepcopy
import json
import urllib

Expand Down Expand Up @@ -315,3 +316,26 @@ 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"))
self.assertIn(self.site_configuration_other.values["MKTG_URLS"]["ROOT"], response.content)

def test_index_redirects_to_courses_with_site_override(self):
""" Test index view redirects if ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER is set in SiteConfiguration """
self.use_site(self.site_for_courses_redirection)
response = self.client.get(reverse("root"))
self.assertRedirects(
response,
reverse('courses'),
fetch_redirect_response=False
)

def test_index_redirects_to_courses_with_feature_flag(self):
""" Test index view redirects if ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER feature flag is set """
self.use_site(self.site_for_courses_redirection)
feature_flags = deepcopy(settings.FEATURES)
feature_flags['ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER'] = True
with self.settings(FEATURES=feature_flags):
response = self.client.get(reverse("root"))
self.assertRedirects(
response,
reverse('courses'),
fetch_redirect_response=False
)
7 changes: 7 additions & 0 deletions lms/djangoapps/branding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def index(request):
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)):
return redirect(reverse('dashboard'))

# Redirect to courses if user is anonymous
if request.user.is_anonymous:
if configuration_helpers.get_value(
'ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER',
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER', False)):
return redirect(reverse('courses'))

if settings.FEATURES.get('AUTH_USE_CERTIFICATES'):
from openedx.core.djangoapps.external_auth.views import ssl_login
# Set next URL to dashboard if it isn't set to avoid
Expand Down
5 changes: 3 additions & 2 deletions lms/djangoapps/commerce/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ def test_update(self):
self.assertIsNone(VerificationDeadline.deadline_for_course(self.course.id))

# Generate the expected data
verification_deadline = datetime(year=2020, month=12, day=31, tzinfo=pytz.utc)
expiration_datetime = datetime.now(pytz.utc)
now = datetime.now(pytz.utc)
verification_deadline = now + timedelta(days=1)
expiration_datetime = now
response, expected = self._get_update_response_and_expected_data(expiration_datetime, verification_deadline)

# Sanity check: The API should return HTTP status 200 for updates
Expand Down
12 changes: 12 additions & 0 deletions openedx/core/djangoapps/site_configuration/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def setUp(self):
}
)

self.site_for_courses_redirection = SiteFactory.create(
domain='fake.site.domain',
name='fake.site.name'
)
self.site_configuration_for_courses_redirection = SiteConfigurationFactory.create(
site=self.site_for_courses_redirection,
values={
"SITE_NAME": self.site_for_courses_redirection.domain,
"ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER": True,
}
)

# Initialize client with default site domain
self.use_site(self.site)

Expand Down

0 comments on commit 876d19e

Please sign in to comment.