Exemple #1
0
    def test_no_first_name_subscribe_adds_person_and_subscription(self):
        email = Factory.rand_email()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            json.dumps({
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            }),
            'json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )

        json_string = response.content.decode('utf-8')
        response_data = json.loads(json_string)
        self.assertEquals(response_data["success"], True)
        self.assertEquals(response.status_code, 200)

        self.assertEquals(Person.objects.count(), 1)
        p = Person.objects.all()[0]
        self.assertEquals(p.email, email)

        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertEquals(s.person, p)
        self.assertEquals(s.newsletter.name, self.newsletter.name)
        self.assertEquals(s.subscription_url, subscription_url)
        self.assertEquals(s.subscribed_from_ip, self._source_ip)
Exemple #2
0
    def test_clicked_confirm_a_second_time(self):
        self.assertEquals(Subscription.objects.count(), 0)
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse(
                'inkmail:subscribe',
            ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )
        self.assertEquals(response.status_code, 200)
        process_outgoing_message_queue()

        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertIn(s.opt_in_link, mail.outbox[0].body)

        self.get(s.opt_in_link)
        s = Subscription.objects.get(pk=s.pk)
        self.assertEquals(s.double_opted_in, True)
        self.assertBasicallyEqualTimes(s.double_opted_in_at, self.now())
        first_time = s.double_opted_in_at

        # Click it again
        self.get(s.opt_in_link)
        s = Subscription.objects.get(pk=s.pk)
        self.assertEquals(s.double_opted_in, True)
        self.assertBasicallyEqualTimes(s.double_opted_in_at, first_time)
Exemple #3
0
 def test_post_subscribe_200(self):
     email = Factory.rand_email()
     name = Factory.rand_name()
     subscription_url = Factory.rand_url()
     response = self.post(
         reverse('inkmail:subscribe', ),
         {
             'first_name': name,
             'email': email,
             'newsletter': self.newsletter.internal_name,
             'subscription_url': subscription_url,
         },
     )
     self.assertEquals(response.status_code, 200)
     self.assertEquals(HistoricalEvent.objects.count(), 1)
     self.assertEquals(Person.objects.count(), 1)
     self.assertEquals(Subscription.objects.count(), 1)
     he = HistoricalEvent.objects.all()[0]
     p = Person.objects.all()[0]
     s = Subscription.objects.all()[0]
     self.assertEquals(he.event_type, "subscribed")
     self.assertEquals(he.event_creator_type, "person")
     self.assertEquals(he.event_creator_pk, p.pk)
     self.assertHistoricalEventDataEquality(
         he,
         person=p,
         event_type="subscribed",
         newsletter=self.newsletter,
         subscription=s,
     )
Exemple #4
0
    def test_import_ignores_banned_people(self):
        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)

        banned_person = Factory.person()
        banned_person.ban()
        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 0)

        import_source = Factory.rand_str()
        email = banned_person.email
        subscribed_at = Factory.rand_datetime()
        subscription_url = Factory.rand_url()
        double_opted_in = Factory.rand_bool()

        self.newsletter.import_subscriber(
            import_source=import_source,
            email=email,
            subscribed_at=subscribed_at,
            subscription_url=subscription_url,
            double_opted_in=double_opted_in,
            newsletter_name=self.newsletter.internal_name,
            overwrite=True,
        )

        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Newsletter.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 0)
Exemple #5
0
    def test_post_subscribe_200(self):
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )
        self.assertEquals(response.status_code, 200)
        process_outgoing_message_queue()

        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(mail.outbox[0].subject,
                          self.newsletter.confirm_message.subject)
        self.assertEquals(OutgoingMessage.objects.count(), 1)
        om = OutgoingMessage.objects.all()[0]
        self.assertIn(
            om.render_email_string(
                self.newsletter.confirm_message.body_text_unrendered),
            mail.outbox[0].alternatives[0][0])
        self.assertIn(
            om.render_email_string(
                self.newsletter.confirm_message.body_text_unrendered,
                plain_text=True), mail.outbox[0].body)
        self.assertEquals(len(mail.outbox[0].to), 1)
        self.assertEquals(mail.outbox[0].to[0], email)
        self.assertEquals(mail.outbox[0].from_email,
                          self.newsletter.full_from_email)
Exemple #6
0
    def test_post_subscribe_adds_person_and_subscription(self):
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )

        self.assertEquals(response.status_code, 200)

        self.assertEquals(Person.objects.count(), 1)
        p = Person.objects.all()[0]
        self.assertEquals(p.first_name, name)
        self.assertEquals(p.email, email)

        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertEquals(s.person, p)
        self.assertEquals(s.newsletter.name, self.newsletter.name)
        self.assertEquals(s.subscription_url, subscription_url)
        self.assertEquals(s.subscribed_from_ip, self._source_ip)
