Skip to content
Snippets Groups Projects
Unverified Commit 900b7e25 authored by Nimisha Asthagiri's avatar Nimisha Asthagiri Committed by GitHub
Browse files

Merge pull request #20001 from mahyard/master

Support a URL address as FOOTER_ORGANIZATION_LOGO
parents 1cb09ec3 3d23ee43
No related branches found
No related tags found
No related merge requests found
......@@ -486,13 +486,12 @@ def _absolute_url_staticfile(is_secure, name):
unicode
"""
url_path = staticfiles_storage.url(name)
# In production, the static file name will be an absolute
# URL pointing to a CDN. In this case, we can just return the URL.
if six.moves.urllib.parse.urlparse(name).netloc:
return name
# In production, the static files URL will be an absolute
# URL pointing to a CDN. If this happens, we can just
# return the URL.
if six.moves.urllib.parse.urlparse(url_path).netloc:
return url_path
url_path = staticfiles_storage.url(name)
# For local development, the returned URL will be relative,
# so we need to make it absolute.
......
......@@ -9,7 +9,7 @@ import mock
import six
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse
from branding.models import BrandingApiConfig
......@@ -109,13 +109,10 @@ class TestFooter(CacheIsolationTestCase):
def test_absolute_urls_with_cdn(self):
self._set_feature_flag(True)
# 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):
# Requesting footer while we have overridden FOOTER_ORGANIZATION_IMAGE
# with an absolute url
cdn_url = u"http://cdn.example.com/static/image.png"
with override_settings(FOOTER_ORGANIZATION_IMAGE=cdn_url):
resp = self._get_footer()
self.assertEqual(resp.status_code, 200)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment