allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [13/46] allura git commit: [#6057] ticket:788 Add/fix tests
Date Mon, 15 Jun 2015 12:27:32 GMT
[#6057] ticket:788 Add/fix tests


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

Branch: refs/heads/hs/7873
Commit: a0b3aed29a4a7e9657838f584f49e668f54bfd41
Parents: 1ac85b8
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Jun 5 12:19:37 2015 +0000
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Tue Jun 9 21:06:06 2015 +0000

----------------------------------------------------------------------
 Allura/allura/app.py                            |  1 +
 Allura/allura/model/project.py                  |  6 +--
 Allura/allura/tests/functional/test_admin.py    | 10 ++++
 Allura/allura/tests/model/test_project.py       | 17 ++++++
 Allura/allura/tests/test_app.py                 | 35 +++++++++++++
 .../forgelink/tests/functional/test_root.py     | 54 ++++++++++++++++++++
 6 files changed, 120 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index a9d3ff0..58aa49d 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -76,6 +76,7 @@ class ConfigOption(object):
     def validate(self, value):
         if self.validator:
             return self.validator.to_python(value)
+        return value
 
 
 class SitemapEntry(object):

http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index e280d63..2ad3be4 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -742,10 +742,10 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         options['mount_label'] = mount_label or App.default_mount_label or mount_point
         options['ordinal'] = int(ordinal)
         options_on_install = {o.name: o for o in App.options_on_install()}
-        for o, v in override_options.iteritems():
+        for o, val in override_options.iteritems():
             if o in options_on_install:
-                v = self._validate_tool_option(options_on_install[o], v)
-            options[o] = v
+                val = self._validate_tool_option(options_on_install[o], val)
+            options[o] = val
         cfg = AppConfig(
             project_id=self._id,
             tool_name=ep_name.lower(),

http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 819a92a..d239591 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -358,6 +358,16 @@ class TestProjectAdmin(TestController):
             assert 'error' in self.webflash(r)
             assert 'limit exceeded' in self.webflash(r)
 
+    def test_tool_options_on_install(self):
+        self.app.get('/admin/options_on_install', status=404)
+        self.app.get('/admin/options_on_install?tool_name=fake', status=404)
+        r = self.app.get('/admin/options_on_install?tool_name=tickets')
+        assert_equals(r.body, '')
+        opts = ['EnableVoting']
+        with mock.patch.object(ForgeTrackerApp, 'config_on_install', new=opts):
+            r = self.app.get('/admin/options_on_install?tool_name=tickets')
+            assert_in(u'<input id="EnableVoting" name="EnableVoting" type="checkbox">',
r)
+
     def test_grouping_threshold(self):
         r = self.app.get('/admin/tools')
         grouping_threshold = r.html.find(

http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/Allura/allura/tests/model/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_project.py b/Allura/allura/tests/model/test_project.py
index d8a754f..2fe3dc8 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -24,6 +24,7 @@ from nose import with_setup
 from nose.tools import assert_equals, assert_in
 from pylons import tmpl_context as c
 from ming.orm.ormsession import ThreadLocalORMSession
+from formencode import validators as fev
 
 from allura import model as M
 from allura.lib import helpers as h
@@ -96,6 +97,22 @@ def test_project():
     c.app.config.breadcrumbs()
 
 
+@with_setup(setUp)
+def test_install_app_validates_options():
+    from forgetracker.tracker_main import ForgeTrackerApp
+    name = 'TicketMonitoringEmail'
+    opt = [o for o in ForgeTrackerApp.config_options if o.name == name][0]
+    opt.validator = fev.Email(not_empty=True)
+    with patch.object(ForgeTrackerApp, 'config_on_install', new=[opt.name]):
+        for v in [None, '', 'bad@email']:
+            with td.raises(ToolError):
+                c.project.install_app('Tickets', 'test-tickets', **{name: v})
+            assert_equals(c.project.app_instance('test-tickets'), None)
+        c.project.install_app('Tickets', 'test-tickets', **{name: 'e@e.com'})
+        app = c.project.app_instance('test-tickets')
+        assert_equals(app.config.options[name], 'e@e.com')
+
+
 def test_project_index():
     project, idx = c.project, c.project.index()
     assert 'id' in idx

http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/Allura/allura/tests/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index a31f112..2642a95 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -18,6 +18,8 @@
 from pylons import tmpl_context as c
 import mock
 from ming.base import Object
+from nose.tools import assert_equal, assert_raises
+from formencode import validators as fev
 
 from alluratest.controller import setup_unit_test
 from allura import app
@@ -52,6 +54,39 @@ def test_config_options():
     assert options[1].default == 'MyTestValue'
 
 
+def test_config_option_without_validator():
+    opt = app.ConfigOption('test1', str, None)
+    assert_equal(opt.validate(None), None)
+    assert_equal(opt.validate(''), '')
+    assert_equal(opt.validate('val'), 'val')
+
+
+def test_config_option_with_validator():
+    v = fev.NotEmpty()
+    opt = app.ConfigOption('test1', str, None, validator=v)
+    assert_equal(opt.validate('val'), 'val')
+    assert_raises(fev.Invalid, opt.validate, None)
+    assert_raises(fev.Invalid, opt.validate, '')
+
+
+def test_options_on_install_default():
+    a = app.Application(c.project, c.app.config)
+    assert_equal(a.options_on_install(), [])
+
+
+def test_options_on_install():
+    opts = [app.ConfigOption('url', str, None),
+            app.ConfigOption('private', bool, None)]
+    class TestApp(app.Application):
+        config_options = app.Application.config_options + opts + [
+            app.ConfigOption('not_on_install', str, None),
+        ]
+        config_on_install = ['url', 'private']
+
+    a = TestApp(c.project, c.app.config)
+    assert_equal(a.options_on_install(), opts)
+
+
 def test_sitemap():
     sm = app.SitemapEntry('test', '')[
         app.SitemapEntry('a', 'a/'),

http://git-wip-us.apache.org/repos/asf/allura/blob/a0b3aed2/ForgeLink/forgelink/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/functional/test_root.py b/ForgeLink/forgelink/tests/functional/test_root.py
index 021b91f..1372be8 100644
--- a/ForgeLink/forgelink/tests/functional/test_root.py
+++ b/ForgeLink/forgelink/tests/functional/test_root.py
@@ -15,6 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+import json
 from nose.tools import assert_equal
 
 from allura import model as M
@@ -61,3 +62,56 @@ class TestRootController(TestController):
         response = self.app.get('/link/help')
         # HACK: support for remote redirects is limited in follow()
         assert 'http://www.google.de/search?q=help' in response
+
+
+class TestConfigOptions(TestController):
+
+    @property
+    def project(self):
+        return M.Project.query.get(shortname='test')
+
+    def assert_url(self, mount_point, val):
+        app = self.project.app_instance(mount_point)
+        assert_equal(app.config.options['url'], val)
+
+    def test_sets_url_on_install(self):
+        r = self.app.post('/p/test/admin/update_mounts', params={
+            'new.install': 'install',
+            'new.ep_name': 'link',
+            'new.ordinal': '1',
+            'new.mount_point': 'link-google',
+            'new.mount_label': 'Google',
+            'url': 'google.com'})
+        self.assert_url('link-google', 'http://google.com')
+
+    def test_validates_url_on_install(self):
+        r = self.app.post('/p/test/admin/update_mounts', params={
+            'new.install': 'install',
+            'new.ep_name': 'link',
+            'new.ordinal': '1',
+            'new.mount_point': 'link-google',
+            'new.mount_label': 'Google',
+            'url': 'invalid url'})
+        flash = json.loads(self.webflash(r))
+        assert_equal(flash['status'], 'error')
+        assert_equal(flash['message'], 'ToolError: url: That is not a valid URL')
+        app = self.project.app_instance('link-google')
+        assert_equal(app, None)
+
+    @td.with_link
+    def test_sets_url_on_config(self):
+        self.assert_url('link', None)
+        params = {'url': 'https://allura.apache.org'}
+        r = self.app.post('/p/test/admin/link/configure', params=params)
+        assert_equal(self.webflash(r), '')
+        self.assert_url('link', 'https://allura.apache.org')
+
+    @td.with_link
+    def test_validates_url_on_config(self):
+        self.assert_url('link', None)
+        params = {'url': 'invalid link'}
+        r = self.app.post('/p/test/admin/link/configure', params=params)
+        flash = json.loads(self.webflash(r))
+        assert_equal(flash['status'], 'error')
+        assert_equal(flash['message'], 'url: That is not a valid URL')
+        self.assert_url('link', None)


Mime
View raw message