def test_send_immediately_success(self, get_current_request): get_current_request.return_value = self.request add_users() self.request.context = Mailing.by_name('welcome_email') result = self.view.send_immediately_success(self.APPSTRUCT) self.assertIsInstance(result, HTTPFound) self.assertEqual(result.location, '/mailing/4/edit/') self.assertEqual( self.request.session.pop_flash(), [u'Mailing "welcome_email" sent to 1 recipients.'], ) mailer = get_mailer(self.request) self.assertEqual(len(mailer.outbox), 1) self.assertEqual(mailer.outbox[0].recipients, [ '*****@*****.**', ]) self.assertEqual(mailer.outbox[0].subject, u'Über Welcome!') self.assertIn( u'Hello Öne Bar', mailer.outbox[0].html, ) self.assertIn(u'Welcome to this über amazing BIMT app!', mailer.outbox[0].html) self.assertIn('Best wishes,', mailer.outbox[0].html) self.assertIn('BIMT Team', mailer.outbox[0].html)
def initTestingDB(auditlog_types=False, auditlog_entries=False, groups=False, users=False, portlets=False, mailings=False): engine = create_engine('sqlite:///:memory:') Base.metadata.create_all(engine) Session.configure(bind=engine) if auditlog_types: add_audit_log_event_types() if groups or users: add_groups() if users: add_users() if mailings: add_mailings() add_demo_mailing() if portlets: add_demo_portlet() if auditlog_entries: add_demo_auditlog_entries()
def test_exclude(self): add_groups() add_users() mailing = _make_mailing( name='foo', groups=[Group.by_name('enabled')], exclude_groups=[Group.by_name('admins'), Group.by_name('staff')], ) self.request.context = mailing self.assertItemsEqual( self.view.recipients, [User.by_email('*****@*****.**')], )
def test_set_value_for_send_immediately_button(self): add_groups() add_users() add_demo_mailing() self.request.context = Mailing.by_name('welcome_email') schema = colander.Schema() form = deform.Form(schema, buttons=['foo', 'bar', 'send_immediately']) self.view.before(form) self.assertEqual(form.buttons[0].value, 'foo') self.assertEqual(form.buttons[1].value, 'bar') self.assertEqual( form.buttons[2].value, 'Immediately send mailing "welcome_email" to all 1 recipients ' 'without date constraints?')
def test_send_immediately_success_non_unicode(self, get_current_request): get_current_request.return_value = self.request add_users() self.request.context = _make_mailing( id=1, name='foo', groups=None, exclude_groups=None, trigger=MailingTriggers.never.name, days=0, subject='Subject', body='Body', ) with self.assertRaises(AssertionError) as cm: self.view.send_immediately_success(self.APPSTRUCT) self.assertEqual( cm.exception.message, 'Mail body type must be unicode, not <type \'str\'>!')
def test_test_success_non_unicode(self): add_users() self.request.user = User.by_email('*****@*****.**') self.request.context = _make_mailing( id=1, name='foo', groups=None, exclude_groups=None, trigger=MailingTriggers.never.name, days=0, subject='Subject', body='Body', ) with self.assertRaises(AssertionError) as cm: self.view.test_success(self.APPSTRUCT) self.assertEqual( cm.exception.message, 'Mail body type must be unicode, not <type \'str\'>!')
def test_test_success(self): add_users() self.request.user = User.by_email('*****@*****.**') self.request.context = Mailing.by_name('welcome_email') result = self.view.test_success(self.APPSTRUCT) self.assertIsInstance(result, HTTPFound) self.assertEqual(result.location, '/mailing/4/edit/') self.assertEqual( self.request.session.pop_flash(), [u'Mailing "welcome_email" sent to "*****@*****.**".'], ) mailer = get_mailer(self.request) self.assertEqual(len(mailer.outbox), 1) self.assertEqual(mailer.outbox[0].subject, u'[Mailing Test] Über Welcome!') self.assertIn('This mailing would be sent to:', mailer.outbox[0].html) self.assertIn('*****@*****.**', mailer.outbox[0].html)