Exemple #7
0
    def test_extended_types_encryption(self):
        e = Factory.rand_phone()
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = Factory.rand_name()
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = Factory.temp_password()
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = Factory.rand_url()
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)
Exemple #8
0
    def test_invalid_opt_in_click(self):
        self.assertEquals(Subscription.objects.count(), 0)
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse(
                'inkmail:subscribe',
            ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )
        self.assertEquals(response.status_code, 200)
        process_outgoing_message_queue()

        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertIn(s.opt_in_link, mail.outbox[0].body)

        self.get("%s%s" % (s.opt_in_link, Factory.rand_str(length=2)))
        s = Subscription.objects.get(pk=s.pk)
        self.assertEquals(s.double_opted_in, False)
        self.assertEquals(s.double_opted_in_at, None)
Exemple #9
0
    def test_unsubscribe_resubscribe_updates_all_fields(self):
        self.assertEquals(len(mail.outbox), 0)
        self.create_subscribed_person()
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)
        self.send_newsletter_message()

        self.assertEquals(len(mail.outbox), 1)
        m = mail.outbox[0]
        self.assertEquals(OutgoingMessage.objects.count(), 1)
        om = OutgoingMessage.objects.all()[0]

        # Unsubscribe
        self.assertIn(om.unsubscribe_link, m.body)
        self.get(om.unsubscribe_link)

        # Fetch updated subscription
        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, True)
        self.assertBasicallyEqualTimes(self.subscription.unsubscribed_at, self.now())

        # Re-subscribe
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse(
                'inkmail:subscribe',
            ),
            {
                'first_name': name,
                'email': self.person.email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )
        self.assertEquals(response.status_code, 200)
        self.assertEquals(Subscription.objects.count(), 1)
        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)

        process_outgoing_message_queue()
        self.assertEquals(len(mail.outbox), 2)
        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertIn(s.opt_in_link, mail.outbox[1].body)

        # Re-double-opt-in
        self.get(s.opt_in_link)
        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)
        process_outgoing_message_queue()

        # Check fields
        self.person = Person.objects.get(pk=self.person.pk)
        self.assertEquals(self.person.first_name, name)
        self.assertEquals(self.subscription.subscription_url, subscription_url)
Exemple #10
0
    def test_extended_types_encryption(self):
        e = Factory.rand_phone()
        self.assertEquals(e, decrypt(encrypt(e)))

        e = Factory.rand_name()
        self.assertEquals(e, decrypt(encrypt(e)))

        e = Factory.temp_password()
        self.assertEquals(e, decrypt(encrypt(e)))

        e = Factory.rand_url()
        self.assertEquals(e, decrypt(encrypt(e)))
Exemple #11
0
    def test_post_subscribe_200(self):
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )

        self.assertEquals(response.status_code, 200)
Exemple #12
0
    def test_extended_types_encryption(self):
        e = {
            "a": Factory.rand_phone(),
            "b": Factory.rand_phone(),
            "c": Factory.temp_password(),
        }
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = {
            "a": Factory.rand_name(),
            "b": Factory.rand_phone(),
            "c": Factory.rand_name(),
        }
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = {
            "a": Factory.temp_password(),
            "q": Factory.rand_phone(),
            "l": settings,
        }
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)

        e = {
            "p": Factory.rand_url(),
            "r": Factory.rand_rand_phoneurl(),
            "a": Factory.temp_password(),
        }
        historical_event = HistoricalEvent.objects.create()
        historical_event.event_data = e
        historical_event.save()
        historical_event = None
        historical_event = HistoricalEvent.objects.all()[0]
        self.assertEquals(historical_event.event_data, e)
Exemple #13
0
    def test_newsletter_required(self):
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': email,
                'subscription_url': subscription_url,
            },
        )

        self.assertEquals(response.status_code, 422)

        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)
Exemple #14
0
    def test_post_subscribe_200(self):
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            json.dumps({
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            }),
            'json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )

        json_string = response.content.decode('utf-8')
        response_data = json.loads(json_string)
        self.assertEquals(response_data["success"], True)
        self.assertEquals(response.status_code, 200)
