incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [8/9] git commit: [#6276] use mock SMTP server instead of real one during tests
Date Thu, 06 Jun 2013 17:33:01 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/eda24bf0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/eda24bf0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/eda24bf0

Branch: refs/heads/db/6276
Commit: eda24bf070c99eb31810904bd52f4117a8195aad
Parents: 2e53530
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Tue Jun 4 18:20:31 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Jun 5 13:31:08 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/eda24bf0/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