You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/03/26 16:54:50 UTC

[3/3] git commit: [#6007] Better installation of subproject in bootstrap. Don't leave a c.user/project

[#6007] Better installation of subproject in bootstrap.  Don't leave a c.user/project

Default subproject is now named, not first tool in test project,
and with a wiki instead of no tools.

This also stops leaving a c.user and c.project around.  So many tests
are updated to explicitly set up a c.user or c.project if they were
relying on that.


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

Branch: refs/heads/db/6007
Commit: df1e4dfdfe7713ed240e188339d12e4e4249aa59
Parents: 4c3f669
Author: Dave Brondsema <db...@geek.net>
Authored: Mon Mar 25 14:39:49 2013 -0700
Committer: Dave Brondsema <db...@geek.net>
Committed: Tue Mar 26 11:54:38 2013 -0400

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                        |    9 ++-
 Allura/allura/model/discuss.py                     |    2 +-
 Allura/allura/model/project.py                     |    4 +-
 Allura/allura/tests/functional/test_discuss.py     |    3 +-
 .../allura/tests/functional/test_neighborhood.py   |    4 +-
 Allura/allura/tests/functional/test_root.py        |   10 ++-
 Allura/allura/tests/model/test_project.py          |   39 ++++++------
 Allura/allura/tests/test_globals.py                |   50 +++++++-------
 Allura/allura/tests/test_mail_util.py              |    2 +-
 Allura/allura/tests/unit/test_post_model.py        |    8 ++-
 Allura/allura/websetup/bootstrap.py                |   25 +++++---
 11 files changed, 89 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index a3d01b8..f27b8bd 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -548,18 +548,21 @@ class ProjectRegistrationProvider(object):
             g.post_event('project_created')
         return p
 
-    def register_subproject(self, project, name, user, install_apps):
+    def register_subproject(self, project, name, user, install_apps, project_name=None):
         from allura import model as M
         assert h.re_path_portion.match(name), 'Invalid subproject shortname'
         shortname = project.shortname + '/' + name
+        ordinal = int(project.ordered_mounts(include_hidden=True)[-1]['ordinal']) + 1
         sp = M.Project(
             parent_id=project._id,
             neighborhood_id=project.neighborhood_id,
             shortname=shortname,
-            name=name,
+            name=project_name or name,
             database_uri=project.database_uri,
             last_updated = datetime.utcnow(),
-            is_root=False)
+            is_root=False,
+            ordinal=ordinal,
+        )
         with h.push_config(c, project=sp):
             M.AppConfig.query.remove(dict(project_id=c.project._id))
             if install_apps:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 9d26242..58f301b 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -571,7 +571,7 @@ class Post(Message, VersionedArtifact, ActivityObject):
         self.status = 'ok'
         author = self.author()
         security.simple_grant(
-            self.acl, author.project_role()._id, 'moderate')
+            self.acl, author.project_role(self.project)._id, 'moderate')
         self.commit()
         if (c.app.config.options.get('PostingPolicy') == 'ApproveOnceModerated'
             and author._id != None):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 9f07f67..900b4e3 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -592,11 +592,11 @@ class Project(MappedClass, ActivityNode, ActivityObject):
             if ac.tool_name == tool_type:
                 return ac
 
-    def new_subproject(self, name, install_apps=True, user=None):
+    def new_subproject(self, name, install_apps=True, user=None, project_name=None):
         if not h.re_path_portion.match(name):
             raise exceptions.ToolError, 'Mount point "%s" is invalid' % name
         provider = plugin.ProjectRegistrationProvider.get()
