9
9
from zope.security.proxy import removeSecurityProxy
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,
14
17
from lp.testing import (
20
class TestQuestionCommentVisibility(BrowserTestCase):
23
class TestQuestionMessageVisibility(
24
BrowserTestCase, TestMessageVisibilityMixin):
22
26
layer = DatabaseFunctionalLayer
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
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)
38
comment_text in view.contents,
39
"Administrator cannot see the hidden comment.")
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)
47
comment_text in view.contents,
48
"Registy member cannot see the hidden comment.")
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)
55
comment_text in view.contents,
56
"Anonymous person can see the hidden comment.")
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)
63
comment_text in view.contents,
64
"Random user can see the hidden comment.")
67
class TestQuestionSpamControls(BrowserTestCase):
37
def getView(self, context, user=None, no_login=False):
38
"""Required by the mixin."""
39
view = self.getViewBrowser(
46
class TestHideQuestionMessageControls(
47
BrowserTestCase, TestHideMessageControlMixin):
69
49
layer = DatabaseFunctionalLayer
71
def makeQuestionWithMessage(self):
51
control_text = 'mark-spam-0'
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)
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)
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)
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)
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(