Skip to content

Commit

Permalink
Added a unit test for having both a root_path and SCRIPT_NAME env
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGoderre committed Apr 1, 2016
1 parent e55dfca commit 87c6a4e
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions ckan/tests/lib/test_helpers.py
@@ -1,8 +1,8 @@
import nose
import i18n
import pytz
import tzlocal
from babel import Locale
from pylons import config

import ckan.lib.helpers as h
import ckan.exceptions
Expand Down Expand Up @@ -37,18 +37,38 @@ def test_url_for_static_raises_when_called_with_protocol_relative(self):

@helpers.change_config('ckan.site_url', 'http://example.com')
@helpers.change_config('ckan.root_path', '/my/custom/path/{{LANG}}/foo')
def test_url_for_static_with_root_path_and_locale(self):
def test_url_for_static_with_root_path(self):
url = '/my/custom/path/foo/my-asset/file.txt'
generated_url = h.url_for_static('/my-asset/file.txt')
eq_(generated_url, url)

@helpers.change_config('ckan.site_url', 'http://example.com')
@helpers.change_config('ckan.root_path', '/my/custom/path/{{LANG}}/foo')
def test_url_for_static_qualified_with_root_path_and_locale(self):
def test_url_for_static_qualified_with_root_path(self):
url = 'http://example.com/my/custom/path/foo/my-asset/file.txt'
generated_url = h.url_for_static('/my-asset/file.txt', qualified=True)
eq_(generated_url, url)

def test_url_for_static_with_root_path_and_script_name_env(self):
app = helpers._get_test_app()
app.get('/', extra_environ={
'SCRIPT_NAME': '/my/custom/path'
})
original = config.copy()
config['ckan.site_url'] = 'http://example.com'
config['ckan.root_path'] = '/my/custom/path/{{LANG}}/foo'
url = 'http://example.com/my/custom/path/foo/my-asset/file.txt'

try:
generated_url = h.url_for_static('/my-asset/file.txt', qualified=True)
eq_(generated_url, url)
finally:
config.clear()
config.update(original)
app.get('/', extra_environ={
'SCRIPT_NAME': ''
})


class TestHelpersUrlForStaticOrExternal(object):

Expand Down Expand Up @@ -148,6 +168,29 @@ def test_url_for_qualified_with_root_path_and_locale(self):
locale='de')
eq_(generated_url, url)

def test_url_for_qualified_with_root_path_locale_and_script_name_env(self):
app = helpers._get_test_app()
app.get('/', extra_environ={
'SCRIPT_NAME': '/my/custom/path'
})
original = config.copy()
config['ckan.site_url'] = 'http://example.com'
config['ckan.root_path'] = '/my/custom/path/{{LANG}}/foo'
url = 'http://example.com/my/custom/path/de/foo/dataset/my_dataset'
try:
generated_url = h.url_for(controller='package',
action='read',
id='my_dataset',
qualified=True,
locale='de')
eq_(generated_url, url)
finally:
config.clear()
config.update(original)
app.get('/', extra_environ={
'SCRIPT_NAME': ''
})


class TestHelpersRenderMarkdown(object):

Expand Down

0 comments on commit 87c6a4e

Please sign in to comment.