~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=adeuring][bug=817106] Make notification emails cope with UTF8 in
        the message.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# NOTE: The first line above must stay first; do not move the copyright
 
3
# notice to the top.  See http://www.python.org/dev/peps/pep-0263/.
 
4
#
1
5
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
6
# GNU Affero General Public License version 3 (see the file LICENSE).
3
7
 
 
8
from email.utils import formataddr
4
9
from storm.store import Store
5
10
from zope.component import getUtility
6
11
from zope.security.proxy import removeSecurityProxy
37
42
 
38
43
    layer = LaunchpadZopelessLayer
39
44
 
 
45
    def test_notify_from_unicode_names(self):
 
46
        # People with unicode in their names should appear correctly in the
 
47
        # email and not get smashed to ASCII or otherwise transliterated.
 
48
        RANDOM_UNICODE = u"Loïc"
 
49
        creator = self.factory.makePerson(displayname=RANDOM_UNICODE)
 
50
        spr = self.factory.makeSourcePackageRelease(creator=creator)
 
51
        self.factory.makeSourcePackageReleaseFile(sourcepackagerelease=spr)
 
52
        archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
 
53
        pocket = PackagePublishingPocket.RELEASE
 
54
        distroseries = self.factory.makeDistroSeries()
 
55
        distroseries.changeslist = "blah@example.com"
 
56
        blamer = self.factory.makePerson()
 
57
        notify(
 
58
            blamer, spr, [], [], archive, distroseries, pocket,
 
59
            action='accepted')
 
60
        notifications = pop_notifications()
 
61
        self.assertEqual(2, len(notifications))
 
62
        msg = notifications[1].get_payload(0)
 
63
        body = msg.get_payload(decode=True)
 
64
        self.assertIn("Loïc", body)
 
65
 
40
66
    def test_calculate_subject_customfile(self):
41
67
        lfa = self.factory.makeLibraryFileAlias()
42
68
        package_upload = self.factory.makePackageUpload()
87
113
            'Maintainer': 'Foo Bar <foo.bar@canonical.com>',
88
114
            'Changes': ' * Foo!',
89
115
            }
90
 
        (changesfile, date, changedby, maintainer) = fetch_information(
 
116
        info = fetch_information(
91
117
            None, None, changes)
92
 
        self.assertEqual('2001-01-01', date)
93
 
        self.assertEqual(' * Foo!', changesfile)
94
 
        for field in (changedby, maintainer):
 
118
        self.assertEqual('2001-01-01', info['date'])
 
119
        self.assertEqual(' * Foo!', info['changesfile'])
 
120
        fields = [
 
121
            info['changedby'],
 
122
            info['maintainer'],
 
123
            info['changedby_displayname'],
 
124
            info['maintainer_displayname'],
 
125
            ]
 
126
        for field in fields:
95
127
            self.assertEqual('Foo Bar <foo.bar@canonical.com>', field)
96
128
 
97
129
    def test_fetch_information_spr(self):
98
 
        spr = self.factory.makeSourcePackageRelease()
99
 
        (changesfile, date, changedby, maintainer) = fetch_information(
100
 
            spr, None, None)
101
 
        self.assertEqual(date, spr.dateuploaded)
102
 
        self.assertEqual(changesfile, spr.changelog_entry)
103
 
        self.assertEqual(changedby, format_address_for_person(spr.creator))
104
 
        self.assertEqual(
105
 
            maintainer, format_address_for_person(spr.maintainer))
 
130
        creator = self.factory.makePerson(displayname=u"foø")
 
131
        maintainer = self.factory.makePerson(displayname=u"bær")
 
132
        spr = self.factory.makeSourcePackageRelease(
 
133
            creator=creator, maintainer=maintainer)
 
134
        info = fetch_information(spr, None, None)
 
135
        self.assertEqual(info['date'], spr.dateuploaded)
 
136
        self.assertEqual(info['changesfile'], spr.changelog_entry)
 
137
        self.assertEqual(
 
138
            info['changedby'], format_address_for_person(spr.creator))
 
139
        self.assertEqual(
 
140
            info['maintainer'], format_address_for_person(spr.maintainer))
 
141
        self.assertEqual(
 
142
            u"foø <%s>" % spr.creator.preferredemail.email,
 
143
            info['changedby_displayname'])
 
144
        self.assertEqual(
 
145
            u"bær <%s>" % spr.maintainer.preferredemail.email,
 
146
            info['maintainer_displayname'])
106
147
 
107
148
    def test_fetch_information_bprs(self):
108
149
        bpr = self.factory.makeBinaryPackageRelease()
109
 
        (changesfile, date, changedby, maintainer) = fetch_information(
110
 
            None, [bpr], None)
 
150
        info = fetch_information(None, [bpr], None)
111
151
        spr = bpr.build.source_package_release
112
 
        self.assertEqual(date, spr.dateuploaded)
113
 
        self.assertEqual(changesfile, spr.changelog_entry)
114
 
        self.assertEqual(changedby, format_address_for_person(spr.creator))
115
 
        self.assertEqual(
116
 
            maintainer, format_address_for_person(spr.maintainer))
 
152
        self.assertEqual(info['date'], spr.dateuploaded)
 
153
        self.assertEqual(info['changesfile'], spr.changelog_entry)
 
154
        self.assertEqual(
 
155
            info['changedby'], format_address_for_person(spr.creator))
 
156
        self.assertEqual(
 
157
            info['maintainer'], format_address_for_person(spr.maintainer))
 
158
        self.assertEqual(
 
159
            info['changedby_displayname'],
 
160
            formataddr((spr.creator.displayname,
 
161
                        spr.creator.preferredemail.email)))
 
162
        self.assertEqual(
 
163
            info['maintainer_displayname'],
 
164
            formataddr((spr.maintainer.displayname,
 
165
                        spr.maintainer.preferredemail.email)))
117
166
 
118
167
    def test_calculate_subject_spr(self):
119
168
        spr = self.factory.makeSourcePackageRelease()
291
340
        result = is_auto_sync_upload(
292
341
            spr=None, bprs=None, pocket=None, changed_by_email=None)
293
342
        self.assertFalse(result)
294