Exemplo n.º 1
0
 def test_full_html(self):
     stack = helpers.create_stack()
     e = Email.find_by_id_anon(stack['email_id'])
     e.html = '<h1>this is the new test html, {{ First Name }}</h1>'
     e.preheader = "I am a preheader"
     check = "<span class='preheader'>%s</span>%s<br>%s" % (e.preheader, e.html, e.account.footer_html)
     self.assertEqual(e.full_html(), check)
Exemplo n.º 2
0
 def test_get_percent_complete_cache(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.expire_counts()
     redis.set('dispatcher_%s_percent' % d.id, 15)
     self.assertEqual(d.get_percent_complete(), 15)
     redis.delete('dispatcher_%s_percent' % d.id)
Exemplo n.º 3
0
 def test_process_skip_blacklisted(self):
     stack = helpers.create_stack()
     send = Send.query.first()
     self.assertEqual(send.state, 0)
     Blacklist.create(account_id=stack['account_id'], email=send.data.get("Email Address"))
     send.process()
     self.assertEqual(send.state, 7)
Exemplo n.º 4
0
 def test_dispatcher_send(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     disp_count = redis.llen("dispatcher")
     d.send()
     self.assertEqual(redis.llen("dispatcher"), disp_count + 1)
     redis.delete("dispatcher")
Exemplo n.º 5
0
 def test_dispatcher_send_bad_state(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     disp_count = redis.llen("dispatcher")
     d.update(state=1)
     d.send()
     self.assertEqual(redis.llen("dispatcher"), disp_count)
     self.assertEqual(d.state, 1)
Exemplo n.º 6
0
 def test_render_text_attr(self):
     stack = helpers.create_stack()
     e = Email.find_by_id_anon(stack['email_id'])
     data = {
         'First Name': 'Bobby Lee'
     }
     check = 'text only here Bobby Lee\n\nContact Us - http://localhost:5000/pf/vib/12345, http://localhost:5000/pf/unsubscribe/12345'
     self.assertEqual(e.render_text_attr(data,'12345'), check)
Exemplo n.º 7
0
 def test_get_percent_complete_not_ready(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.expire_counts()
     [d.incr_sent() for _ in range(5)]
     [d.incr_skipped() for _ in range(2)]
     self.assertEqual(d.get_percent_complete(), 0)
     redis.delete('dispatcher_%s_percent' % d.id)
Exemplo n.º 8
0
 def test_full_text(self):
     stack = helpers.create_stack()
     e = Email.find_by_id_anon(stack['email_id'])
     e.html = '<h1>this is the new test html, {{ First Name }}</h1>'
     e.text = 'text only test'
     e.preheader = "I am a preheader"
     check = "%s\n\n%s" % (e.text, e.account.footer_text)
     self.assertEqual(e.full_text(), check)
Exemplo n.º 9
0
 def test_process_skip_no_hash(self):
     stack = helpers.create_stack()
     send = Send.query.first()
     send.state = 0
     send.hash_id = None
     send.save()
     send.process()
     self.assertEqual(send.state, 103)
Exemplo n.º 10
0
 def test_process_success(self):
     stack = helpers.create_stack()
     send = Send.query.first()
     self.assertEqual(send.message, None)
     send.process()
     p_send = Send.query.first()
     self.assertEqual(p_send.state, 1)
     self.assertEqual(p_send.message.get('recipient_metadata')[0].get('rcpt'), p_send.data.get("Email Address"))
Exemplo n.º 11
0
 def test_campaign_determiner_duplicates_true(self):
     stack = helpers.create_stack()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     e = Email.find_by_id_anon(stack['email_id'])
     e.update(selector_col_val='["dog"]')
     e2 = Email.create(account_id=c.account_id, name="EmailTwo", campaign_id=c.id)
     e2.update(selector_col_val='["dog"]')
     self.assertEqual(c.determiner_duplicates(),(True,'dog'))
Exemplo n.º 12
0
 def test_render_html_attr(self):
     stack = helpers.create_stack()
     e = Email.find_by_id_anon(stack['email_id'])
     data = {
         'First Name': 'Bobby Lee'
     }
     check = '<b>Body here, Hi Bobby Lee</b><br>http://localhost:5000/pf/vib/12345, http://localhost:5000/pf/unsubscribe/12345'
     self.assertEqual(e.render_html_attr(data,'12345'), check)
Exemplo n.º 13
0
 def test_dispatcher_send_email_from_data_success(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     sent_cnt_db = Send.query.count()
     sent_cnt_cache = int(d.get_sent())
     d.send_email_from_data({'dog': 'cat'})
     self.assertEqual(sent_cnt_db + 1, Send.query.count())
     self.assertEqual(str(sent_cnt_cache + 1), d.get_sent())
Exemplo n.º 14
0
 def test_dispatcher_send_email_from_data_already_exists(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     send = Send.find_by_id_anon(stack['send_id'])
     sent_count_cache = int(d.get_sent())
     send_cnt = Send.query.count()
     d.send_email_from_data({'hash_id': send.hash_id})
     self.assertEqual(send_cnt, Send.query.count())
     self.assertEqual(sent_count_cache, int(d.get_sent()))
Exemplo n.º 15
0
 def test_campaign_email_determiner_none(self):
     stack = helpers.create_stack()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     c.update(selector_col_name='dog')
     e = Email.find_by_id_anon(stack['email_id'])
     e.update(selector_col_val='["woof"]')
     e2 = Email.create(account_id=c.account_id, name="EmailTwo", campaign_id=c.id)
     e2.update(selector_col_val='["heina"]')
     self.assertEqual(c.email_determiner({'dog': 'cat'}), None)
Exemplo n.º 16
0
 def test_check_keys(self):
     stack = helpers.create_stack()
     e = Email.find_by_id_anon(stack['email_id'])
     mylist = List.find_by_id_anon(stack['list_id'])
     e.html = "cats and {{dogs}}"
     e.save()
     mylist.import_data="{['cats': 'no_dogs']}"
     mylist.save()
     self.assertEqual( e.check_keys(stack['list_id']), (False, 'dogs') )
Exemplo n.º 17
0
 def test_expire_counts(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.expire_counts()
     d.incr_sent()
     d.incr_skipped()
     d.incr_queued()
     self.assertEqual(int(d.get_sent()), 1)
     d.expire_counts()
     self.assertEqual(int(d.get_sent()), 0)
Exemplo n.º 18
0
 def test_get_percent_complete_under_90(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.expire_counts()
     [d.incr_queued() for _ in range(10)]
     [d.incr_sent() for _ in range(5)]
     [d.incr_skipped() for _ in range(2)]
     self.assertEqual(d.get_percent_complete(), 70)
     self.assertEqual(redis.exists('dispatcher_%s_percent' % d.id), True)
     d.expire_counts()
     redis.delete('dispatcher_%s_percent' % d.id)
Exemplo n.º 19
0
 def test_campaign_get_selector_import_data(self):
     stack = helpers.create_stack()
     l = List.find_by_id_anon(stack['list_id'])
     l.import_data = [{"dog": "cat"}, {"dog": "bird"}]
     l.save()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     c.selector_col_name = 'dog'
     c.save()
     e = Email.find_by_id_anon(stack['email_id'])
     e.selector_col_val = '["cat"]'
     e.save()
     self.assertEqual(c.get_selector_import_data(), [{'dog': 'cat'}])
Exemplo n.º 20
0
 def test_process_skip_bad_state(self):
     stack = helpers.create_stack()
     send = Send.query.first()
     redis.delete('dispatcher_%s_sent' % send.dispatcher_id)
     send.state = -1
     send.process()
     self.assertEqual(send.attempts, 1)
     self.assertEqual(send.dispatcher.get_sent(), '1')
     send.process()
     self.assertEqual(send.attempts, 2)
     self.assertEqual(send.dispatcher.get_sent(), '1')
     redis.delete('dispatcher_%s_sent' % send.dispatcher_id)
Exemplo n.º 21
0
 def test_dispatcher_send_email_from_data_no_email(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     e = Email.find_by_id_anon(stack['email_id'])
     c.update(selector_col_name='dog')
     e.update(selector_col_val='["false"]')
     send_cnt = Send.query.count()
     sk_cnt = int(d.get_skipped())
     d.send_email_from_data({'dog': 'cat'})
     self.assertEqual(send_cnt, Send.query.count())
     self.assertEqual(str(sk_cnt + 1), d.get_skipped())
Exemplo n.º 22
0
 def test_dispatcher_prep_data(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     orig_data = d.import_data
     disp_count = redis.llen("dispatcher")
     d.prep_data()
     self.assertEqual(d.state, 1)
     self.assertEqual(redis.llen("dispatcher"), disp_count + 1)
     self.assertEqual(d.import_data, orig_data)
     self.assertEqual(d.adjusted_data[0].keys(), ['name', 'hash_id'])
     self.assertEqual(len(d.adjusted_data[1].get('hash_id')), 64)
     self.assertEqual(len(d.adjusted_data), len(orig_data))
     redis.delete("dispatcher")
Exemplo n.º 23
0
 def test_dispatcher_queue_emails(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.expire_counts()
     d.prep_data()
     count = len(d.adjusted_data)
     mail_count = redis.llen("mail")
     d.queue_emails()
     self.assertEqual(d.state, 3)
     self.assertEqual(redis.llen("mail"), mail_count + count)
     self.assertEqual(d.get_queued(), str(count))
     self.assertEqual(d.queued_count, count)
     redis.delete("dispatcher")
Exemplo n.º 24
0
 def test_get_percent_complete_done(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     d.update(queued_count=10)
     d.expire_counts()
     [d.incr_queued() for _ in range(10)]
     [d.incr_sent() for _ in range(6)]
     [d.incr_skipped() for _ in range(4)]
     self.assertEqual(d.get_percent_complete(), 100)
     self.assertEqual(d.percent_complete, 100)
     self.assertEqual(d.state, 10)
     self.assertEqual(d.sent_count, 6)
     self.assertEqual(d.skipped_count, 4)
     redis.delete('dispatcher_%s_percent' % d.id)
Exemplo n.º 25
0
 def test_check_for_recent_found(self):
     stack = helpers.create_stack()
     d = Dispatcher.find_by_id_anon(stack['dispatcher_id'])
     limit = pytz.utc.localize(datetime.utcnow())
     Dispatcher.create(
         campaign_id=d.campaign_id,
         created_at=limit,
         account_id=d.account_id,
         user_id=d.user_id,
         list_id=d.list_id
     )
     limit = limit - timedelta(minutes=5) # so d doesn't trip it
     d.update(created_at=limit)
     self.assertEqual(d.check_for_recent(d.campaign_id), True)
Exemplo n.º 26
0
    def test_process_skip_bad_to_email(self):
        stack = helpers.create_stack()
        send = Send.query.first()

        #try blank column
        data = send.data
        send.update(data={})
        send.state=0
        data['Email Address'] = ''
        send.data = data
        send.save()
        send.process()
        self.assertEqual(send.state, 8)

        #try no column
        data = send.data
        send.update(data={})
        send.state=0
        data.pop("Email Address")
        send.data = data
        send.save()
        send.process()
        self.assertEqual(send.state, 8)
Exemplo n.º 27
0
 def test_campaign_selector_missing_false(self):
     stack = helpers.create_stack()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     self.assertEqual(c.selector_missing(),False)
Exemplo n.º 28
0
 def test_find_by_hash(self):
     stack = helpers.create_stack()
     self.assertEqual(Send.find_by_hash('azyx').id, stack['send_id'])
Exemplo n.º 29
0
 def test_campaign_selector_missing_true(self):
     stack = helpers.create_stack()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     e2 = Email.create(account_id=c.account_id, name="EmailTwo", campaign_id=c.id)
     self.assertEqual(c.selector_missing(),True)
Exemplo n.º 30
0
 def test_campaign_email_determiner_no_specification(self):
     stack = helpers.create_stack()
     c = Campaign.find_by_id_anon(stack['campaign_id'])
     e = Email.find_by_id_anon(stack['email_id'])
     e2 = Email.create(account_id=c.account_id, name="EmailTwo", campaign_id=c.id)
     self.assertEqual(c.email_determiner({}), e)