You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2017/10/30 14:42:58 UTC
[3/6] allura git commit: Replace g.url usage with h.absurl;
have it always use config.base_url so it works fine behind proxies,
etc
Replace g.url usage with h.absurl; have it always use config.base_url so it works fine behind proxies, etc
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1c57792a
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1c57792a
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1c57792a
Branch: refs/heads/master
Commit: 1c57792ad2bd22f5f3b30e2fc76cfc66997a054a
Parents: fac64c6
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Aug 22 22:53:29 2017 -0400
Committer: Kenton Taylor <kt...@slashdotmedia.com>
Committed: Mon Oct 30 10:42:32 2017 -0400
----------------------------------------------------------------------
Allura/allura/lib/app_globals.py | 7 -------
Allura/allura/lib/helpers.py | 7 +------
Allura/allura/model/auth.py | 3 ++-
Allura/allura/templates/oauth_authorize_ok.html | 4 ++--
Allura/allura/tests/functional/test_auth.py | 4 ++--
Allura/allura/tests/functional/test_user_profile.py | 4 ++--
Allura/allura/tests/scripts/test_create_sitemap_files.py | 6 +++---
Allura/allura/tests/test_globals.py | 5 +----
Allura/allura/tests/test_helpers.py | 9 +--------
Allura/test.ini | 2 ++
ForgeGit/forgegit/tests/model/test_repository.py | 8 ++++----
ForgeSVN/forgesvn/tests/model/test_repository.py | 6 +++---
ForgeTracker/forgetracker/tests/functional/test_root.py | 2 +-
13 files changed, 24 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 883634d..1f49315 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -544,13 +544,6 @@ class Globals(object):
'h.set_context() is preferred over this method'
c.app = c.project.app_instance(name)
- def url(self, base, **kw):
- params = urlencode(kw)
- if params:
- return '%s%s?%s' % (request.host_url, base, params)
- else:
- return '%s%s' % (request.host_url, base)
-
def postload_contents(self):
text = '''
'''
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index c4116da..de9273a 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -455,12 +455,7 @@ def absurl(url):
return None
if '://' in url:
return url
- try:
- # try request first, so we can get proper http/https value
- host = request.host_url
- except TypeError:
- # for tests, etc
- host = tg.config['base_url'].rstrip('/')
+ host = tg.config['base_url'].rstrip('/')
return host + url
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 69a3bd7..780e8dd 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -206,7 +206,8 @@ please visit the following URL:
%s
''' % (self.email,
self.claimed_by_user(include_pending=True).username,
- g.url('/auth/verify_addr', a=self.nonce))
+ h.absurl('/auth/verify_addr?a={}'.format(h.urlquote(self.nonce))),
+ )
log.info('Verification email:\n%s', text)
allura.tasks.mail_tasks.sendsimplemail.post(
fromaddr=g.noreply,
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/templates/oauth_authorize_ok.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/oauth_authorize_ok.html b/Allura/allura/templates/oauth_authorize_ok.html
index 02f1de0..a727b72 100644
--- a/Allura/allura/templates/oauth_authorize_ok.html
+++ b/Allura/allura/templates/oauth_authorize_ok.html
@@ -26,8 +26,8 @@
{% block content %}
<p>You have authorized {{ rtok.consumer_token.name }} access to your account. If you wish
to revoke this access at any time, please visit
- <a href="{{g.url('/auth/preferences/') }}">user preferences</a>
+ <a href="/auth/preferences">user preferences</a>
and click 'revoke access'.</p>
<h2>PIN: {{ rtok.validation_pin }}</h2>
-<a href="{{g.url('/auth/preferences/')}}">Return to preferences</a>
+<a href="/auth/preferences/">Return to preferences</a>
{% endblock %}
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 7def429..780e1cf 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -928,9 +928,9 @@ class TestAuth(TestController):
r = self.app.get('/auth/logout')
r = self.app.post('/auth/do_login', antispam=True, params=dict(
username='test-user', password='foo',
- return_to='http://localhost:8080/foo',
+ return_to='http://localhost/foo',
_session_id=self.app.cookies['_session_id']))
- assert_equal(r.location, 'http://localhost:8080/foo')
+ assert_equal(r.location, 'http://localhost/foo')
r = self.app.get('/auth/logout')
r = self.app.post('/auth/do_login', antispam=True, params=dict(
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index 5655b4b..2707260 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -103,7 +103,7 @@ class TestUserProfile(TestController):
sendsimplemail.post.assert_called_once_with(
cc=User.by_username('test-admin').get_pref('email_address'),
- text=u'test message\n\n---\n\nThis message was sent to you via the Allura web mail form. You may reply to this message directly, or send a message to Test Admin at http://localhost:8080/u/test-admin/profile/send_message\n',
+ text=u'test message\n\n---\n\nThis message was sent to you via the Allura web mail form. You may reply to this message directly, or send a message to Test Admin at http://localhost/u/test-admin/profile/send_message\n',
toaddr=User.by_username('test-user').get_pref('email_address'),
fromaddr=User.by_username('test-admin').get_pref('email_address'),
reply_to=User.by_username('test-admin').get_pref('email_address'),
@@ -116,7 +116,7 @@ class TestUserProfile(TestController):
sendsimplemail.post.assert_called_once_with(
cc=None,
- text=u'test message\n\n---\n\nThis message was sent to you via the Allura web mail form. You may reply to this message directly, or send a message to Test Admin at http://localhost:8080/u/test-admin/profile/send_message\n',
+ text=u'test message\n\n---\n\nThis message was sent to you via the Allura web mail form. You may reply to this message directly, or send a message to Test Admin at http://localhost/u/test-admin/profile/send_message\n',
toaddr=User.by_username('test-user').get_pref('email_address'),
fromaddr=User.by_username('test-admin').get_pref('email_address'),
reply_to=User.by_username('test-admin').get_pref('email_address'),
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/tests/scripts/test_create_sitemap_files.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/scripts/test_create_sitemap_files.py b/Allura/allura/tests/scripts/test_create_sitemap_files.py
index 240d7ba..df00e98 100644
--- a/Allura/allura/tests/scripts/test_create_sitemap_files.py
+++ b/Allura/allura/tests/scripts/test_create_sitemap_files.py
@@ -50,9 +50,9 @@ class TestCreateSitemapFiles(object):
xml_index = ET.parse(os.path.join(tmpdir.path, 'sitemap.xml'))
ns = {'ns0': 'http://www.sitemaps.org/schemas/sitemap/0.9'}
locs = [loc.text for loc in xml_index.findall('ns0:sitemap/ns0:loc', ns)]
- assert_in('http://localhost:8080/allura_sitemap/sitemap-0.xml', locs)
+ assert_in('http://localhost/allura_sitemap/sitemap-0.xml', locs)
xml_0 = ET.parse(os.path.join(tmpdir.path, 'sitemap-0.xml'))
urls = [loc.text for loc in xml_0.findall('ns0:url/ns0:loc', ns)]
- assert_in('http://localhost:8080/p/wiki/', urls)
- assert_in('http://localhost:8080/p/test/sub1/', urls)
+ assert_in('http://localhost/p/wiki/', urls)
+ assert_in('http://localhost/p/test/sub1/', urls)
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index ec87f16..a3dd87d 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -74,9 +74,6 @@ def test_app_globals():
with h.push_context('test', 'wiki', neighborhood='Projects'):
assert g.app_static(
'css/wiki.css') == '/nf/_static_/wiki/css/wiki.css', g.app_static('css/wiki.css')
- assert g.url(
- '/foo', a='foo bar') == 'http://localhost/foo?a=foo+bar', g.url('/foo', a='foo bar')
- assert g.url('/foo') == 'http://localhost/foo', g.url('/foo')
@with_setup(setUp)
@@ -443,7 +440,7 @@ Some text in a regular paragraph
for i in range(10):
print i
''')
- assert_in('http://localhost:8080/', g.forge_markdown(email=True).convert('[Home]'))
+ assert_in('http://localhost/', g.forge_markdown(email=True).convert('[Home]'))
assert 'class="codehilite"' in g.markdown.convert('''
~~~~
def foo(): pass
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 8435a12..fbc9813 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -491,17 +491,10 @@ class TestUrlOpen(TestCase):
self.assertEqual(urlopen.call_count, 1)
-def test_absurl_no_request():
+def test_absurl():
assert_equals(h.absurl('/p/test/foobar'), 'http://localhost/p/test/foobar')
-@patch.object(h, 'request',
- new=Request.blank('/p/test/foobar', base_url='https://www.mysite.com/p/test/foobar'))
-def test_absurl_with_request():
- assert_equals(h.absurl('/p/test/foobar'),
- 'https://www.mysite.com/p/test/foobar')
-
-
def test_daterange():
assert_equals(
list(h.daterange(datetime(2013, 1, 1), datetime(2013, 1, 4))),
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index 4381cb6..8c7abb1 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -53,6 +53,8 @@ debug = false
; not necessary anyway
stats.sample_rate = 0
+base_url = http://localhost
+
; specify these without any build_key being included
ew.script_name = /nf/_ew_/
ew.url_base = /nf/_ew_/
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 88d0455..bc89736 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -213,7 +213,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f:
c = f.read()
self.assertIn(
- 'curl -s http://localhost:8080/auth/refresh_repo/p/test/src-git/\n', c)
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
self.assertIn('exec $DIR/post-receive-user\n', c)
shutil.rmtree(dirname)
@@ -247,7 +247,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f:
c = f.read()
self.assertIn(
- 'curl -s http://localhost:8080/auth/refresh_repo/p/test/src-git/\n', c)
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
self.assertIn('exec $DIR/post-receive-user\n', c)
shutil.rmtree(dirname)
@@ -469,12 +469,12 @@ http://example.com/
By Dave Brondsema''', text_body)
# these bracketed links could look like HTML tags, ensure they don't get removed
- assert_in('further messages, please visit <http://localhost:8080/auth/subscriptions/>', text_body)
+ assert_in('further messages, please visit <http://localhost/auth/subscriptions/>', text_body)
# limited markdown handling of commit messages (see `markdown_commit`)
# and HTML escaped
assert_in('''<hr/>
-<div class="markdown_content"><p>Add foo.txt. Commit ref <a class="alink" href="http://localhost:8080/p/test/weird-chars/ci/616d24f8dd4e95cadd8e93df5061f09855d1a066/">[616d24f8dd4e95cadd8e93df5061f09855d1a066]</a> *bold* <b>bold</b></p>
+<div class="markdown_content"><p>Add foo.txt. Commit ref <a class="alink" href="http://localhost/p/test/weird-chars/ci/616d24f8dd4e95cadd8e93df5061f09855d1a066/">[616d24f8dd4e95cadd8e93df5061f09855d1a066]</a> *bold* <b>bold</b></p>
<p>* one<br/>
* two<br/>
* three</p>
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 38dc5fe..024c585 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -166,7 +166,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
with open(os.path.join(g.tmpdir, 'testsvn/hooks/post-commit')) as f:
hook_data = f.read()
self.assertIn(
- 'curl -s http://localhost:8080/auth/refresh_repo/p/test/src/\n',
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src/\n',
hook_data)
self.assertIn('exec $DIR/post-commit-user "$@"\n', hook_data)
@@ -218,7 +218,7 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
with open(os.path.join(g.tmpdir, 'testsvn/hooks/post-commit')) as f:
c = f.read()
self.assertIn(
- 'curl -s http://localhost:8080/auth/refresh_repo/p/test/src/\n', c)
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src/\n', c)
self.assertIn('exec $DIR/post-commit-user "$@"\n', c)
repo.refresh(notify=False)
@@ -877,7 +877,7 @@ class TestRepo(_TestWithRepo):
for n in notifications:
if '100 new commits' in n.subject:
assert_in(u'By Test Committer on 10/08/2010 15:32', n.text)
- assert_in(u'http://localhost:8080/ci/foo99/', n.text)
+ assert_in(u'http://localhost/ci/foo99/', n.text)
break
else:
assert False, 'Did not find notification'
http://git-wip-us.apache.org/repos/asf/allura/blob/1c57792a/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 8113d02..40afa8c 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2396,7 +2396,7 @@ class TestFunctionalController(TrackerTestController):
# check subject
assert 'Subject: [test:bugs] #1 test <h2> ticket' in body
# check html, need tags escaped
- assert_in('<p><strong> <a class="alink" href="http://localhost:8080/p/test/bugs/1/">[bugs:#1]</a>'
+ assert_in('<p><strong> <a class="alink" href="http://localhost/p/test/bugs/1/">[bugs:#1]</a>'
' test <h2> ticket</strong></p>',
body)
# check plaintext (ok to have "html" tags)