-        return provider.register_subproject(self, name, user or c.user, install_apps)
+        return provider.register_subproject(self, name, user or c.user, install_apps, project_name=project_name)
 
     def ordered_mounts(self, include_hidden=False):
         '''Returns an array of a projects mounts (tools and sub-projects) in

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index 596cf60..de25eee 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -108,7 +108,8 @@ class TestDiscuss(TestController):
         # set wiki page private
         from forgewiki.model import Page
         page = Page.query.get(_id=thread.ref.artifact._id)  # need to look up the page directly, so ming is aware of our change
-        role_admin = M.ProjectRole.by_name('Admin')._id
+        project = M.Project.query.get(shortname='test')
+        role_admin = M.ProjectRole.by_name('Admin', project)._id
         page.acl = [
             M.ACE.allow(role_admin, M.ALL_PERMISSIONS),
             M.DENY_ALL,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 02e3760..cf28ff7 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -784,10 +784,12 @@ class TestNeighborhood(TestController):
                           extra_environ=dict(username='root'))
 
     def test_add_a_project_link(self):
+        from pylons import tmpl_context as c
         # Install Home tool for all neighborhoods
         for nb in M.Neighborhood.query.find().all():
             p = nb.neighborhood_project
-            p.install_app('home', 'home', 'Home', ordinal=0)
+            with h.push_config(c, user=M.User.query.get()):
+                p.install_app('home', 'home', 'Home', ordinal=0)
         r = self.app.get('/p/')
         assert 'Add a Project' in r
         r = self.app.get('/u/', extra_environ=dict(username='test-user'))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index 3f4e7dd..b5ff8b3 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -11,6 +11,7 @@ Please read http://pythonpaste.org/webtest/ for more information.
 
 """
 from tg import config
+from pylons import tmpl_context as c
 from nose.tools import assert_equal
 from ming.orm.ormsession import ThreadLocalORMSession
 
@@ -62,7 +63,7 @@ class TestRootController(TestController):
     def test_project_browse(self):
         com_cat = M.ProjectCategory.query.find(dict(label='Communications')).first()
         fax_cat = M.ProjectCategory.query.find(dict(label='Fax')).first()
-        M.Project.query.find(dict(name='adobe-1')).first().category_id = com_cat._id
+        M.Project.query.find(dict(shortname='adobe-1')).first().category_id = com_cat._id
         response = self.app.get('/browse')
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1
@@ -94,7 +95,8 @@ class TestRootController(TestController):
         # Install home app
         nb = M.Neighborhood.query.get(name='Adobe')
         p = nb.neighborhood_project
-        p.install_app('home', 'home', 'Home', ordinal=0)
+        with push_config(c, user=M.User.query.get(username='test-admin')):
+            p.install_app('home', 'home', 'Home', ordinal=0)
 
         response = self.app.get('/adobe/')
         projects = response.html.findAll('div',{'class':'border card'})
@@ -107,8 +109,8 @@ class TestRootController(TestController):
     def test_neighborhood_project_browse(self):
         com_cat = M.ProjectCategory.query.find(dict(label='Communications')).first()
         fax_cat = M.ProjectCategory.query.find(dict(label='Fax')).first()
-        M.Project.query.find(dict(name='adobe-1')).first().category_id = com_cat._id
-        M.Project.query.find(dict(name='adobe-2')).first().category_id = fax_cat._id
+        M.Project.query.find(dict(shortname='adobe-1')).first().category_id = com_cat._id
+        M.Project.query.find(dict(shortname='adobe-2')).first().category_id = fax_cat._id
         response = self.app.get('/adobe/browse')
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/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 5277d34..08dda33 100644
--- a/Allura/allura/tests/model/test_project.py
+++ b/Allura/allura/tests/model/test_project.py
@@ -2,7 +2,7 @@
 """
 Model tests for project
 """
-from nose.tools import with_setup
+from nose.tools import with_setup, assert_equals, assert_in
 from pylons import tmpl_context as c
 from ming.orm.ormsession import ThreadLocalORMSession
 
@@ -22,23 +22,22 @@ def setUp():
 def setup_with_tools():
     setup_global_objects()
 
-@with_setup(setUp)
 def test_project():
-    assert type(c.project.sidebar_menu()) == list
-    assert c.project.script_name in c.project.url()
+    assert_equals(type(c.project.sidebar_menu()), list)
+    assert_in(c.project.script_name, c.project.url())
     old_proj = c.project
     h.set_context('test/sub1', neighborhood='Projects')
-    assert type(c.project.sidebar_menu()) == list
-    assert type(c.project.sitemap()) == list
-    assert c.project.sitemap()[0].label == 'Admin'
-    assert old_proj in list(c.project.parent_iter())
+    assert_equals(type(c.project.sidebar_menu()), list)
+    assert_equals(type(c.project.sitemap()), list)
+    assert_equals(c.project.sitemap()[1].label, 'Admin')
+    assert_in(old_proj, list(c.project.parent_iter()))
     h.set_context('test', 'wiki', neighborhood='Projects')
     adobe_nbhd = M.Neighborhood.query.get(name='Adobe')
     p = M.Project.query.get(shortname='adobe-1', neighborhood_id=adobe_nbhd._id)
     # assert 'http' in p.url() # We moved adobe into /adobe/, not http://adobe....
-    assert p.script_name in p.url()
-    assert c.project.shortname == 'test'
-    assert '<p>' in c.project.description_html
+    assert_in(p.script_name, p.url())
+    assert_equals(c.project.shortname, 'test')
+    assert_in('<p>', c.project.description_html)
     c.project.uninstall_app('hello-test-mount-point')
     ThreadLocalORMSession.flush_all()
 
@@ -65,7 +64,8 @@ def test_project():
     c.app.config.breadcrumbs()
 
 def test_subproject():
-    sp = c.project.new_subproject('test-project-nose')
+    project = M.Project.query.get(shortname='test')
+    sp = project.new_subproject('test-project-nose')
     spp = sp.new_subproject('spp')
     ThreadLocalORMSession.flush_all()
     sp.delete()
@@ -75,13 +75,14 @@ def test_subproject():
 def test_anchored_tools():
     c.project.neighborhood.anchored_tools = 'wiki:Wiki, tickets:Ticket'
     c.project.install_app = MagicMock()
-    assert c.project.sitemap()[0].label == 'Wiki'
-    assert c.project.install_app.call_args[0][0] == 'tickets'
-    assert c.project.ordered_mounts()[0]['ac'].tool_name == 'Wiki'
+    assert_equals(c.project.sitemap()[0].label, 'Wiki')
+    assert_equals(c.project.install_app.call_args[0][0], 'tickets')
+    assert_equals(c.project.ordered_mounts()[0]['ac'].tool_name, 'Wiki')
 
 
 def test_set_ordinal_to_admin_tool():
-    assert c.project.sitemap()
-    assert c.project.app_config('admin').options.ordinal == 100
-
-
+    with h.push_config(c,
+                       user=M.User.anonymous(),
+                       project=M.Project.query.get(shortname='test')):
+        assert c.project.sitemap()
+        assert c.project.app_config('admin').options.ordinal == 100

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 493787c..25dd021 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -82,44 +82,44 @@ def test_macros():
 
     with h.push_context(p_nbhd.neighborhood_project._id):
         r = g.markdown_wiki.convert('[[projects]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects labels=root]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' not in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' not in r, r
         r = g.markdown_wiki.convert('[[projects labels=sub1]]')
-        assert '<img alt="test Logo"' not in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' not in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects labels=test]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects labels=test,root]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' not in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' not in r, r
         r = g.markdown_wiki.convert('[[projects labels=test,sub1]]')
-        assert '<img alt="test Logo"' not in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' not in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects labels=root|sub1]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects labels=test,root|root,sub1]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' not in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' not in r, r
         r = g.markdown_wiki.convert('[[projects labels=test,root|test,sub1]]')
-        assert '<img alt="test Logo"' in r, r
-        assert '<img alt="sub1 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' in r, r
+        assert '<img alt="A Subproject Logo"' in r, r
         r = g.markdown_wiki.convert('[[projects show_total=True sort=random]]')
         assert '<p class="macro_projects_total">3 Projects</p>' in r, r
         r = g.markdown_wiki.convert('[[projects show_total=True private=True sort=random]]')
         assert '<p class="macro_projects_total">1 Projects</p>' in r, r
-        assert '<img alt="test2 Logo"' in r, r
-        assert '<img alt="test Logo"' not in r, r
-        assert '<img alt="sub1 Logo"' not in r, r
+        assert '<img alt="Test 2 Logo"' in r, r
+        assert '<img alt="Test Project Logo"' not in r, r
+        assert '<img alt="A Subproject Logo"' not in r, r
 
         r = g.markdown_wiki.convert('[[projects show_proj_icon=True]]')
-        assert '<img alt="test Logo"' in r
+        assert '<img alt="Test Project Logo"' in r
         r = g.markdown_wiki.convert('[[projects show_proj_icon=False]]')
-        assert '<img alt="test Logo"' not in r
+        assert '<img alt="Test Project Logo"' not in r
 
     c.project = curr_project
     r = g.markdown_wiki.convert('[[download_button]]')
@@ -352,7 +352,7 @@ def test_filtering():
     # set up for test
     from random import choice
     random_trove = choice(M.TroveCategory.query.find().all())
-    test_project = M.Project.query.get(name='test')
+    test_project = M.Project.query.get(shortname='test')
     test_project_troves = getattr(test_project, 'trove_' + random_trove.type)
     test_project_troves.append(random_trove._id)
     ThreadLocalORMSession.flush_all()
@@ -425,7 +425,7 @@ def test_hideawards_macro():
     award.full = u'Award full'
     award.created_by_neighborhood_id = p_nbhd._id
 
-    project = M.Project.query.get(neighborhood_id=p_nbhd._id, name=u'test')
+    project = M.Project.query.get(neighborhood_id=p_nbhd._id, shortname=u'test')
 
     award_grant = M.AwardGrant(award=award,
                                granted_by_neighborhood=p_nbhd,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/test_mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_mail_util.py b/Allura/allura/tests/test_mail_util.py
index 82b1366..090d710 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -46,7 +46,7 @@ class TestReactor(unittest.TestCase):
     def test_parse_address_good(self):
         topic, project, app = parse_address('foo@wiki.test.p' + config.common_suffix)
         assert_equal(topic, 'foo')
-        assert_equal(project.name, 'test')
+        assert_equal(project.shortname, 'test')
         assert_equal(app.__class__.__name__, 'ForgeWikiApp')
 
     def test_unicode_simple_message(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/tests/unit/test_post_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_post_model.py b/Allura/allura/tests/unit/test_post_model.py
index 9cec1c9..525a9ce 100644
--- a/Allura/allura/tests/unit/test_post_model.py
+++ b/Allura/allura/tests/unit/test_post_model.py
@@ -1,3 +1,7 @@
+from pylons import tmpl_context as c
+
+from allura.lib import helpers as h
+from allura import model as M
 from allura.tests.unit import WithDatabase
 from allura.tests.unit import patches
 from allura.tests.unit.factories import create_post
@@ -15,6 +19,6 @@ class TestPostModel(WithDatabase):
         assert self.post.status == 'pending'
 
     def test_that_it_can_be_approved(self):
-        self.post.approve()
+        with h.push_config(c, user=M.User()):
+            self.post.approve()
         assert self.post.status == 'ok'
-

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/df1e4dfd/Allura/allura/websetup/bootstrap.py
----------------------------------------------------------------------
diff --git a/Allura/allura/websetup/bootstrap.py b/Allura/allura/websetup/bootstrap.py
index 6143210..6157496 100644
--- a/Allura/allura/websetup/bootstrap.py
+++ b/Allura/allura/websetup/bootstrap.py
@@ -17,6 +17,7 @@ from ming.orm.ormsession import ThreadLocalORMSession
 
 import allura
 from allura.lib import plugin
+from allura.lib import helpers as h
 from allura import model as M
 from allura.websetup import schema
 from allura.command import EnsureIndexCommand
@@ -69,7 +70,6 @@ def bootstrap(command, conf, vars):
         log.error('Error clearing solr index')
     if asbool(conf.get('cache_test_data')):
         if restore_test_data():
-            from allura.lib import helpers as h
             h.set_context('test', neighborhood='Projects')
             return
     log.info('Initializing search')
@@ -190,10 +190,8 @@ def bootstrap(command, conf, vars):
         # TODO: Hope that Ming can be improved to at least avoid stuff below
         sess.flush(x)
 
-    c.project = p0
-    c.user = u_admin
-    p1 = p0.new_subproject('sub1')
     ThreadLocalORMSession.flush_all()
+
     if asbool(conf.get('load_test_data')):
         if asbool(conf.get('cache_test_data')):
             cache_test_data()
@@ -201,10 +199,21 @@ def bootstrap(command, conf, vars):
         # regular first-time setup
         p0.add_user(u_admin, ['Admin'])
         log.info('Registering initial apps')
-        for ep_name, app in g.entry_points['tool'].iteritems():
-            if not app.installable:
-                continue
-            p0.install_app(ep_name)
+        with h.push_config(c, user=u_admin):
+            for ep_name, app in g.entry_points['tool'].iteritems():
+                if not app.installable:
+                    continue
+                p0.install_app(ep_name)
+
+    # reload our p0 project so that p0.app_configs is accurate with all the newly installed apps
+    ThreadLocalORMSession.flush_all()
+    ThreadLocalORMSession.close_all()
+    p0 = M.Project.query.get(_id=p0._id)
+    sub = p0.new_subproject('sub1', project_name='A Subproject')
+    with h.push_config(c, user=u_admin):
+        sub.install_app('wiki')
+
+
     ThreadLocalORMSession.flush_all()
     ThreadLocalORMSession.close_all()