~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/answers/tests/test_question_notifications.py

  • Committer: Curtis Hovey
  • Date: 2011-04-22 05:54:55 UTC
  • mto: (12906.3.2 question-recipients-0)
  • mto: This revision was merged to the branch mainline in revision 12914.
  • Revision ID: curtis.hovey@canonical.com-20110422055455-27ebmkof9axvuyf1
Always send notfications about added questions as though they come from the owner.
Process/users make questions for other users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
from zope.interface import implements
11
11
 
12
 
from lp.answers.notification import QuestionModifiedDefaultNotification
 
12
from lp.answers.notification import (
 
13
    QuestionAddedNotification,
 
14
    QuestionModifiedDefaultNotification,
 
15
    )
13
16
from lp.registry.interfaces.person import IPerson
14
17
 
15
18
 
35
38
    def __init__(self, id=1, title="Question title"):
36
39
        self.id = id
37
40
        self.title = title
 
41
        self.owner = FakeUser()
38
42
 
39
43
 
40
44
class StubQuestionMessage:
109
113
        self.assertEquals(
110
114
            'Re: [Question #1]: Message subject',
111
115
            self.notification.getSubject())
 
116
 
 
117
    def test_user_is_event_user(self):
 
118
        """The notification user is always the event user."""
 
119
        question = StubQuestion()
 
120
        event = FakeEvent()
 
121
        notification = TestQuestionModifiedNotification(question, event)
 
122
        self.assertEqual(event.user, notification.user)
 
123
        self.assertNotEqual(question.owner, notification.user)
 
124
 
 
125
 
 
126
class TestQuestionAddedNotification(QuestionAddedNotification):
 
127
    """A subclass that does not send emails."""
 
128
 
 
129
    def shouldNotify(self):
 
130
        return False
 
131
 
 
132
 
 
133
class QuestionCreatedTestCase(TestCase):
 
134
    """Test cases for mail notifications about created questions."""
 
135
 
 
136
    def test_user_is_question_owner(self):
 
137
        """The notification user is always the question owner."""
 
138
        question = StubQuestion()
 
139
        event = FakeEvent()
 
140
        notification = TestQuestionAddedNotification(question, event)
 
141
        self.assertEqual(question.owner, notification.user)
 
142
        self.assertNotEqual(event.user, notification.user)