diff --git a/lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py b/lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py index ec431fbba4..4903203be2 100644 --- a/lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py +++ b/lms/djangoapps/linkedin/management/commands/linkedin_mailusers.py @@ -191,11 +191,11 @@ class Command(BaseCommand): reverse('course_root', kwargs={'course_id': cert.course_id}) ) - course_title = course.display_name + course_title = course.display_name_with_default course_img_url = 'https://{}{}'.format(settings.SITE_NAME, course_image_url(course)) course_end_date = course.end.strftime('%b %Y') - course_org = course.display_organization + course_org = course.org courses_list.append({ 'course_url': course_url, @@ -208,7 +208,7 @@ class Command(BaseCommand): context = {'courses_list': courses_list, 'num_courses': len(courses_list)} body = render_to_string('linkedin/linkedin_email.html', context) - subject = '{}, Add your Achievements to your LinkedIn Profile'.format(user.profile.name) + subject = u'{}, Add your Achievements to your LinkedIn Profile'.format(user.profile.name) if mock_run: return True else: @@ -219,7 +219,7 @@ class Command(BaseCommand): Send an email. Return True if it succeeded, False if it didn't. """ fromaddr = settings.DEFAULT_FROM_EMAIL - toaddr = '%s <%s>' % (user.profile.name, user.email) + toaddr = u'{} <{}>'.format(user.profile.name, user.email) msg = EmailMessage(subject, body, fromaddr, (toaddr,)) msg.content_subtype = "html" @@ -231,7 +231,7 @@ class Command(BaseCommand): except SINGLE_EMAIL_FAILURE_ERRORS: # Something unrecoverable is wrong about the email acct we're sending to log.exception( - "LinkedIn: Email send failed for user {}, email {}" + u"LinkedIn: Email send failed for user {}, email {}" .format(user.username, user.email) ) return False diff --git a/lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py b/lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py index 9bbc6244d7..333913ead6 100644 --- a/lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py +++ b/lms/djangoapps/linkedin/management/commands/tests/test_mailusers.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ Test email scripts. """ @@ -51,9 +52,16 @@ class MailusersTests(TestCase): self.barney = barney = User( username='barney', email='barney@bedrock.gov') barney.save() + LinkedIn(user=barney, has_linkedin_account=True).save() UserProfile(user=barney, name='Barney Rubble').save() + self.adam = adam = User( + username='adam', email='adam@adam.gov') + adam.save() + + LinkedIn(user=adam, has_linkedin_account=True).save() + UserProfile(user=adam, name='Adam (חיים פּלי)').save() self.cert1 = cert1 = GeneratedCertificate( status='downloadable', user=fred, @@ -71,7 +79,11 @@ class MailusersTests(TestCase): user=barney, course_id='TESTX/3/TEST3') cert3.save() - + cert5 = GeneratedCertificate( + status='downloadable', + user=adam, + course_id='TESTX/3/TEST3') + cert5.save() @mock.patch.dict('django.conf.settings.LINKEDIN_API', {'EMAIL_WHITELIST': ['barney@bedrock.gov']}) @@ -97,7 +109,9 @@ class MailusersTests(TestCase): json.loads(self.fred.linkedin.emailed_courses), ['TESTX/1/TEST1', 'TESTX/2/TEST2']) self.assertEqual( json.loads(self.barney.linkedin.emailed_courses), ['TESTX/3/TEST3']) - self.assertEqual(len(mail.outbox), 2) + self.assertEqual( + json.loads(self.adam.linkedin.emailed_courses), ['TESTX/3/TEST3']) + self.assertEqual(len(mail.outbox), 3) self.assertEqual( mail.outbox[0].to, ['Fred Flintstone ']) self.assertEqual( @@ -106,6 +120,8 @@ class MailusersTests(TestCase): mail.outbox[1].to, ['Barney Rubble ']) self.assertEqual( mail.outbox[1].subject, 'Barney Rubble, Add your Achievements to your LinkedIn Profile') + self.assertEqual( + mail.outbox[2].subject, u'Adam (חיים פּלי), Add your Achievements to your LinkedIn Profile') def test_mail_users_grandfather_mock(self): """ @@ -117,6 +133,8 @@ class MailusersTests(TestCase): json.loads(self.fred.linkedin.emailed_courses), []) self.assertEqual( json.loads(self.barney.linkedin.emailed_courses), []) + self.assertEqual( + json.loads(self.adam.linkedin.emailed_courses), []) self.assertEqual(len(mail.outbox), 0) def test_transaction_semantics(self):