Repository: fedora-infra/bodhi

Issue:
Put versions back into e-mail subjects
In https://github.com/fedora-infra/bodhi/pull/1561 we made it so update e-mail subjects use the new beautify title code (which is very nice), but inadvertently we also stopped including version info on the packages and now only list the package names. It has been requested that we bring back the versions into e-mail subjects, so we should modify the new beautify title to have an ```nvr``` flag (defaulting to ```False```) that includes the ```nvr``` of the Build if ```True```, and uses the current behavior if ```False```.


Discussion:
I'm not sure how I didn't notice this before, but the patch for this issue only added the ability for the nvr to be included in the title without actually modifying the e-mail code to use the new ability. This means that e-mails still don't have nvrs in the subject lines.

Resolving patch:
diff --git a/bodhi/server/mail.py b/bodhi/server/mail.py
--- a/bodhi/server/mail.py
+++ b/bodhi/server/mail.py
@@ -484,7 +484,7 @@ def send(to, msg_type, update, sender=None, agent=None):
             "X-Bodhi-Update-Release": update.release.name,
             "X-Bodhi-Update-Status": update.status.description,
             "X-Bodhi-Update-Builds": ",".join([b.nvr for b in update.builds]),
-            "X-Bodhi-Update-Title": update.beautify_title(),
+            "X-Bodhi-Update-Title": update.beautify_title(nvr=True),
             "X-Bodhi-Update-Pushed": update.pushed,
             "X-Bodhi-Update-Submitter": update.user.name,
         }
@@ -502,7 +502,7 @@ def send(to, msg_type, update, sender=None, agent=None):
 
     subject_template = u'[Fedora Update] %s[%s] %s'
     for person in iterate(to):
-        subject = subject_template % (critpath, msg_type, update.beautify_title())
+        subject = subject_template % (critpath, msg_type, update.beautify_title(nvr=True))
         fields = MESSAGES[msg_type]['fields'](agent, update)
         body = MESSAGES[msg_type]['body'] % fields
         send_mail(sender, person, subject, body, headers=headers)


Test patch:
diff --git a/bodhi/tests/server/test_mail.py b/bodhi/tests/server/test_mail.py
new file mode 100644
--- /dev/null
+++ b/bodhi/tests/server/test_mail.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+# Copyright 2017 Red Hat, Inc.
+#
+# This file is part of Bodhi.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+"""Tests for bodhi.server.mail."""
+import mock
+
+from bodhi.server import mail, models
+from bodhi.tests.server import base
+
+
+class TestSend(base.BaseTestCase):
+    """Test the send() function."""
+    @mock.patch.dict('bodhi.server.mail.config', {'smtp_server': 'smtp.example.com'})
+    @mock.patch('bodhi.server.mail.smtplib.SMTP')
+    def test_nvr_in_subject(self, SMTP):
+        """Assert that the sent e-mail has the full NVR in the subject."""
+        update = models.Update.query.all()[0]
+
+        mail.send('fake@news.com', 'comment', update, agent='bowlofeggs')
+
+        SMTP.assert_called_once_with('smtp.example.com')
+        sendmail = SMTP.return_value.sendmail
+        self.assertEqual(sendmail.call_count, 1)
+        self.assertEqual(sendmail.mock_calls[0][1][0], 'updates@fedoraproject.org')
+        self.assertEqual(sendmail.mock_calls[0][1][1], ['fake@news.com'])
+        self.assertTrue('X-Bodhi-Update-Title: bodhi-2.0-1.fc17' in sendmail.mock_calls[0][1][2])
+        self.assertTrue(
+            'Subject: [Fedora Update] [comment] bodhi-2.0-1.fc17' in sendmail.mock_calls[0][1][2])