Exemple #1
0
    def test_receive__user_has_prefs(self):
        """When we get a bounce, we create the UserPrefs for that user."""
        # Note, no existing UserPref for starrer_4.

        bounce_message = testing_config.Blank(original=testing_config.Blank(
            get=lambda header: '*****@*****.**'))

        self.handler.receive(bounce_message)

        prefs_list = models.UserPref.get_prefs_for_emails(
            ['*****@*****.**'])
        updated_pref = prefs_list[0]
        self.assertEqual('*****@*****.**', updated_pref.email)
        self.assertTrue(updated_pref.bounced)
        self.assertTrue(updated_pref.notify_as_starrer)
Exemple #2
0
    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)
Exemple #3
0
    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()
Exemple #4
0
    def test_receive__create_prefs(self, mock_emailmessage_constructor):
        """When we get a bounce, we create the UserPrefs for that user."""
        # Note, no existing UserPref for starrer_4.

        bounce_message = testing_config.Blank(
            original={
                'to': '*****@*****.**',
                'from': 'sender',
                'subject': 'subject',
                'text': 'body'
            })

        self.handler.receive(bounce_message)

        prefs_list = models.UserPref.get_prefs_for_emails(
            ['*****@*****.**'])
        updated_pref = prefs_list[0]
        self.assertEqual('*****@*****.**', updated_pref.email)
        self.assertTrue(updated_pref.bounced)
        self.assertTrue(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__first_time(self, mock_get_current_user):
        mock_get_current_user.return_value = testing_config.Blank(
            email=lambda: '*****@*****.**')

        actual = models.UserPref.get_signed_in_user_pref()

        self.assertEqual('*****@*****.**', actual.email)
        self.assertEqual(True, actual.notify_as_starrer)
        self.assertEqual(False, actual.bounced)