@@ -0,0 +1,2906 @@
+import datetime%0A%0Afrom django.test import TestCase%0A%0Afrom corehq.util.models import (%0A    BouncedEmail,%0A    PermanentBounceMeta,%0A    BounceSubType,%0A    GENERAL_BOUNCE_THRESHOLD,%0A    ComplaintBounceMeta,%0A)%0A%0A%0Aclass TestBouncedEmails(TestCase):%0A    SUPPRESSED_BOUNCE = 'permanent_bounce@gmail.com'%0A    UNDETERMINED_BOUNCE = 'undetermined_bounce@gmail.com'%0A    GENERAL_BOUNCE = 'general_bounce@gmail.com'%0A    GENERAL_AT_TRESH = 'general_bounce_stillok@gmail.com'%0A    GENERAL_ABOVE_THRESH = 'general_bounce_bad@gmail.com'%0A    COMPLAINT = 'complaint@gmail.com'%0A    NO_META_BOUNCE = 'no_meta@gmail.com'%0A%0A    @staticmethod%0A    def _create_permanent_meta(email_address, sub_type, num_records=1):%0A        bounced_email = BouncedEmail.objects.create(email=email_address)%0A        for rec_num in range(0, num_records):%0A            PermanentBounceMeta.objects.create(%0A                bounced_email=bounced_email,%0A                timestamp=datetime.datetime.now(),%0A                sub_type=sub_type,%0A            )%0A%0A    def setUp(self):%0A        super().setUp()%0A        self._create_permanent_meta(%0A            self.SUPPRESSED_BOUNCE,%0A            BounceSubType.SUPPRESSED%0A        )%0A        self._create_permanent_meta(%0A            self.UNDETERMINED_BOUNCE,%0A            BounceSubType.UNDETERMINED%0A        )%0A        self._create_permanent_meta(%0A            self.GENERAL_BOUNCE,%0A            BounceSubType.GENERAL%0A        )%0A        self._create_permanent_meta(%0A            self.GENERAL_AT_TRESH,%0A            BounceSubType.GENERAL,%0A            GENERAL_BOUNCE_THRESHOLD,%0A        )%0A        self._create_permanent_meta(%0A            self.GENERAL_ABOVE_THRESH,%0A            BounceSubType.GENERAL,%0A            GENERAL_BOUNCE_THRESHOLD + 1,%0A        )%0A        BouncedEmail.objects.create(email=self.NO_META_BOUNCE)%0A        complaint_email = BouncedEmail.objects.create(email=self.COMPLAINT)%0A        ComplaintBounceMeta.objects.create(%0A            bounced_email=complaint_email,%0A            timestamp=datetime.datetime.now(),%0A        )%0A%0A    def tearDown(self):%0A        ComplaintBounceMeta.objects.all().delete()%0A        PermanentBounceMeta.objects.all().delete()%0A        BouncedEmail.objects.all().delete()%0A        super().tearDown()%0A%0A    def test_hard_bounce_emails(self):%0A        recipients = %5B%0A            'imok@gmail.com',%0A            self.SUPPRESSED_BOUNCE,%0A            self.UNDETERMINED_BOUNCE,%0A            self.GENERAL_BOUNCE,%0A            self.GENERAL_AT_TRESH,%0A            self.GENERAL_ABOVE_THRESH,%0A            self.COMPLAINT,%0A            self.NO_META_BOUNCE,%0A        %5D%0A%0A        bounced_emails = BouncedEmail.get_hard_bounced_emails(recipients)%0A        self.assertEqual(%0A            bounced_emails,%0A            %7B%0A                self.SUPPRESSED_BOUNCE,%0A                self.UNDETERMINED_BOUNCE,%0A                self.GENERAL_ABOVE_THRESH,%0A                self.COMPLAINT,%0A                self.NO_META_BOUNCE,%0A            %7D%0A        )%0A

add tests for getting hard bounced emails from a list of emails