def test_email_diff_notification_wont_fire_without_changes(self): initial_count = len(mail.outbox) # version is indentical to previous one old_version = self.original_language.get_tip() new_version = self.original_language.add_version( subtitles=old_version.get_subtitles()) # no notifications should be sent res = send_new_version_notification(new_version.pk) self.assertEqual(res, None) self.assertEqual(len(mail.outbox), initial_count)
def test_email_diff_not_for_private(self): # make sure we never send email for private versions initial_count = len(mail.outbox) version = self.original_language.get_tip() version.visibility = 'private' version.save() self.assertTrue(version.is_private()) res = send_new_version_notification(version.pk) self.assertEqual(res, False) self.assertEqual(len(mail.outbox), initial_count)
def test_no_version_no_breakage(self): initial_count = len(mail.outbox) res = send_new_version_notification(1000) self.assertEqual(res, False) self.assertEqual(len(mail.outbox), initial_count)
def test_email_diff_subtitles(self): initial_count = len(mail.outbox) # set a user who can receive notification # make sure we have a different author, else he won't get notified author = User(username='******', email='*****@*****.**', notify_by_email=True, valid_email=True) author.save(send_email_confirmation=False) # bypass logic from hell author.valid_email = True author.save() # this is needed for the non_editor template check user2 = User(username='******', email='*****@*****.**', notify_by_email=True, valid_email=True) user2.save(send_email_confirmation=False) # bypass logic from hell user2.valid_email = True user2.save() # version is indentical to previous one video, video_url = Video.add("http://wwww.example.com/video-diff.mp4", None) video.followers.add(author) video.followers.add(user2) language = SubtitleLanguage(video=video, language_code='en') language.save() subs_data = [ [0, 1000, '1'], [1000, 2000, '2'], ] subtitles_1 = SubtitleSet.from_list('en', subs_data) old_version = language.add_version(subtitles=subtitles_1, author=author) # now we change the text on the second sub subs_data[1][2] = '2 changed' # add a regular sub subs_data.append([2000, 3000, 'new sub']) # add an unsyced subs_data.append([None, None, 'no sync']) subtitles_2 = SubtitleSet.from_list('en', subs_data) new_version = language.add_version(subtitles=subtitles_2) self.assertTrue(len(video.notification_list()) > 0) res = send_new_version_notification(new_version.pk) self.assertNotEqual(res, None) # we expect two emails, one is the new-edits-non-editor, and # the other for mail_notification.html self.assertEqual(len(mail.outbox), initial_count + 2) for email_number, email_msg in enumerate(mail.outbox): # make sure this is the right message self.assertIn("New edits to ", email_msg.subject) self.assertIn("video-diff.mp4", email_msg.subject) html = BeautifulSoup(email_msg.body) html_text = "".join(html.body(text=True)).replace("\n", "") if email_number == 0: # assert text and timing changes are correct self.assertIn('67% of the text', html_text) self.assertIn('33% of the timing was changed.', html_text) # find the listed text changes to make sure they match diff_table = html.findAll('table', attrs={'class': 'diffs'})[0] old_version_changes = [] new_version_changes = [] for i, node in enumerate(diff_table.findAll('td')): if i % 2 == 0: old_version_changes.append(node.text) else: new_version_changes.append(node.text) self.assertEqual(old_version_changes, [u'2', u'', u'']) self.assertEqual(new_version_changes, [ u'2 changed', u'new sub', u'no sync', ])