1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Test for emails sent after bug task modification."""
6
from unittest import TestLoader
10
from zope.component import getUtility
11
from zope.interface import providedBy
12
from zope.event import notify
14
from canonical.testing import DatabaseFunctionalLayer
15
from canonical.launchpad.database import BugNotification
16
from canonical.launchpad.webapp.interfaces import ILaunchBag
19
from lp.bugs.interfaces.bugtask import BugTaskStatus
20
from lp.bugs.scripts.bugnotification import construct_email_notifications
21
from lp.testing import TestCaseWithFactory
23
from lazr.lifecycle.event import ObjectModifiedEvent
24
from lazr.lifecycle.snapshot import Snapshot
27
class TestModificationNotification(TestCaseWithFactory):
28
"""Test email notifications when a bug task is modified."""
30
layer = DatabaseFunctionalLayer
33
# Run the tests as a logged-in user.
34
super(TestModificationNotification, self).setUp(
35
user='test@canonical.com')
36
self.user = getUtility(ILaunchBag).user
37
self.product = self.factory.makeProduct(owner=self.user)
38
self.bug = self.factory.makeBug(product=self.product)
39
self.bug_task = self.bug.getBugTask(self.product)
40
self.bug_task_before_modification = Snapshot(self.bug_task,
41
providing=providedBy(self.bug_task))
43
def test_for_bug_modifier_header(self):
44
"""Test X-Launchpad-Bug-Modifier appears when a bug is modified."""
45
self.bug_task.transitionToStatus(BugTaskStatus.CONFIRMED, self.user)
46
notify(ObjectModifiedEvent(
47
self.bug_task, self.bug_task_before_modification,
48
['status'], user=self.user))
50
latest_notification = BugNotification.selectFirst(orderBy='-id')
51
notifications, messages = construct_email_notifications(
52
[latest_notification])
53
self.assertEqual(len(notifications), 1,
54
'email notification not created')
55
headers = [msg['X-Launchpad-Bug-Modifier'] for msg in messages]
56
self.assertEqual(len(headers), len(messages))
60
return TestLoader().loadTestsFromName(__name__)