Exemple #15
0
    def test_import_with_no_newsletter_creates_person_but_not_subscription(
            self):
        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)

        import_source = Factory.rand_str()
        email = Factory.rand_email()
        subscribed_at = Factory.rand_datetime()
        subscription_url = Factory.rand_url()
        double_opted_in = Factory.rand_bool()

        self.newsletter.import_subscriber(
            import_source=import_source,
            email=email,
            subscribed_at=subscribed_at,
            subscription_url=subscription_url,
            double_opted_in=double_opted_in,
        )

        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Newsletter.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 0)
Exemple #16
0
    def test_email_required(self):
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            json.dumps({
                'first_name': name,
                # 'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            }),
            'json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )

        json_string = response.content.decode('utf-8')
        response_data = json.loads(json_string)
        self.assertEquals(response_data["success"], False)
        self.assertEquals(response.status_code, 422)

        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)
Exemple #17
0
    def test_unsubscribe_resubscribe_non_opted_in_requires_opt_in_then_allows_messages_sent(
            self):
        self.assertEquals(len(mail.outbox), 0)
        self.create_subscribed_person()
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)
        self.send_newsletter_message()

        self.assertEquals(len(mail.outbox), 1)
        m = mail.outbox[0]
        self.assertEquals(OutgoingMessage.objects.count(), 1)
        om = OutgoingMessage.objects.all()[0]

        # Unsubscribe
        self.assertIn(om.unsubscribe_link, m.body)
        self.get(om.unsubscribe_link)

        # Fetch updated subscription
        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, True)

        # Re-opt them out manually
        self.subscription.double_opted_in = False
        self.subscription.double_opted_in_at = None
        self.subscription.save()

        # self.assertEquals(self.subscription.double_opted_in, False)
        # self.assertEquals(self.subscription.double_opted_in_at, None)
        self.assertBasicallyEqualTimes(self.subscription.unsubscribed_at,
                                       self.now())

        # Re-subscribe
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': self.person.first_name,
                'email': self.person.email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': Factory.rand_url(),
            },
        )
        self.assertEquals(response.status_code, 200)
        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)

        process_outgoing_message_queue()

        self.assertEquals(len(mail.outbox), 2)
        self.assertEquals(Subscription.objects.count(), 1)
        s = Subscription.objects.all()[0]
        self.assertIn(s.opt_in_link, mail.outbox[1].body)

        # Re-double-opt-in
        self.get(self.subscription.opt_in_link)

        self.subscription = Subscription.objects.get(pk=self.subscription.pk)
        self.assertEquals(self.subscription.unsubscribed, False)
        self.assertEquals(self.subscription.unsubscribed_at, None)
        self.assertEquals(self.subscription.double_opted_in, True)
        self.assertBasicallyEqualTimes(self.subscription.double_opted_in_at,
                                       self.now())

        process_outgoing_message_queue()

        # Welcome email re-sent
        self.assertEquals(len(mail.outbox), 3)

        # Send newsletter, make sure it sent.
        self.send_newsletter_message()
        process_outgoing_message_queue()
        self.assertEquals(len(mail.outbox), 4)
Exemple #18
0
    def test_unsubscribe_resubscribe_has_records_of_all_actions(self):
        self.newsletter = Factory.newsletter()
        self.assertEquals(HistoricalEvent.objects.count(), 0)
        email = Factory.rand_email()
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )

        self.assertEquals(response.status_code, 200)

        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 1)
        p = Person.objects.all()[0]
        s = Subscription.objects.all()[0]

        self.assertEquals(HistoricalEvent.objects.count(), 1)
        he = HistoricalEvent.objects.order_by("-created_at").all()[0]
        self.assertEquals(he.event_type, "subscribed")
        self.assertEquals(he.event_creator_type, "person")
        self.assertEquals(he.event_creator_pk, p.pk)
        self.assertHistoricalEventDataEquality(
            he,
            person=p,
            event_type="subscribed",
            newsletter=self.newsletter,
            subscription=s,
        )

        # Unsubscribe
        om = OutgoingMessage.objects.all()[0]
        self.get(om.unsubscribe_link)

        s = Subscription.objects.get(pk=s.pk)
        self.assertEquals(HistoricalEvent.objects.count(), 2)
        he = HistoricalEvent.objects.order_by("-created_at").all()[0]
        self.assertEquals(he.event_type, "unsubscribe")
        self.assertEquals(he.event_creator_type, "person")
        self.assertEquals(he.event_creator_pk, p.pk)
        self.assertHistoricalEventDataEquality(
            he,
            person=p,
            event_type="unsubscribe",
            subscription=s,
            outgoingmessage=om,
        )

        # Fetch updated subscription
        s = Subscription.objects.get(pk=s.pk)

        # Re-subscribe
        name = Factory.rand_name()
        subscription_url = Factory.rand_url()
        response = self.post(
            reverse('inkmail:subscribe', ),
            {
                'first_name': name,
                'email': p.email,
                'newsletter': self.newsletter.internal_name,
                'subscription_url': subscription_url,
            },
        )
        self.assertEquals(response.status_code, 200)
        s = Subscription.objects.get(pk=s.pk)
        p = Person.objects.get(pk=p.pk)

        self.assertEquals(HistoricalEvent.objects.count(), 3)
        he = HistoricalEvent.objects.order_by("-created_at").all()[0]
        self.assertEquals(he.event_type, "subscribed")
        self.assertEquals(he.event_creator_type, "person")
        self.assertEquals(he.event_creator_pk, p.pk)
        self.assertHistoricalEventDataEquality(
            he,
            person=p,
            event_type="subscribed",
            newsletter=self.newsletter,
            subscription=s,
        )

        process_outgoing_message_queue()

        # Re-double-opt-in
        self.get(s.opt_in_link)

        s = Subscription.objects.get(pk=s.pk)
        p = Person.objects.get(pk=p.pk)

        self.assertEquals(HistoricalEvent.objects.count(), 4)
        he = HistoricalEvent.objects.order_by("-created_at").all()[0]
        self.assertEquals(he.event_type, "double-opt-in")
        self.assertEquals(he.event_creator_type, "person")
        self.assertEquals(he.event_creator_pk, p.pk)
        self.assertHistoricalEventDataEquality(
            he,
            person=p,
            event_type="double-opt-in",
            newsletter=self.newsletter,
            subscription=s,
        )
