Skip to content

Commit

Permalink
Fix get_absolute_static_url calling get_current_scheme without passin…
Browse files Browse the repository at this point in the history
…g the request
  • Loading branch information
aarranz committed Oct 2, 2018
1 parent 4b0a884 commit 6c6e3a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/wirecloud/commons/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

from wirecloud.commons.exceptions import ErrorResponse
from wirecloud.commons.utils.html import clean_html, filter_changelog
from wirecloud.commons.utils.http import build_downloadfile_response, build_sendfile_response, get_current_domain, get_current_scheme, get_content_type, normalize_boolean_param, produces, validate_url_param
from wirecloud.commons.utils.http import build_downloadfile_response, build_sendfile_response, get_absolute_static_url, get_current_domain, get_current_scheme, get_content_type, normalize_boolean_param, produces, validate_url_param
from wirecloud.commons.utils.log import SkipUnreadablePosts
from wirecloud.commons.utils.mimeparser import best_match, InvalidMimeType, parse_mime_type
from wirecloud.commons.utils.version import Version
from wirecloud.commons.utils.wgt import WgtFile
from wirecloud.platform.core.plugins import get_version_hash


# Avoid nose to repeat these tests (they are run through wirecloud/commons/tests/__init__.py)
Expand Down Expand Up @@ -565,6 +566,31 @@ def test_get_content_type_invalid_mime_type(self):
request.META['CONTENT_TYPE'] = 'application/json/ji'
self.assertEqual(get_content_type(request), ('', {}))

@override_settings(STATIC_URL="/static/")
@patch("wirecloud.commons.utils.http.get_current_scheme")
@patch("wirecloud.commons.utils.http.get_current_domain")
def test_get_absolute_static_url_unversioned(self, get_current_domain, get_current_scheme):
request = self._prepare_request_mock()
get_current_scheme.return_value = "http"
get_current_domain.return_value = "dashboards.example.org"

self.assertEqual(get_absolute_static_url("/path", request=request), 'http://dashboards.example.org/path')

get_current_scheme.assert_called_once_with(request)
get_current_domain.assert_called_once_with(request)

@override_settings(STATIC_URL="/static/")
@patch("wirecloud.commons.utils.http.get_current_scheme")
@patch("wirecloud.commons.utils.http.get_current_domain")
def test_get_absolute_static_url_versioned(self, get_current_domain, get_current_scheme):
request = self._prepare_request_mock()
get_current_scheme.return_value = "http"
get_current_domain.return_value = "dashboards.example.org"
self.assertEqual(get_absolute_static_url("/path", request=request, versioned=True), 'http://dashboards.example.org/path?v=' + get_version_hash())

get_current_scheme.assert_called_once_with(request)
get_current_domain.assert_called_once_with(request)

@override_settings(FORCE_PROTO=None)
def test_get_current_scheme_http(self):
request = self._prepare_request_mock()
Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/commons/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def get_absolute_reverse_url(viewname, request=None, **kwargs):
def get_absolute_static_url(url, request=None, versioned=False):
from django.conf import settings

scheme = get_current_scheme()
scheme = get_current_scheme(request)
base = urljoin(scheme + '://' + get_current_domain(request), settings.STATIC_URL)

if versioned:
Expand Down

0 comments on commit 6c6e3a1

Please sign in to comment.