incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [22/27] git commit: [#6314] Refactored, added tests, and removed hard-coded nbhd from ShortUrl
Date Fri, 07 Jun 2013 23:42:17 GMT
[#6314] Refactored, added tests, and removed hard-coded nbhd from ShortUrl

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/577b65f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/577b65f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/577b65f8

Branch: refs/heads/db/6276
Commit: 577b65f853872fb6f85a16d5790ffb490032ff2c
Parents: 9ea4661
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Jun 7 17:19:18 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Jun 7 17:19:18 2013 +0000

----------------------------------------------------------------------
 Allura/development.ini                             |    2 +-
 Allura/test.ini                                    |    4 +-
 ForgeShortUrl/forgeshorturl/main.py                |   18 +-------
 ForgeShortUrl/forgeshorturl/model/shorturl.py      |   13 ++++--
 .../forgeshorturl/tests/functional/test.py         |   31 +++++++++++++++
 5 files changed, 46 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/577b65f8/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 0ddf539..646c468 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -250,7 +250,7 @@ auto_reload_templates = true
 # pip install -e git://github.com/brondsem/html2text.git#egg=html2text
 forgeblog.exfeed = false
 
-short_url.url_pattern = {base_url}p/{project}/{mount_point}/{short_name}
+short_url.url_pattern = {base_url}/{nbhd}/{project}/{mount_point}/{short_name}
 
 [app:tool_test]
 use = egg:Allura

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/577b65f8/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index cebbe80..f1bd5f2 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -37,7 +37,7 @@ port = 5000
 use = config:development.ini#tool_test
 db_prefix = test_
 
-base_url = http://localhost/
+base_url = http://localhost
 
 # Use test MongoDB DB server
 # ming.main.master = mongo://127.0.0.1:27018/allura
@@ -107,7 +107,7 @@ support_tool_choices = wiki tickets discussion
 
 disable_csrf_protection=1
 
-short_url.url_pattern = {base_url}p/{project}/{mount_point}/{short_name}
+short_url.url_pattern = {base_url}/{nbhd}/{project}/{mount_point}/{short_name}
 
 [app:main_without_authn]
 use = main

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/577b65f8/ForgeShortUrl/forgeshorturl/main.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/main.py b/ForgeShortUrl/forgeshorturl/main.py
index 8ecce61..d26c69e 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -154,11 +154,7 @@ class RootController(BaseController):
             'limit': limit,
             'pagenum': pagenum,
             'count': count,
-            'url_len': len(config['short_url.url_pattern'].format(
-                    base_url=config['base_url'],
-                    project=c.project.shortname,
-                    mount_point=c.app.config.options.mount_point,
-                    short_name='')),
+            'url_len': len(ShortUrl.build_short_url(c.app, short_name='')),
         }
 
     @expose('jinja:forgeshorturl:templates/search.html')
@@ -180,11 +176,7 @@ class RootController(BaseController):
         d = search_app(**search_params)
         d['search_comments_disable'] = True
         d['search_history_disable'] = True
-        d['url_len'] = len(config['short_url.url_pattern'].format(
-                base_url=config['base_url'],
-                project=c.project.shortname,
-                mount_point=c.app.config.options.mount_point,
-                short_name=''))
+        d['url_len'] = len(ShortUrl.build_short_url(c.app, short_name=''))
         return d
 
     @expose()
@@ -270,8 +262,4 @@ class ShortURLAdminController(DefaultAdminController):
             redirect(request.referer)
         return dict(
                 app=self.app,
-                url_len=len(config['short_url.url_pattern'].format(
-                    base_url=config['base_url'],
-                    project=c.project.shortname,
-                    mount_point=self.app.config.options.mount_point,
-                    short_name='')))
+                url_len=len(ShortUrl.build_short_url(c.app, short_name='')))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/577b65f8/ForgeShortUrl/forgeshorturl/model/shorturl.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/model/shorturl.py b/ForgeShortUrl/forgeshorturl/model/shorturl.py
index 8a7fce7..41617bd 100644
--- a/ForgeShortUrl/forgeshorturl/model/shorturl.py
+++ b/ForgeShortUrl/forgeshorturl/model/shorturl.py
@@ -71,9 +71,14 @@ class ShortUrl(M.Artifact):
     def url(self):
         return self.app.url + self.short_name
 
-    def short_url(self):
+    @classmethod
+    def build_short_url(cls, app, short_name):
         return config['short_url.url_pattern'].format(
                 base_url=config['base_url'],
-                project=self.app.project.shortname,
-                mount_point=self.app.config.options.mount_point,
-                short_name=self.short_name)
+                nbhd=app.project.neighborhood.url_prefix.strip('/'),
+                project=app.project.shortname,
+                mount_point=app.config.options.mount_point,
+                short_name=short_name)
+
+    def short_url(self):
+        return self.build_short_url(self.app, self.short_name)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/577b65f8/ForgeShortUrl/forgeshorturl/tests/functional/test.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/tests/functional/test.py b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
index 5d7f9d7..e162b38 100644
--- a/ForgeShortUrl/forgeshorturl/tests/functional/test.py
+++ b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
@@ -16,8 +16,11 @@
 #       under the License.
 
 from pylons import tmpl_context as c
+from tg import config
 from nose.tools import assert_equal
+import mock
 
+from allura.lib import helpers as h
 from allura.tests import decorators as td
 from alluratest.controller import TestController
 
@@ -107,3 +110,31 @@ class TestRootController(TestController):
                 extra_environ=dict(username='test-user'), status=403)
         self.app.post('/admin/url/remove', params=dict(shorturl='g'),
                 extra_environ=dict(username='test-user'), status=403)
+
+    def test_build_short_url(self):
+        with h.push_config(config, **{
+                'short_url.url_pattern': '{base_url}:{nbhd}:{project}:{mount_point}:{short_name}',
+                'base_url': 'b',
+            }):
+            nbhd = mock.Mock(url_prefix='/n/')
+            project = mock.Mock(shortname='p', neighborhood=nbhd)
+            app = mock.Mock(project=project)
+            app.config.options.mount_point = 'm'
+
+            url = ShortUrl.build_short_url(app, 's')
+
+            assert_equal(url, 'b:n:p:m:s')
+
+    def test_short_url(self):
+        response = self.app.get('/admin/url/add')
+        response.form['short_url'] = 'test'
+        response.form['full_url'] = 'http://www.google.com/'
+        response.form.submit()
+
+        surl = ShortUrl.query.get(short_name='test')
+
+        with h.push_config(config, **{
+                'short_url.url_pattern': '{base_url}:{nbhd}:{project}:{mount_point}:{short_name}',
+                'base_url': 'b',
+            }):
+            assert_equal(surl.short_url(), 'b:p:test:url:test')


Mime
View raw message