Exemple #19
0
    def test_import_overwrites_if_told_to(self):
        s = None
        p = None
        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)

        first_import_source = Factory.rand_str()
        email = Factory.rand_email()
        first_subscribed_at = Factory.rand_datetime()
        first_subscription_url = Factory.rand_url()
        first_double_opted_in = Factory.rand_bool()
        first_double_opted_in_at = Factory.rand_datetime()
        first_first_name = Factory.rand_name()
        first_last_name = Factory.rand_name()
        first_subscription_ip = Factory.rand_ip()
        first_time_zone = Factory.rand_timezone()

        self.newsletter.import_subscriber(
            import_source=first_import_source,
            email=email,
            subscribed_at=first_subscribed_at,
            subscription_url=first_subscription_url,
            double_opted_in=first_double_opted_in,
            double_opted_in_at=first_double_opted_in_at,
            first_name=first_first_name,
            last_name=first_last_name,
            subscription_ip=first_subscription_ip,
            time_zone=first_time_zone,
            newsletter_name=self.newsletter.internal_name,
        )

        second_import_source = Factory.rand_str()
        second_subscribed_at = Factory.rand_datetime()
        second_subscription_url = Factory.rand_url()
        second_double_opted_in = Factory.rand_bool()
        second_double_opted_in_at = Factory.rand_datetime()
        second_second_name = Factory.rand_name()
        second_last_name = Factory.rand_name()
        second_subscription_ip = Factory.rand_ip()
        second_time_zone = Factory.rand_timezone()
        second_import_time = timezone.now()  # noqa

        self.newsletter.import_subscriber(
            import_source=second_import_source,
            email=email,
            subscribed_at=second_subscribed_at,
            subscription_url=second_subscription_url,
            double_opted_in=second_double_opted_in,
            double_opted_in_at=second_double_opted_in_at,
            first_name=second_second_name,
            last_name=second_last_name,
            subscription_ip=second_subscription_ip,
            time_zone=second_time_zone,
            newsletter_name=self.newsletter.internal_name,
            overwrite=True,
        )

        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Newsletter.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 1)
        p = Person.objects.all()[0]
        s = Subscription.objects.all()[0]

        # Check person
        self.assertEquals(p.first_name, second_second_name)
        self.assertEquals(p.last_name, second_last_name)
        self.assertEquals(p.email, email)
        self.assertEquals(p.hashed_first_name, lookup_hash(second_second_name))
        self.assertEquals(p.hashed_last_name, lookup_hash(second_last_name))
        self.assertEquals(p.hashed_email, lookup_hash(email))
        self.assertEquals(p.email_verified, second_double_opted_in)
        self.assertEquals(p.time_zone, second_time_zone)
        self.assertEquals(p.was_imported, True)
        self.assertBasicallyEqualTimes(p.was_imported_at, second_import_time)
        self.assertEquals(p.import_source, second_import_source)
        self.assertEquals(p.marked_troll, False)
        self.assertEquals(p.marked_troll_at, None)
        self.assertEquals(p.banned, False)
        self.assertEquals(p.banned_at, None)
        self.assertEquals(p.hard_bounced, False)
        self.assertEquals(p.hard_bounced_at, None)
        self.assertEquals(p.hard_bounced_reason, None)
        self.assertEquals(p.hard_bounced_message, None)
        self.assertEquals(p.never_contact_set, False)
        self.assertEquals(p.never_contact_set_at, None)
        self.assertEquals(p.personal_contact, False)

        # Check subscription
        self.assertEquals(s.person, p)
        self.assertEquals(s.newsletter, self.newsletter)
        self.assertBasicallyEqualTimes(s.subscribed_at, second_import_time)
        self.assertEquals(s.subscription_url, second_subscription_url)
        self.assertEquals(s.subscribed_from_ip, second_subscription_ip)
        self.assertEquals(s.was_imported, True)
        self.assertBasicallyEqualTimes(s.was_imported_at, second_import_time)
        self.assertEquals(s.import_source, second_import_source)
        self.assertEquals(s.double_opted_in, second_double_opted_in)
        self.assertBasicallyEqualTimes(s.double_opted_in_at,
                                       second_double_opted_in_at)
        self.assertEquals(s.has_set_never_unsubscribe, False)
        self.assertEquals(s.unsubscribed, False)
        self.assertEquals(s.unsubscribed_at, None)
