def test_receive__user_has_prefs(self, mock_emailmessage_constructor): """When we get a bounce, we update the UserPrefs for that user.""" starrer_3_pref = models.UserPref(email='*****@*****.**', notify_as_starrer=False) starrer_3_pref.put() bounce_message = testing_config.Blank( original={ 'to': '*****@*****.**', 'from': 'sender', 'subject': 'subject', 'text': 'body' }) self.handler.receive(bounce_message) updated_pref = models.UserPref.get_by_id(starrer_3_pref.key().id()) self.assertEqual('*****@*****.**', updated_pref.email) self.assertTrue(updated_pref.bounced) self.assertFalse(updated_pref.notify_as_starrer) expected_subject = "Mail to '*****@*****.**' bounced" mock_emailmessage_constructor.assert_called_once_with( sender=self.sender, to=self.expected_to, subject=expected_subject, body=mock.ANY) mock_message = mock_emailmessage_constructor.return_value mock_message.check_initialized.assert_called_once_with() mock_message.send.assert_called()
def test_get_signed_in_user_pref__had_pref(self, mock_get_current_user): mock_get_current_user.return_value = testing_config.Blank( email=lambda: '*****@*****.**') user_pref = models.UserPref(email='*****@*****.**', notify_as_starrer=False, bounced=True) user_pref.put() actual = models.UserPref.get_signed_in_user_pref() self.assertEqual('*****@*****.**', actual.email) self.assertEqual(False, actual.notify_as_starrer) self.assertEqual(True, actual.bounced)
def test_receive__user_has_prefs(self): """When we get a bounce, we update the UserPrefs for that user.""" starrer_3_pref = models.UserPref(email='*****@*****.**', notify_as_starrer=False) starrer_3_pref.put() bounce_message = testing_config.Blank(original=testing_config.Blank( get=lambda header: '*****@*****.**')) self.handler.receive(bounce_message) updated_pref = models.UserPref.get_by_id(starrer_3_pref.key().id()) self.assertEqual('*****@*****.**', updated_pref.email) self.assertTrue(updated_pref.bounced) self.assertFalse(updated_pref.notify_as_starrer)
def test_make_email_tasks__starrer_unsubscribed(self, mock_f_e_b): """We don't email users who starred the feature but opted out.""" mock_f_e_b.return_value = 'mock body html' starrer_2_pref = models.UserPref(email='*****@*****.**', notify_as_starrer=False) starrer_2_pref.put() notifier.FeatureStar.set_star('*****@*****.**', self.feature_2.key().id()) actual_tasks = notifier.make_email_tasks(self.feature_2, True, self.changes) self.assertEqual(2, len(actual_tasks)) # Note: There is no starrer_task. owner_task, watcher_task = actual_tasks self.assertEqual('*****@*****.**', owner_task['to']) self.assertEqual('*****@*****.**', watcher_task['to']) mock_f_e_b.assert_called_once_with(True, self.feature_2, self.changes)
def test_get__signed_in(self, mock_gsiup, mock_render): mock_gsiup.return_value = models.UserPref(email='*****@*****.**') actual = self.handler.get() mock_render.assert_called_once()