← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/spam-tech-debt into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/spam-tech-debt into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/spam-tech-debt/+merge/60794

Summary
=======
Previous work for adding message hiding utilities to questions and bugs introduced a lot of repeated code in testing. This branch removes that to a mixin in answersbugs.

Preimplemenation
================
Spoke with Curtis Hovey.

Implementation
==============
lib/lp/coop/answersbugs/__init__.py
-----------------------------------
Updated docs.

lib/lp/coop/answersbugs/visibility.py
-------------------------------------
Created test mixins for visibility access and spam control access.

lib/lp/answers/browser/tests/test_questionmessages.py
lib/lp/bugs/browser/tests/test_bugcomment.py
--------------------------------------------
Updated tests.

Tests
=====
bin/test -vvc -t test_bugcomment -t test_questionmessages

QA
==
qa-untestable

Lint
====
= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/answers/browser/tests/test_questionmessages.py
  lib/lp/bugs/browser/tests/test_bugcomment.py
  lib/lp/coop/answersbugs/__init__.py
  lib/lp/coop/answersbugs/visibility.py

-- 
https://code.launchpad.net/~jcsackett/launchpad/spam-tech-debt/+merge/60794
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/spam-tech-debt into lp:launchpad.
=== modified file 'lib/lp/answers/browser/tests/test_questionmessages.py'
--- lib/lp/answers/browser/tests/test_questionmessages.py	2011-05-06 15:00:46 +0000
+++ lib/lp/answers/browser/tests/test_questionmessages.py	2011-05-12 14:11:40 +0000
@@ -9,66 +9,44 @@
 from zope.security.proxy import removeSecurityProxy
 
 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
-from canonical.launchpad.testing.pages import find_tag_by_id
 from canonical.testing.layers import DatabaseFunctionalLayer
+from lp.coop.answersbugs.visibility import (
+    TestHideMessageControlMixin,
+    TestMessageVisibilityMixin,
+    )
 from lp.testing import (
     BrowserTestCase,
     person_logged_in,
     )
 
 
-class TestQuestionCommentVisibility(BrowserTestCase):
+class TestQuestionMessageVisibility(
+        BrowserTestCase, TestMessageVisibilityMixin):
 
     layer = DatabaseFunctionalLayer
 
-    def makeQuestionWithHiddenComment(self, questionbody=None):
+    def makeHiddenMessage(self):
         administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
         with person_logged_in(administrator):
             question = self.factory.makeQuestion()
-            comment = question.addComment(administrator, questionbody)
+            comment = question.addComment(administrator, self.comment_text)
             removeSecurityProxy(comment).message.visible = False
         return question
 
-    def test_admin_can_see_comments(self):
-        comment_text = "You can't see me."
-        question = self.makeQuestionWithHiddenComment(comment_text)
-        administrator = self.factory.makeAdministrator()
-        view = self.getViewBrowser(context=question, user=administrator)
-        self.assertTrue(
-           comment_text in view.contents,
-           "Administrator cannot see the hidden comment.")
-
-    def test_registry_can_see_comments(self):
-        comment_text = "You can't see me."
-        question = self.makeQuestionWithHiddenComment(comment_text)
-        registry_expert = self.factory.makeRegistryExpert()
-        view = self.getViewBrowser(context=question, user=registry_expert)
-        self.assertTrue(
-           comment_text in view.contents,
-           "Registy member cannot see the hidden comment.")
-
-    def test_anon_cannot_see_comments(self):
-        comment_text = "You can't see me."
-        question = self.makeQuestionWithHiddenComment(comment_text)
-        view = self.getViewBrowser(context=question, no_login=True)
-        self.assertFalse(
-           comment_text in view.contents,
-           "Anonymous person can see the hidden comment.")
-
-    def test_random_cannot_see_comments(self):
-        comment_text = "You can't see me."
-        question = self.makeQuestionWithHiddenComment(comment_text)
-        view = self.getViewBrowser(context=question)
-        self.assertFalse(
-           comment_text in view.contents,
-           "Random user can see the hidden comment.")
-
-
-class TestQuestionSpamControls(BrowserTestCase):
+    def getView(self, context, user=None, no_login=False):
+        view = self.getViewBrowser(
+            context=context,
+            user=user,
+            no_login=no_login)
+        return view
+
+
+class TestHideQuestionMessageControls(
+        BrowserTestCase, TestHideMessageControlMixin):
 
     layer = DatabaseFunctionalLayer
 
-    def makeQuestionWithMessage(self):
+    def getContext(self):
         administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
         question = self.factory.makeQuestion()
         body = self.factory.getUniqueString()
@@ -76,28 +54,9 @@
             question.addComment(administrator, body)
         return question
 
-    def test_admin_sees_spam_control(self):
-        question = self.makeQuestionWithMessage()
-        administrator = self.factory.makeAdministrator()
-        view = self.getViewBrowser(context=question, user=administrator)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIsNot(None, spam_link)
-
-    def test_registry_sees_spam_control(self):
-        question = self.makeQuestionWithMessage()
-        registry_expert = self.factory.makeRegistryExpert()
-        view = self.getViewBrowser(context=question, user=registry_expert)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIsNot(None, spam_link)
-
-    def test_anon_doesnt_see_spam_control(self):
-        question = self.makeQuestionWithMessage()
-        view = self.getViewBrowser(context=question, no_login=True)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIs(None, spam_link)
-
-    def test_random_doesnt_see_spam_control(self):
-        question = self.makeQuestionWithMessage()
-        view = self.getViewBrowser(context=question)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIs(None, spam_link)
+    def getView(self, context, user=None, no_login=False):
+        view = self.getViewBrowser(
+            context=context,
+            user=user,
+            no_login=no_login)
+        return view

=== modified file 'lib/lp/bugs/browser/tests/test_bugcomment.py'
--- lib/lp/bugs/browser/tests/test_bugcomment.py	2011-05-10 16:16:21 +0000
+++ lib/lp/bugs/browser/tests/test_bugcomment.py	2011-05-12 14:11:40 +0000
@@ -15,12 +15,16 @@
 from zope.component import getUtility
 
 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
-from canonical.launchpad.testing.pages import find_tag_by_id
 from canonical.testing.layers import DatabaseFunctionalLayer
 from lp.bugs.browser.bugcomment import group_comments_with_activity
+from lp.coop.answersbugs.visibility import (
+    TestHideMessageControlMixin,
+    TestMessageVisibilityMixin,
+    )
 from lp.testing import (
     BrowserTestCase,
     person_logged_in,
+    celebrity_logged_in,
     TestCase,
     )
 
@@ -188,88 +192,42 @@
         self.assertEqual([activity3], comment2.activity)
 
 
-class TestBugCommentVisibility(BrowserTestCase):
+class TestBugCommentVisibility(
+        BrowserTestCase, TestMessageVisibilityMixin):
 
     layer = DatabaseFunctionalLayer
 
-    def makeBugWithHiddenComment(self, bugbody=None):
-        administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
-        bug = self.factory.makeBug()
-        with person_logged_in(administrator):
-            comment = self.factory.makeBugComment(bug=bug, body=bugbody)
+    def makeHiddenMessage(self):
+        with celebrity_logged_in('admin'):
+            bug = self.factory.makeBug()
+            comment = self.factory.makeBugComment(
+                    bug=bug, body=self.comment_text)
             comment.visible = False
         return bug
 
-    def test_admin_can_see_comments(self):
-        comment_text = "You can't see me."
-        bug = self.makeBugWithHiddenComment(comment_text)
-        admin = self.factory.makeAdministrator()
-        view = self.getViewBrowser(
-            context=bug.default_bugtask, user=admin)
-        self.assertTrue(
-           comment_text in view.contents,
-           "Administrator cannot see the hidden comment.")
-
-    def test_registry_can_see_comments(self):
-        comment_text = "You can't see me."
-        bug = self.makeBugWithHiddenComment(comment_text)
-        registry_expert = self.factory.makeRegistryExpert()
-        view = self.getViewBrowser(
-            context=bug.default_bugtask, user=registry_expert)
-        self.assertTrue(
-           comment_text in view.contents,
-           "Registy member cannot see the hidden comment.")
-
-    def test_anon_cannot_see_comments(self):
-        comment_text = "You can't see me."
-        bug = self.makeBugWithHiddenComment(comment_text)
-        view = self.getViewBrowser(context=bug.default_bugtask, no_login=True)
-        self.assertFalse(
-           comment_text in view.contents,
-           "Anonymous person can see the hidden comment.")
-
-    def test_random_cannot_see_comments(self):
-        comment_text = "You can't see me."
-        bug = self.makeBugWithHiddenComment(comment_text)
-        view = self.getViewBrowser(context=bug.default_bugtask)
-        self.assertFalse(
-           comment_text in view.contents,
-           "Random user can see the hidden comment.")
-
-
-class TestBugSpamControls(BrowserTestCase):
+    def getView(self, context, user=None, no_login=False):
+        view = self.getViewBrowser(
+            context=context.default_bugtask,
+            user=user,
+            no_login=no_login)
+        return view
+
+
+class TestBugHideCommentControls(
+        BrowserTestCase, TestHideMessageControlMixin):
 
     layer = DatabaseFunctionalLayer
 
-    def makeBugWithComment(self, bugbody=None):
+    def getContext(self):
         administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
         bug = self.factory.makeBug()
         with person_logged_in(administrator):
-            self.factory.makeBugComment(bug=bug, body=bugbody)
+            self.factory.makeBugComment(bug=bug)
         return bug
 
-    def test_admin_sees_spam_control(self):
-        bug = self.makeBugWithComment()
-        administrator = self.factory.makeAdministrator()
-        view = self.getViewBrowser(context=bug, user=administrator)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIsNot(None, spam_link)
-
-    def test_registry_sees_spam_control(self):
-        bug = self.makeBugWithComment()
-        registry_expert = self.factory.makeRegistryExpert()
-        view = self.getViewBrowser(context=bug, user=registry_expert)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIsNot(None, spam_link)
-
-    def test_anon_doesnt_see_spam_control(self):
-        bug = self.makeBugWithComment()
-        view = self.getViewBrowser(context=bug, no_login=True)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIs(None, spam_link)
-
-    def test_random_doesnt_see_spam_control(self):
-        bug = self.makeBugWithComment()
-        view = self.getViewBrowser(context=bug)
-        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
-        self.assertIs(None, spam_link)
+    def getView(self, context, user=None, no_login=False):
+        view = self.getViewBrowser(
+            context=context.default_bugtask,
+            user=user,
+            no_login=no_login)
+        return view

=== modified file 'lib/lp/coop/answersbugs/__init__.py'
--- lib/lp/coop/answersbugs/__init__.py	2009-06-25 04:06:00 +0000
+++ lib/lp/coop/answersbugs/__init__.py	2011-05-12 14:11:40 +0000
@@ -4,5 +4,5 @@
 """The Answers - Bugs Collaboration Package
 
 This package contains the code that allows bugs and questions to be linked
-together.
+together, as well as code common to the bugs and answers.
 """

=== added file 'lib/lp/coop/answersbugs/visibility.py'
--- lib/lp/coop/answersbugs/visibility.py	1970-01-01 00:00:00 +0000
+++ lib/lp/coop/answersbugs/visibility.py	2011-05-12 14:11:40 +0000
@@ -0,0 +1,82 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the bugcomment module."""
+
+__metaclass__ = type
+
+__all__ = [
+    'TestMessageVisibilityMixin',
+    'TestHideMessageControlMixin',
+    ]
+
+
+from canonical.launchpad.testing.pages import find_tag_by_id
+
+
+class TestMessageVisibilityMixin:
+
+    comment_text = "You can't see me."
+
+    def makeHiddenMessage(self):
+        pass
+
+    def getView(self, context, user=None, no_login=False):
+        pass
+
+    def test_admin_can_see_comments(self):
+        context = self.makeHiddenMessage()
+        admin = self.factory.makeAdministrator()
+        view = self.getView(context=context, user=admin)
+        self.assertIn(self.comment_text, view.contents)
+
+    def test_registry_can_see_comments(self):
+        context = self.makeHiddenMessage()
+        registry_expert = self.factory.makeRegistryExpert()
+        view = self.getView(context=context, user=registry_expert)
+        self.assertIn(self.comment_text, view.contents)
+
+    def test_anon_cannot_see_comments(self):
+        context = self.makeHiddenMessage()
+        view = self.getView(context=context, no_login=True)
+        self.assertNotIn(self.comment_text, view.contents)
+
+    def test_random_cannot_see_comments(self):
+        context = self.makeHiddenMessage()
+        view = self.getView(context=context)
+        self.assertNotIn(self.comment_text, view.contents)
+
+
+class TestHideMessageControlMixin:
+
+    def getContext(self):
+        pass
+
+    def getView(self, context, user=None, no_login=False):
+        pass
+
+    def test_admin_sees_hide_control(self):
+        context = self.getContext()
+        administrator = self.factory.makeAdministrator()
+        view = self.getView(context=context, user=administrator)
+        hide_link = find_tag_by_id(view.contents, 'mark-spam-1')
+        self.assertIsNot(None, hide_link)
+
+    def test_registry_sees_hide_control(self):
+        context = self.getContext()
+        registry_expert = self.factory.makeRegistryExpert()
+        view = self.getView(context=context, user=registry_expert)
+        hide_link = find_tag_by_id(view.contents, 'mark-spam-1')
+        self.assertIsNot(None, hide_link)
+
+    def test_anon_doesnt_see_hide_control(self):
+        context = self.getContext()
+        view = self.getView(context=context, no_login=True)
+        hide_link = find_tag_by_id(view.contents, 'mark-spam-1')
+        self.assertIs(None, hide_link)
+
+    def test_random_doesnt_see_hide_control(self):
+        context = self.getContext()
+        view = self.getView(context=context)
+        hide_link = find_tag_by_id(view.contents, 'mark-spam-1')
+        self.assertIs(None, hide_link)