Exemple #20
0
    def test_import_imports_trolls_but_marks_them(self):
        self.assertEquals(Person.objects.count(), 0)
        self.assertEquals(Subscription.objects.count(), 0)

        troll = Factory.person()
        troll.mark_troll()
        self.assertEquals(Person.objects.count(), 1)

        import_source = Factory.rand_str()
        email = troll.email
        subscribed_at = Factory.rand_datetime()
        subscription_url = Factory.rand_url()
        double_opted_in = Factory.rand_bool()
        import_time = timezone.now()

        self.newsletter.import_subscriber(
            import_source=import_source,
            email=email,
            subscribed_at=subscribed_at,
            subscription_url=subscription_url,
            double_opted_in=double_opted_in,
            newsletter_name=self.newsletter.internal_name,
            overwrite=True,
        )

        self.assertEquals(Person.objects.count(), 1)
        self.assertEquals(Newsletter.objects.count(), 1)
        self.assertEquals(Subscription.objects.count(), 1)
        p = Person.objects.all()[0]
        s = Subscription.objects.all()[0]

        # Check person
        self.assertEquals(p.first_name, None)
        self.assertEquals(p.last_name, None)
        self.assertEquals(p.email, email)
        self.assertEquals(p.hashed_first_name, lookup_hash(None))
        self.assertEquals(p.hashed_last_name, lookup_hash(None))
        self.assertEquals(p.hashed_email, lookup_hash(email))
        self.assertEquals(p.email_verified, double_opted_in)
        self.assertEquals(p.time_zone, None)
        self.assertEquals(p.was_imported, True)
        self.assertBasicallyEqualTimes(p.was_imported_at, import_time)
        self.assertEquals(p.import_source, import_source)
        self.assertEquals(p.marked_troll, True)
        self.assertBasicallyEqualTimes(p.marked_troll_at, import_time)
        self.assertEquals(p.banned, False)
        self.assertEquals(p.banned_at, None)
        self.assertEquals(p.hard_bounced, False)
        self.assertEquals(p.hard_bounced_at, None)
        self.assertEquals(p.hard_bounced_reason, None)
        self.assertEquals(p.hard_bounced_message, None)
        self.assertEquals(p.never_contact_set, False)
        self.assertEquals(p.never_contact_set_at, None)
        self.assertEquals(p.personal_contact, False)

        # Check subscription
        self.assertEquals(s.person, p)
        self.assertEquals(s.newsletter, self.newsletter)
        self.assertBasicallyEqualTimes(s.subscribed_at, import_time)
        self.assertEquals(s.subscription_url, subscription_url)
        self.assertEquals(s.subscribed_from_ip, None)
        self.assertEquals(s.was_imported, True)
        self.assertBasicallyEqualTimes(s.was_imported_at, import_time)
        self.assertEquals(s.import_source, import_source)
        self.assertEquals(s.double_opted_in, double_opted_in)
        self.assertEquals(s.double_opted_in_at, None)
        self.assertEquals(s.has_set_never_unsubscribe, False)
        self.assertEquals(s.unsubscribed, False)
        self.assertEquals(s.unsubscribed_at, None)