19
19
from canonical.config import config
20
20
from canonical.database.sqlbase import commit
21
21
from canonical.launchpad.ftests import import_secret_test_key
22
from canonical.launchpad.interfaces.emailaddress import EmailAddressStatus
22
23
from canonical.launchpad.webapp.authorization import LaunchpadSecurityPolicy
23
24
from canonical.testing.layers import (
24
25
LaunchpadFunctionalLayer,
111
112
'affects malone',
115
def test_mailToHelpFromNonActiveUser(self):
116
"""Mail from people without a preferred email get a help message."""
117
self.factory.makePerson(
119
email_address_status=EmailAddressStatus.NEW)
120
message = self.factory.makeSignedMessage(email_address='non@eg.dom')
121
handler = MaloneHandler()
122
response = handler.extractAndAuthenticateCommands(
123
message, 'help@bugs.launchpad.net')
124
mail_handled, add_comment_to_bug, commands = response
125
self.assertEquals(mail_handled, True)
126
emails = self.getSentMail()
127
self.assertEquals(1, len(emails))
128
self.assertEquals(['non@eg.dom'], emails[0][1])
130
'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])
114
132
def test_mailToHelpFromUnknownUser(self):
115
133
"""Mail from people of no account to help@ is simply dropped.
117
message = self.factory.makeSignedMessage()
135
message = self.factory.makeSignedMessage(
136
email_address='unregistered@eg.dom')
118
137
handler = MaloneHandler()
119
138
mail_handled, add_comment_to_bug, commands = \
120
139
handler.extractAndAuthenticateCommands(message,
125
144
def test_mailToHelp(self):
126
145
"""Mail to help@ generates a help command."""
127
message = self.factory.makeSignedMessage()
146
user = self.factory.makePerson(email='user@dom.eg')
147
message = self.factory.makeSignedMessage(email_address='user@dom.eg')
128
148
handler = MaloneHandler()
129
with person_logged_in(self.factory.makePerson()):
149
with person_logged_in(user):
130
150
mail_handled, add_comment_to_bug, commands = \
131
151
handler.extractAndAuthenticateCommands(message,
132
152
'help@bugs.launchpad.net')
133
153
self.assertEquals(mail_handled, True)
134
self.assertEquals(len(self.getSentMail()), 1)
135
# TODO: Check the right mail was sent. -- mbp 20100923
154
emails = self.getSentMail()
155
self.assertEquals(1, len(emails))
156
self.assertEquals([message['From']], emails[0][1])
158
'Subject: Launchpad Bug Tracker Email Interface' in emails[0][2])
137
160
def getSentMail(self):
138
161
# Sending mail is (unfortunately) a side effect of parsing the