From 6f880cdc76068a9a6dcf112965f43c198f4835a8 Mon Sep 17 00:00:00 2001 From: hachiyanagi-ks Date: Thu, 29 Oct 2015 17:55:38 +0900 Subject: [PATCH] Enable to configure the header logo #470 --- lms/djangoapps/branding/__init__.py | 2 +- lms/djangoapps/branding/tests/test_views.py | 43 +++++++++++++++++++++ lms/envs/aws.py | 3 ++ lms/envs/common.py | 3 ++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/branding/__init__.py b/lms/djangoapps/branding/__init__.py index fabc73a10f6e..26606606d34b 100644 --- a/lms/djangoapps/branding/__init__.py +++ b/lms/djangoapps/branding/__init__.py @@ -54,7 +54,7 @@ def get_logo_url(): # if the MicrositeConfiguration has a value for the logo_image_url # let's use that - image_url = microsite.get_value('logo_image_url') + image_url = microsite.get_value('logo_image_url', getattr(settings, 'HEADER_LOGO_IMAGE', None)) if image_url: return '{static_url}{image_url}'.format( static_url=settings.STATIC_URL, diff --git a/lms/djangoapps/branding/tests/test_views.py b/lms/djangoapps/branding/tests/test_views.py index 64dd0f3b5143..171f26e79518 100644 --- a/lms/djangoapps/branding/tests/test_views.py +++ b/lms/djangoapps/branding/tests/test_views.py @@ -6,10 +6,12 @@ from django.test import TestCase from django.core.urlresolvers import reverse from django.conf import settings +from django.test.utils import override_settings import mock import ddt from config_models.models import cache +from branding import get_logo_url from branding.models import BrandingApiConfig @@ -233,3 +235,44 @@ def _set_is_edx_domain(self, is_edx_domain): """Configure whether this an EdX-controlled domain. """ with mock.patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': is_edx_domain}): yield + + +def university_microsite_configuration(): + return { + 'university': 'test-university' + } + + +def logo_image_microsite_configuration(): + return { + 'university': 'test-university', + 'logo_image_url': 'images/test-microsite-logo.png' + } + + +class LogoUrlTest(TestCase): + """Tests for logo url""" + + def _logo_url(self, path): + return settings.STATIC_URL + path + + def test_default_logo(self): + self.assertEqual(self._logo_url('images/default-theme/logo.png'), get_logo_url()) + + @override_settings(FEATURES={"IS_EDX_DOMAIN":True}) + def test_default_logo_edx_domain(self): + self.assertEqual(self._logo_url('images/edx-theme/edx-logo-77x36.png'), get_logo_url()) + + @override_settings(FEATURES={"IS_EDX_DOMAIN":True}) + @mock.patch("microsite_configuration.microsite.get_configuration", university_microsite_configuration) + def test_university_logo(self): + self.assertEqual(self._logo_url('images/test-university-on-edx-logo.png'), get_logo_url()) + + @override_settings(HEADER_LOGO_IMAGE='images/test-header-logo-image.png') + def test_settings_header_logo_image(self): + self.assertEqual(self._logo_url('images/test-header-logo-image.png'), get_logo_url()) + + @override_settings(HEADER_LOGO_IMAGE='images/test-header-logo-image.png') + @mock.patch("microsite_configuration.microsite.get_configuration", logo_image_microsite_configuration) + def test_settings_header_logo_image_microsite(self): + self.assertEqual(self._logo_url('images/test-microsite-logo.png'), get_logo_url()) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index e2e99e288f20..d15c93e48a39 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -323,6 +323,9 @@ # Example: {'CN': 'http://api.xuetangx.com/edx/video?s3_url='} VIDEO_CDN_URL = ENV_TOKENS.get('VIDEO_CDN_URL', {}) +# Branded header +HEADER_LOGO_IMAGE = ENV_TOKENS.get('HEADER_LOGO_IMAGE', HEADER_LOGO_IMAGE) + # Branded footer FOOTER_OPENEDX_URL = ENV_TOKENS.get('FOOTER_OPENEDX_URL', FOOTER_OPENEDX_URL) FOOTER_OPENEDX_LOGO_IMAGE = ENV_TOKENS.get('FOOTER_OPENEDX_LOGO_IMAGE', FOOTER_OPENEDX_LOGO_IMAGE) diff --git a/lms/envs/common.py b/lms/envs/common.py index d93b6991a6a0..1ecf3b748b00 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1074,6 +1074,9 @@ JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' +######################### Branded Header ################################### +HEADER_LOGO_IMAGE = None + ######################### Branded Footer ################################### # Constants for the footer used on the site and shared with other sites # (such as marketing and the blog) via the branding API.