allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [25/27] git commit: [#6276] use mock SMTP server instead of real one during tests
Date Fri, 07 Jun 2013 23:42:20 GMT
[#6276] use mock SMTP server instead of real one during tests


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

Branch: refs/heads/db/6276
Commit: 3ba5a1ab68f4ac59f4d1023ac9d1529ce867006b
Parents: afe5b38
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Tue Jun 4 18:20:31 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Jun 7 21:19:38 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/decorators.py |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3ba5a1ab/Allura/allura/tests/decorators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/decorators.py b/Allura/allura/tests/decorators.py
index eed0a65..745b008 100644
--- a/Allura/allura/tests/decorators.py
+++ b/Allura/allura/tests/decorators.py
@@ -16,12 +16,16 @@
 #       under the License.
 
 from functools import wraps
-
-from allura import model as M
+import contextlib
 
 from ming.orm.ormsession import ThreadLocalORMSession
-
 from pylons import tmpl_context as c
+from mock import patch
+import tg
+from paste.deploy.converters import asbool
+
+from allura import model as M
+
 
 def with_user_project(username):
     def _with_user_project(func):
@@ -40,6 +44,12 @@ def with_user_project(username):
         return wrapped
     return _with_user_project
 
+
+@contextlib.contextmanager
+def NullContextManager():
+    yield
+
+
 def with_tool(project_shortname, ep_name, mount_point=None, mount_label=None,
         ordinal=None, post_install_hook=None, username='test-admin',
         **override_options):
@@ -53,8 +63,14 @@ def with_tool(project_shortname, ep_name, mount_point=None, mount_label=None,
                 c.app = p.install_app(ep_name, mount_point, mount_label, ordinal, **override_options)
                 if post_install_hook:
                     post_install_hook(c.app)
-                while M.MonQTask.run_ready('setup'):
-                    pass
+
+                if asbool(tg.config.get('smtp.mock')):
+                    smtp_mock = patch('allura.lib.mail_util.smtplib.SMTP')
+                else:
+                    smtp_mock = NullContextManager()
+                with smtp_mock:
+                    while M.MonQTask.run_ready('setup'):
+                        pass
                 ThreadLocalORMSession.flush_all()
                 ThreadLocalORMSession.close_all()
             elif mount_point:


Mime
View raw message