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/08/21 22:13:06 UTC
[50/50] git commit: [#3154] add tests to make sure all bulk_exports
can run without context
[#3154] add tests to make sure all bulk_exports can run without context
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/9cbde4c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9cbde4c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9cbde4c3
Branch: refs/heads/db/3154b
Commit: 9cbde4c386517f943fed27c5871d5da28eacf0e2
Parents: a87503e
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Aug 21 18:29:50 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 21 18:29:50 2013 +0000
----------------------------------------------------------------------
ForgeBlog/forgeblog/tests/test_app.py | 32 ++++++++++++--------
.../forgediscussion/tests/test_app.py | 6 ++++
ForgeLink/forgelink/link_main.py | 15 +++++----
ForgeLink/forgelink/tests/test_app.py | 15 +++++----
ForgeWiki/forgewiki/tests/test_app.py | 5 +++
5 files changed, 48 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9cbde4c3/ForgeBlog/forgeblog/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/test_app.py b/ForgeBlog/forgeblog/tests/test_app.py
index 7427b9b..895bb06 100644
--- a/ForgeBlog/forgeblog/tests/test_app.py
+++ b/ForgeBlog/forgeblog/tests/test_app.py
@@ -19,7 +19,9 @@
import tempfile
import json
+
from nose.tools import assert_equal
+from pylons import tmpl_context as c
from allura import model as M
from allura.lib import helpers as h
@@ -36,21 +38,25 @@ class TestBulkExport(object):
@td.with_tool('test', 'Blog', 'blog')
def test_bulk_export(self):
+ # Clear out some context vars, to properly simulate how this is run from the export task
+ # Besides, it's better not to need c context vars
+ c.app = c.project = None
+
project = M.Project.query.get(shortname='test')
blog = project.app_instance('blog')
- h.set_context('test', 'blog', neighborhood='Projects')
- post = BM.BlogPost()
- post.title = 'Test title'
- post.text = 'test post'
- post.labels = ['the firstlabel', 'the second label']
- post.make_slug()
- post.commit()
- post.discussion_thread.add_post(text='test comment')
- post2 = BM.BlogPost()
- post2.title = 'Test2 title'
- post2.text = 'test2 post'
- post2.make_slug()
- post2.commit()
+ with h.push_context('test', 'blog', neighborhood='Projects'):
+ post = BM.BlogPost()
+ post.title = 'Test title'
+ post.text = 'test post'
+ post.labels = ['the firstlabel', 'the second label']
+ post.make_slug()
+ post.commit()
+ post.discussion_thread.add_post(text='test comment')
+ post2 = BM.BlogPost()
+ post2.title = 'Test2 title'
+ post2.text = 'test2 post'
+ post2.make_slug()
+ post2.commit()
f = tempfile.TemporaryFile()
blog.bulk_export(f)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9cbde4c3/ForgeDiscussion/forgediscussion/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/test_app.py b/ForgeDiscussion/forgediscussion/tests/test_app.py
index 07b65f4..3666821 100644
--- a/ForgeDiscussion/forgediscussion/tests/test_app.py
+++ b/ForgeDiscussion/forgediscussion/tests/test_app.py
@@ -21,7 +21,9 @@
import tempfile
import json
+
from nose.tools import assert_equal
+from pylons import tmpl_context as c
from allura import model as M
from forgediscussion.tests.functional.test_rest import TestDiscussionApiBase
@@ -30,6 +32,10 @@ from forgediscussion.tests.functional.test_rest import TestDiscussionApiBase
class TestBulkExport(TestDiscussionApiBase):
def test_bulk_export(self):
+ # Clear out some context vars, to properly simulate how this is run from the export task
+ # Besides, it's better not to need c context vars
+ c.app = c.project = None
+
project = M.Project.query.get(shortname='test')
discussion = project.app_instance('discussion')
f = tempfile.TemporaryFile()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9cbde4c3/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index 199304a..d37db1b 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -65,7 +65,7 @@ class ForgeLinkApp(Application):
Application.__init__(self, project, config)
self.root = RootController()
self.admin = LinkAdminController(self)
- self.api_root = RootRestController()
+ self.api_root = RootRestController(self)
@property
@h.exceptionless([], log)
@@ -96,7 +96,7 @@ class ForgeLinkApp(Application):
super(ForgeLinkApp, self).uninstall(project)
def bulk_export(self, f):
- json.dump(RootRestController().link_json(), f, cls=jsonify.GenericJSON, indent=2)
+ json.dump(RootRestController(self).link_json(), f, cls=jsonify.GenericJSON, indent=2)
class RootController(BaseController):
@@ -130,15 +130,18 @@ class LinkAdminController(DefaultAdminController):
class RootRestController(BaseController):
+ def __init__(self, app):
+ self.app = app
+
def _check_security(self):
- require_access(c.app, 'read')
+ require_access(self.app, 'read')
def link_json(self):
- return dict(url=c.app.config.options.get('url'))
+ return dict(url=self.app.config.options.get('url'))
@expose('json:')
def index(self, url='', **kw):
if (request.method == 'POST') and (url != ''):
- require_access(c.app, 'configure')
- c.app.config.options.url = url
+ require_access(self.app, 'configure')
+ self.app.config.options.url = url
return self.link_json()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9cbde4c3/ForgeLink/forgelink/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/test_app.py b/ForgeLink/forgelink/tests/test_app.py
index 3290aa2..8149815 100644
--- a/ForgeLink/forgelink/tests/test_app.py
+++ b/ForgeLink/forgelink/tests/test_app.py
@@ -19,10 +19,10 @@ import tempfile
import json
from nose.tools import assert_equal
+from pylons import tmpl_context as c
from allura.tests import decorators as td
from allura import model as M
-from allura.lib import helpers as h
from alluratest.controller import setup_basic_test
@@ -33,11 +33,14 @@ class TestBulkExport(object):
@td.with_link
def test_bulk_export(self):
- self.project = M.Project.query.get(shortname='test')
- self.link = self.project.app_instance('link')
- h.set_context(self.project._id, app_config_id=self.link.config._id)
- self.link.config.options['url'] = 'http://sf.net'
+ # Clear out some context vars, to properly simulate how this is run from the export task
+ # Besides, it's better not to need c context vars
+ c.app = c.project = None
+
+ project = M.Project.query.get(shortname='test')
+ link = project.app_instance('link')
+ link.config.options['url'] = 'http://sf.net'
f = tempfile.TemporaryFile()
- self.link.bulk_export(f)
+ link.bulk_export(f)
f.seek(0)
assert_equal(json.loads(f.read())['url'], 'http://sf.net')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9cbde4c3/ForgeWiki/forgewiki/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/test_app.py b/ForgeWiki/forgewiki/tests/test_app.py
index b6db6a2..103def4 100644
--- a/ForgeWiki/forgewiki/tests/test_app.py
+++ b/ForgeWiki/forgewiki/tests/test_app.py
@@ -21,6 +21,7 @@ import json
import operator
from nose.tools import assert_equal
+from pylons import tmpl_context as c
from allura import model as M
from allura.tests import decorators as td
@@ -57,6 +58,10 @@ class TestBulkExport(object):
page.commit()
def test_bulk_export(self):
+ # Clear out some context vars, to properly simulate how this is run from the export task
+ # Besides, it's better not to need c context vars
+ c.app = c.project = None
+
f = tempfile.TemporaryFile()
self.wiki.bulk_export(f)
f.seek(0)