diff --git a/lms/djangoapps/branding/api.py b/lms/djangoapps/branding/api.py index fa90d53309..857706a863 100644 --- a/lms/djangoapps/branding/api.py +++ b/lms/djangoapps/branding/api.py @@ -367,18 +367,20 @@ def get_base_url(is_secure): return _absolute_url(is_secure=is_secure, url_path="") -def get_logo_url(): +def get_logo_url(is_secure=True): """ Return the url for the branded logo image to be used + Arguments: + is_secure (bool): If true, use HTTPS as the protocol. """ # if the MicrositeConfiguration has a value for the logo_image_url # let's use that image_url = microsite.get_value('logo_image_url') if image_url: - return '{static_url}{image_url}'.format( - static_url=settings.STATIC_URL, - image_url=image_url + return _absolute_url_staticfile( + is_secure=is_secure, + name=image_url, ) # otherwise, use the legacy means to configure this diff --git a/lms/djangoapps/branding/tests/test_api.py b/lms/djangoapps/branding/tests/test_api.py new file mode 100644 index 0000000000..c2efd6b932 --- /dev/null +++ b/lms/djangoapps/branding/tests/test_api.py @@ -0,0 +1,23 @@ +# encoding: utf-8 +"""Tests of Branding API """ + +from django.test import TestCase + +import mock +from branding.api import get_logo_url + + +class TestHeader(TestCase): + """Test API end-point for retrieving the header. """ + + def test_cdn_urls_for_logo(self): + # Ordinarily, we'd use `override_settings()` to override STATIC_URL, + # which is what the staticfiles storage backend is using to construct the URL. + # Unfortunately, other parts of the system are caching this value on module + # load, which can cause other tests to fail. To ensure that this change + # doesn't affect other tests, we patch the `url()` method directly instead. + cdn_url = "http://cdn.example.com/static/image.png" + with mock.patch('branding.api.staticfiles_storage.url', return_value=cdn_url): + logo_url = get_logo_url() + + self.assertEqual(logo_url, cdn_url) diff --git a/lms/djangoapps/certificates/api.py b/lms/djangoapps/certificates/api.py index 9c5ead15a1..56b71d5ce8 100644 --- a/lms/djangoapps/certificates/api.py +++ b/lms/djangoapps/certificates/api.py @@ -571,7 +571,7 @@ def get_certificate_header_context(is_secure=True): data returned should be customized according to the microsite settings """ data = dict( - logo_src=branding_api.get_logo_url(), + logo_src=branding_api.get_logo_url(is_secure), logo_url=branding_api.get_base_url(is_secure), ) diff --git a/lms/templates/navigation.html b/lms/templates/navigation.html index 265acf7a97..8521627c28 100644 --- a/lms/templates/navigation.html +++ b/lms/templates/navigation.html @@ -53,7 +53,7 @@ site_status_msg = get_site_status_msg(course_id)

<%block name="navigation_logo"> - ${_( + ${_(