[#3154] add tests to make sure all bulk_exports can run without context
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 @@
@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)
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 @@
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()
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 @@
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 @@
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 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()
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 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 @@
@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')
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 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 @@
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)