~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/adapters/tests/test_notification.py

[r=julian-edwards][bug=796705] Deal with no recipients when rejecting
        inside reject_changes_file().

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from canonical.testing.layers import LaunchpadZopelessLayer
7
7
from lp.archivepublisher.utils import get_ppa_reference
8
8
from lp.services.mail.sendmail import format_address_for_person
 
9
from lp.services.log.logger import BufferLogger
9
10
from lp.soyuz.adapters.notification import (
10
11
    calculate_subject,
11
12
    fetch_information,
 
13
    reject_changes_file,
12
14
    person_to_email,
13
15
    notify,
14
16
    )
128
130
        body = notification.as_string()
129
131
        self.assertEqual(person_to_email(person), notification['To'])
130
132
        self.assertIn('Rejected by archive administrator.\n\n* Foo!\n', body)
 
133
 
 
134
    def test_reject_changes_file_no_email(self):
 
135
        # If we are rejecting a mail, and the person to notify has no
 
136
        # preferred email, we should return early.
 
137
        archive = self.factory.makeArchive()
 
138
        distroseries = self.factory.makeDistroSeries()
 
139
        uploader = self.factory.makePerson()
 
140
        removeSecurityProxy(uploader).preferredemail = None
 
141
        email = '%s <foo@example.com>' % uploader.displayname
 
142
        changes = {'Changed-By': email, 'Maintainer': email}
 
143
        logger = BufferLogger()
 
144
        reject_changes_file(
 
145
            uploader, '/tmp/changes', changes, archive, distroseries, '',
 
146
            logger=logger)
 
147
        self.assertIn(
 
148
            'No recipients have a preferred email.', logger.getLogBuffer())