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 2018/01/02 20:53:16 UTC

allura git commit: Allow packages to have their own test.ini used automatically from their TestController tests

Repository: allura
Updated Branches:
  refs/heads/db/different_test.ini [created] 392c4819d


Allow packages to have their own test.ini used automatically from their TestController tests


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

Branch: refs/heads/db/different_test.ini
Commit: 392c4819de3e293132865249e1a07ead2ae358c5
Parents: fd8533e
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Jan 2 15:45:08 2018 -0500
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Jan 2 15:53:07 2018 -0500

----------------------------------------------------------------------
 AlluraTest/alluratest/controller.py | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/392c4819/AlluraTest/alluratest/controller.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/controller.py b/AlluraTest/alluratest/controller.py
index f479072..1f9ade5 100644
--- a/AlluraTest/alluratest/controller.py
+++ b/AlluraTest/alluratest/controller.py
@@ -52,15 +52,26 @@ DFL_APP_NAME = 'main'
 __test__ = False
 
 
-def get_config_file(config=None):
+def get_config_file(config=None, current_pkg=None):
     if not config:
         config = 'test.ini'
+    if not current_pkg:
+        current_pkg = 'allura'
 
-    try:
-        conf_dir = tg.config.here
-    except AttributeError:
+    conf_dir = pkg_resources.resource_filename(current_pkg, '..')
+    conf_file = os.path.join(conf_dir, config)
+
+    # split on "#" since it could be foo.ini#main
+    if not os.path.exists(conf_file.split('#')[0]) and current_pkg != 'allura':
+        # if there isn't a forgewiki/test.ini for example, then fall back to regular allura
         conf_dir = pkg_resources.resource_filename('allura', '..')
-    return os.path.join(conf_dir, config)
+        conf_file = os.path.join(conf_dir, config)
+
+    if not os.path.exists(conf_file.split('#')[0]):
+        raise EnvironmentError(u'Cannot find .ini config file {}'.format(conf_file))
+    else:
+        return conf_file
+
 
 
 def setup_config_test(config_file=None, force=False):
@@ -100,9 +111,9 @@ def setup_basic_test(config=None, app_name=DFL_APP_NAME):
 setup_basic_test.__test__ = False  # sometimes __test__ above isn't sufficient
 
 
-def setup_functional_test(config=None, app_name=DFL_APP_NAME):
+def setup_functional_test(config=None, app_name=DFL_APP_NAME, current_pkg=None):
     '''Create clean environment for running tests.  Also return WSGI test app'''
-    config = get_config_file(config)
+    config = get_config_file(config, current_pkg=current_pkg)
     setup_basic_test(config, app_name)
     conf_dir = tg.config.here
     wsgiapp = loadapp('config:%s#%s' % (config, app_name),
@@ -153,8 +164,9 @@ class TestController(object):
 
     def setUp(self):
         """Method called by nose before running each test"""
+        pkg = self.__module__.split('.')[0]
         self.app = ValidatingTestApp(
-            setup_functional_test(app_name=self.application_under_test))
+            setup_functional_test(app_name=self.application_under_test, current_pkg=pkg))
         self.app.extra_environ = {'REMOTE_ADDR': '127.0.0.1'}  # remote_addr needed by AntiSpam
         if self.validate_skip:
             self.app.validate_skip = self.validate_skip