You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/06/08 01:42:47 UTC
[2/4] git commit: [#6276] use mock SMTP server instead of real one
during tests
[#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/1042586c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1042586c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1042586c
Branch: refs/heads/master
Commit: 1042586c55fb40587231154092704554d1d0a26e
Parents: 55b86eb
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Tue Jun 4 18:20:31 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Jun 7 23:42:12 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/1042586c/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: