~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/browser/tests/test_questionmessages.py

Merge db-devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from zope.security.proxy import removeSecurityProxy
10
10
 
11
11
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
12
 
from canonical.launchpad.testing.pages import find_tag_by_id
13
12
from canonical.testing.layers import DatabaseFunctionalLayer
 
13
from lp.coop.answersbugs.visibility import (
 
14
    TestHideMessageControlMixin,
 
15
    TestMessageVisibilityMixin,
 
16
    )
14
17
from lp.testing import (
15
18
    BrowserTestCase,
16
19
    person_logged_in,
17
20
    )
18
21
 
19
22
 
20
 
class TestQuestionCommentVisibility(BrowserTestCase):
 
23
class TestQuestionMessageVisibility(
 
24
        BrowserTestCase, TestMessageVisibilityMixin):
21
25
 
22
26
    layer = DatabaseFunctionalLayer
23
27
 
24
 
    def makeQuestionWithHiddenComment(self, questionbody=None):
 
28
    def makeHiddenMessage(self):
 
29
        """Required by the mixin."""
25
30
        administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
26
31
        with person_logged_in(administrator):
27
32
            question = self.factory.makeQuestion()
28
 
            comment = question.addComment(administrator, questionbody)
 
33
            comment = question.addComment(administrator, self.comment_text)
29
34
            removeSecurityProxy(comment).message.visible = False
30
35
        return question
31
36
 
32
 
    def test_admin_can_see_comments(self):
33
 
        comment_text = "You can't see me."
34
 
        question = self.makeQuestionWithHiddenComment(comment_text)
35
 
        administrator = self.factory.makeAdministrator()
36
 
        view = self.getViewBrowser(context=question, user=administrator)
37
 
        self.assertTrue(
38
 
           comment_text in view.contents,
39
 
           "Administrator cannot see the hidden comment.")
40
 
 
41
 
    def test_registry_can_see_comments(self):
42
 
        comment_text = "You can't see me."
43
 
        question = self.makeQuestionWithHiddenComment(comment_text)
44
 
        registry_expert = self.factory.makeRegistryExpert()
45
 
        view = self.getViewBrowser(context=question, user=registry_expert)
46
 
        self.assertTrue(
47
 
           comment_text in view.contents,
48
 
           "Registy member cannot see the hidden comment.")
49
 
 
50
 
    def test_anon_cannot_see_comments(self):
51
 
        comment_text = "You can't see me."
52
 
        question = self.makeQuestionWithHiddenComment(comment_text)
53
 
        view = self.getViewBrowser(context=question, no_login=True)
54
 
        self.assertFalse(
55
 
           comment_text in view.contents,
56
 
           "Anonymous person can see the hidden comment.")
57
 
 
58
 
    def test_random_cannot_see_comments(self):
59
 
        comment_text = "You can't see me."
60
 
        question = self.makeQuestionWithHiddenComment(comment_text)
61
 
        view = self.getViewBrowser(context=question)
62
 
        self.assertFalse(
63
 
           comment_text in view.contents,
64
 
           "Random user can see the hidden comment.")
65
 
 
66
 
 
67
 
class TestQuestionSpamControls(BrowserTestCase):
 
37
    def getView(self, context, user=None, no_login=False):
 
38
        """Required by the mixin."""
 
39
        view = self.getViewBrowser(
 
40
            context=context,
 
41
            user=user,
 
42
            no_login=no_login)
 
43
        return view
 
44
 
 
45
 
 
46
class TestHideQuestionMessageControls(
 
47
        BrowserTestCase, TestHideMessageControlMixin):
68
48
 
69
49
    layer = DatabaseFunctionalLayer
70
50
 
71
 
    def makeQuestionWithMessage(self):
 
51
    control_text = 'mark-spam-0'
 
52
 
 
53
    def getContext(self):
 
54
        """Required by the mixin."""
72
55
        administrator = getUtility(ILaunchpadCelebrities).admin.teamowner
73
56
        question = self.factory.makeQuestion()
74
57
        body = self.factory.getUniqueString()
76
59
            question.addComment(administrator, body)
77
60
        return question
78
61
 
79
 
    def test_admin_sees_spam_control(self):
80
 
        question = self.makeQuestionWithMessage()
81
 
        administrator = self.factory.makeAdministrator()
82
 
        view = self.getViewBrowser(context=question, user=administrator)
83
 
        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
84
 
        self.assertIsNot(None, spam_link)
85
 
 
86
 
    def test_registry_sees_spam_control(self):
87
 
        question = self.makeQuestionWithMessage()
88
 
        registry_expert = self.factory.makeRegistryExpert()
89
 
        view = self.getViewBrowser(context=question, user=registry_expert)
90
 
        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
91
 
        self.assertIsNot(None, spam_link)
92
 
 
93
 
    def test_anon_doesnt_see_spam_control(self):
94
 
        question = self.makeQuestionWithMessage()
95
 
        view = self.getViewBrowser(context=question, no_login=True)
96
 
        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
97
 
        self.assertIs(None, spam_link)
98
 
 
99
 
    def test_random_doesnt_see_spam_control(self):
100
 
        question = self.makeQuestionWithMessage()
101
 
        view = self.getViewBrowser(context=question)
102
 
        spam_link = find_tag_by_id(view.contents, 'mark-spam-1')
103
 
        self.assertIs(None, spam_link)
 
62
    def getView(self, context, user=None, no_login=False):
 
63
        """Required by the mixin."""
 
64
        view = self.getViewBrowser(
 
65
            context=context,
 
66
            user=user,
 
67
            no_login=no_login)
 
68
        return view