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 2012/12/13 17:10:53 UTC

[2/2] git commit: [#5455] Fix akismet logging

[#5455] Fix akismet logging


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

Branch: refs/heads/master
Commit: 424999c33873781aafae610530e7ad3b94bd2ff4
Parents: 78888e7
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Dec 12 23:01:16 2012 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Wed Dec 12 23:01:16 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/spam/akismetservice.py |    3 ++-
 Allura/allura/tests/unit/test_spam.py    |   24 +++++++++++++-----------
 2 files changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/424999c3/Allura/allura/lib/spam/akismetservice.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/spam/akismetservice.py b/Allura/allura/lib/spam/akismetservice.py
index d5768a0..344a7ad 100644
--- a/Allura/allura/lib/spam/akismetservice.py
+++ b/Allura/allura/lib/spam/akismetservice.py
@@ -10,6 +10,7 @@ log = logging.getLogger(__name__)
 class Akismet(akismet.Akismet):
     def check(self, text, artifact=None, user=None, content_type='comment', **kw):
         log_msg = text
+        kw['comment_content'] = text
         kw['comment_type'] = content_type
         if artifact:
             kw['permalink'] = artifact.url()
@@ -18,7 +19,7 @@ class Akismet(akismet.Akismet):
         if user:
             kw['comment_author'] = user.display_name or user.username
             kw['comment_author_email'] = user.email_addresses[0] if user.email_addresses else ''
-        kw['user_ip'] = request.environ['REMOTE_ADDR']
+        kw['user_ip'] = request.environ['HTTP_X_REMOTE_ADDR']
         kw['user_agent'] = request.environ['HTTP_USER_AGENT']
         kw['referrer'] = request.environ['HTTP_REFERER']
         res = self.comment_check(text, data=kw, build_data=False)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/424999c3/Allura/allura/tests/unit/test_spam.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_spam.py b/Allura/allura/tests/unit/test_spam.py
index 1b169a9..ea87b43 100644
--- a/Allura/allura/tests/unit/test_spam.py
+++ b/Allura/allura/tests/unit/test_spam.py
@@ -16,10 +16,12 @@ class TestAkismet(unittest.TestCase):
         self.fake_user = mock.Mock(display_name='Some User',
                 email_addresses=['user@domain'])
         self.fake_environ = dict(
-            REMOTE_ADDR='some ip',
+            HTTP_X_REMOTE_ADDR='some ip',
             HTTP_USER_AGENT='some browser',
             HTTP_REFERER='some url')
+        self.content = 'spam text'
         self.expected_data = dict(
+            comment_content=self.content,
             comment_type='comment',
             user_ip='some ip',
             user_agent='some browser',
@@ -30,8 +32,8 @@ class TestAkismet(unittest.TestCase):
     def test_check(self, request, c):
         request.environ = self.fake_environ
         c.user = None
-        self.akismet.check('spam text')
-        self.akismet.comment_check.assert_called_once_with('spam text',
+        self.akismet.check(self.content)
+        self.akismet.comment_check.assert_called_once_with(self.content,
                 data=self.expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetservice.c')
@@ -39,9 +41,9 @@ class TestAkismet(unittest.TestCase):
     def test_check_with_explicit_content_type(self, request, c):
         request.environ = self.fake_environ
         c.user = None
-        self.akismet.check('spam text', content_type='some content type')
+        self.akismet.check(self.content, content_type='some content type')
         self.expected_data['comment_type'] = 'some content type'
-        self.akismet.comment_check.assert_called_once_with('spam text',
+        self.akismet.comment_check.assert_called_once_with(self.content,
                 data=self.expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetservice.c')
@@ -49,10 +51,10 @@ class TestAkismet(unittest.TestCase):
     def test_check_with_artifact(self, request, c):
         request.environ = self.fake_environ
         c.user = None
-        self.akismet.check('spam text', artifact=self.fake_artifact)
+        self.akismet.check(self.content, artifact=self.fake_artifact)
         expected_data = self.expected_data
         expected_data['permalink'] = 'artifact url'
-        self.akismet.comment_check.assert_called_once_with('spam text',
+        self.akismet.comment_check.assert_called_once_with(self.content,
                 data=expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetservice.c')
@@ -60,11 +62,11 @@ class TestAkismet(unittest.TestCase):
     def test_check_with_user(self, request, c):
         request.environ = self.fake_environ
         c.user = None
-        self.akismet.check('spam text', user=self.fake_user)
+        self.akismet.check(self.content, user=self.fake_user)
         expected_data = self.expected_data
         expected_data.update(comment_author='Some User',
                 comment_author_email='user@domain')
-        self.akismet.comment_check.assert_called_once_with('spam text',
+        self.akismet.comment_check.assert_called_once_with(self.content,
                 data=expected_data, build_data=False)
 
     @mock.patch('allura.lib.spam.akismetservice.c')
@@ -72,9 +74,9 @@ class TestAkismet(unittest.TestCase):
     def test_check_with_implicit_user(self, request, c):
         request.environ = self.fake_environ
         c.user = self.fake_user
-        self.akismet.check('spam text')
+        self.akismet.check(self.content)
         expected_data = self.expected_data
         expected_data.update(comment_author='Some User',
                 comment_author_email='user@domain')
-        self.akismet.comment_check.assert_called_once_with('spam text',
+        self.akismet.comment_check.assert_called_once_with(self.content,
                 data=expected_data, build_data=False)