incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [17/50] git commit: [#5571] ticket:354 More test for spam checking
Date Fri, 24 May 2013 17:04:53 GMT
[#5571] ticket:354 More test for spam checking


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

Branch: refs/heads/db/6255
Commit: 639c292bca560e1b0af684235a1954193a0e5246
Parents: 5b7cbaa
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu May 16 10:19:16 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed May 22 20:54:26 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_discussion.py |   49 +++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/639c292b/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 6b1cca3..774a864 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -30,6 +30,7 @@ from pylons import request, response
 from nose.tools import assert_raises, assert_equals, with_setup
 import mock
 from mock import patch
+from nose.tools import assert_equal
 
 from ming.orm import session, ThreadLocalORMSession
 from webob import Request, Response, exc
@@ -378,3 +379,51 @@ def test_is_spam(role):
         post = mock.Mock()
         assert t.is_spam(post), t.is_spam(post)
         assert spam_checker.check.call_count == 1, spam_checker.call_count
+
+
+@with_setup(setUp, tearDown)
+@mock.patch('allura.controllers.discuss.g.spam_checker')
+def test_not_spam_and_has_unmoderated_post_permission(spam_checker):
+    spam_checker.check.return_value = False
+    d = M.Discussion(shortname='test', name='test')
+    t = M.Thread(discussion_id=d._id, subject='Test Thread')
+    role = M.ProjectRole.by_name('*anonymous')._id
+    post_permission = M.ACE.allow(role, 'post')
+    unmoderated_post_permission = M.ACE.allow(role, 'unmoderated_post')
+    t.acl.append(post_permission)
+    t.acl.append(unmoderated_post_permission)
+    with h.push_config(c, user=M.User.anonymous()):
+        post = t.post('Hey')
+    assert_equal(post.status, 'ok')
+
+
+@with_setup(setUp, tearDown)
+@mock.patch('allura.controllers.discuss.g.spam_checker')
+def test_not_spam_but_has_no_unmoderated_post_permission(spam_checker):
+    spam_checker.check.return_value = False
+    d = M.Discussion(shortname='test', name='test')
+    t = M.Thread(discussion_id=d._id, subject='Test Thread')
+    role = M.ProjectRole.by_name('*anonymous')._id
+    post_permission = M.ACE.allow(role, 'post')
+    t.acl.append(post_permission)
+    with h.push_config(c, user=M.User.anonymous()):
+        post = t.post('Hey')
+    assert_equal(post.status, 'pending')
+
+
+@with_setup(setUp, tearDown)
+@mock.patch('allura.controllers.discuss.g.spam_checker')
+@mock.patch.object(M.Thread, 'notify_moderators')
+def test_spam_and_has_unmoderated_post_permission(spam_checker, notify_moderators):
+    spam_checker.check.return_value = True
+    d = M.Discussion(shortname='test', name='test')
+    t = M.Thread(discussion_id=d._id, subject='Test Thread')
+    role = M.ProjectRole.by_name('*anonymous')._id
+    post_permission = M.ACE.allow(role, 'post')
+    unmoderated_post_permission = M.ACE.allow(role, 'unmoderated_post')
+    t.acl.append(post_permission)
+    t.acl.append(unmoderated_post_permission)
+    with h.push_config(c, user=M.User.anonymous()):
+        post = t.post('Hey')
+    assert_equal(post.status, 'pending')
+    notify_moderators.assert_called_once()


Mime
View raw message