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)
def setUp(self, *args, **kwargs): self.person = Factory.person() self.product = Factory.product(has_epilogue=True) self.purchase = Factory.productpurchase(person=self.person, product=self.product) self.journey = Journey.objects.create(productpurchase=self.purchase, start_date=timezone.now()) self.day1 = self.journey.days[0] # self.pw = Factory.rand_str(include_emoji=False) # self.person.set_password(self.pw) super(TestDailyEmails, self).setUp(*args, **kwargs)
def test_does_not_send_to_everyone_not_in_list(self): subscribed_people = [] subscribed_people_emails = [] nonsubscribed_people = [] nonsubscribed_people_emails = [] num_subscribers = Factory.rand_int(end=20) num_nonsubscribers = Factory.rand_int(end=20) for i in range(0, num_subscribers): s = Factory.subscription(newsletter=self.newsletter) s.double_opt_in() subscribed_people.append(s) subscribed_people_emails.append(s.person.email) for i in range(0, num_nonsubscribers): p = Factory.person() nonsubscribed_people.append(p) nonsubscribed_people_emails.append(p.email) self.send_newsletter_message() self.assertEquals(len(mail.outbox), num_subscribers) for m in mail.outbox: self.assertEquals(len(m.to), 1) self.assertIn(m.to[0], subscribed_people_emails) self.assertNotIn(m.to[0], nonsubscribed_people_emails)
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)
def create_transactional_person(self): self.person = Factory.person()
def setUp(self, *args, **kwargs): self.person = Factory.person() self.pw = Factory.rand_str(include_emoji=False) self.person.set_password(self.pw) super(TestResetPassword, self).setUp(*args, **kwargs)