Пример #1
0
    def test_import_adds_person_to_newsletter(self):
        s = None
        p = None
        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()
        double_opted_in_at = Factory.rand_datetime()
        first_name = Factory.rand_name()
        last_name = Factory.rand_name()
        subscription_ip = Factory.rand_ip()
        time_zone = Factory.rand_timezone()
        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,
            double_opted_in_at=double_opted_in_at,
            first_name=first_name,
            last_name=last_name,
            subscription_ip=subscription_ip,
            time_zone=time_zone,
            newsletter_name=self.newsletter.internal_name,
        )

        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, first_name)
        self.assertEquals(p.last_name, last_name)
        self.assertEquals(p.email, email)
        self.assertEquals(p.hashed_first_name, lookup_hash(first_name))
        self.assertEquals(p.hashed_last_name, lookup_hash(last_name))
        self.assertEquals(p.hashed_email, lookup_hash(email))
        self.assertEquals(p.email_verified, double_opted_in)
        self.assertEquals(p.time_zone, time_zone)
        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, 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, import_time)
        self.assertEquals(s.subscription_url, subscription_url)
        self.assertEquals(s.subscribed_from_ip, subscription_ip)
        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.assertBasicallyEqualTimes(s.double_opted_in_at,
                                       double_opted_in_at)
        self.assertEquals(s.has_set_never_unsubscribe, False)
        self.assertEquals(s.unsubscribed, False)
        self.assertEquals(s.unsubscribed_at, None)
Пример #2
0
 def get(self, *args, **kwargs):
     self._source_ip = Factory.rand_ip()
     return self.client.get(HTTP_X_FORWARDED_FOR=self._source_ip,
                            *args,
                            **kwargs)