def test_mail_utils(self): from zabo.mail_utils import mailbody_transfer_received # first, create an abo in the DB and thus an id to match new_abo = Abo( name=u'foobar', email=u'*****@*****.**', amount=u'23' ) new_abo.linkcode = u'ABCDEFGHIJKAbo' new_abo.locale = u'de' DBSession.add(new_abo) DBSession.flush() assert(new_abo.id == 2) old_abo = Abo.get_by_id(1) old_abo.locale = u'en' _url = 'http://foobar.com' # englisch result1 = mailbody_transfer_received(old_abo, _url) #print result1 self.assertTrue('Hello' in result1) # german result2 = mailbody_transfer_received(new_abo, _url) #print result2 self.assertTrue('Hallo' in result2)
def setUp(self): super(StaffModelTests, self).setUp() with transaction.manager: staff1 = Staff( # german login=u'SomeFoonäme', email=u'*****@*****.**', password=u"12345", ) DBSession.add(staff1) DBSession.flush()
def setUp(self): self.config = testing.setUp() #self.config.include('pyramid_mailer.debug') self.config.include('pyramid_mailer.testing') from sqlalchemy import create_engine engine = create_engine('sqlite://') from zabo.models import ( Base, ) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: model = Abo(name=u'one', email=u'*****@*****.**', amount=55) DBSession.add(model)
def setUp(self): self.config = testing.setUp() self.config.include('pyramid_mailer.testing') try: DBSession.remove() #print("removing old DBSession =======================") except: #print("no DBSession to remove =======================") pass #engine = create_engine('sqlite:///test_models.db') engine = create_engine('sqlite:///:memory:') self.session = DBSession DBSession.configure(bind=engine) # XXX does influence self.session!?! Base.metadata.create_all(engine)
def test_send_mail_view(self): ''' tests for the send_email_view view in backend_views.py i.e. to send out transfer information emails ''' from zabo.backend_views import send_mail_view self.config.add_route('dash', '/dash') ''' if the requested id does not exist, redirect to the dashboard ''' request = testing.DummyRequest() request.registry.settings['the_url'] = 'http://foobar.com' request.registry.settings['mail_from'] = '*****@*****.**' request.matchdict['abo_id'] = u'1foo' # does not exist result = send_mail_view(request) #print result.location self.assertTrue('dash' in result.location) # redirected ''' if the id does exist, send email ''' # first, create an abo in the DB and thus an id to match new_abo = Abo( name=u'foobar', email=u'*****@*****.**', amount=u'23' ) new_abo.linkcode = u'ABCDEFGHIJKAbo' DBSession.add(new_abo) DBSession.flush() assert(new_abo.id == 2) request = testing.DummyRequest() #print type(new_abo.linkcode) request.matchdict['abo_id'] = new_abo.id # does exist from pyramid_mailer import get_mailer mailer = get_mailer(request) result = send_mail_view(request) self.assertEqual(len(mailer.outbox), 1) self.assertEqual( mailer.outbox[0].subject, u"You sustain C3S: Deine Links!") #print dir(mailer.outbox[0]) self.assertTrue(new_abo.linkcode in mailer.outbox[0].body) #print result.location self.assertTrue('dash' in result.location) # redirected
def test_html_and_png(self): """ load the page and image for use by the sponsor """ # make from zabo.models import Abo new_abo = Abo( name=u'oleander', email=u'*****@*****.**', amount=u'23', ) new_abo.locale = u'de' # set the linkcode to sth, which is usually done via button in backend new_abo.linkcode = u'YES_THIS_ONE' DBSession.add(new_abo) DBSession.flush() ''' image ''' image = self.testapp.get( '/verify/{}.png'.format(new_abo.linkcode), status=200) #print len(image.body) self.failUnless(85000 < len(image.body) < 90000) # check size of image ''' html page ''' html = self.testapp.get( '/verify/{}.html'.format(new_abo.linkcode), status=200) #print html.body # link to image must be in html self.failUnless( '/verify/{}.png'.format(new_abo.linkcode) in html.body) self.failUnless('<small>Thanks,</small>' in html.body) #self.failUnless('<small>Contribution by</small>' in html.body) self.failUnless(new_abo.name in html.body)
def _insert_abos(self): with transaction.manager: abo1 = Abo( # english name=u'SomeAliasnäme', email=u'*****@*****.**', amount=u'23', ) abo1.locale = u'en' abo2 = Abo( # german name=u'AAASomeFirstnäme', email=u'*****@*****.**', amount=u'42', ) abo2.locale = u'de' DBSession.add(abo1) DBSession.add(abo2) DBSession.flush()
def setUp(self): super(ZaboModelTests, self).setUp() with transaction.manager: abo1 = Abo( # englisch name=u'SomeFirstnäme', email=u'*****@*****.**', amount=u"12345", ) abo1.locale = u'en' abo1.refcode = u'ABCXXSustainC3S' DBSession.add(abo1) abo2 = Abo( # german name=u'SomeOthernäme', email=u'*****@*****.**', amount=u"12345", ) abo2.locale = u'de' DBSession.add(abo2) DBSession.flush()
def tearDown(self): DBSession.remove() testing.tearDown()
try: _repayment_date = datetime.strptime( request.POST['repayment_date'], '%Y-%m-%d') except ValueError, ve: request.session.flash('wrong date? {}'.format(ve.message)) return HTTPFound(request.route_url('dash')) else: return HTTPFound(request.route_url('dash')) _abo.payment_last_date = _repayment_date _transfer = Transfers( abo_id=_abo.id, date=_repayment_date, amount=_abo.amount, ) DBSession.add(_transfer) log.info( "repeated payment info of abo.id {} reported by {}".format( _abo.id, request.user.login, ) ) # redirect either to dashboard or to details page, # depending on where this came from if ( not isinstance(_referer, NoneType) ) and 'dash' in _referer: # pragma: no cover return HTTPFound( request.route_url(
def setUp(self): self.config = testing.setUp() self.config.include('pyramid_mailer.testing') try: DBSession.close() DBSession.remove() #print "closed and removed DBSession" except: pass #print "no session to close" my_settings = { 'sqlalchemy.url': 'sqlite:///:memory:', 'available_languages': 'da de en es fr', 'zabo.dashboard_number': '32', 'foo': 'bar', 'mailrecipient': '*****@*****.**', 'mail.debug': True, 'mail_from': '*****@*****.**', 'pyramid.includes': 'pyramid_mailer.testing', 'the_url': 'http://example.com', 'financial_blog_url_de': 'https://www.c3s.cc/ueber-c3s/finanzierung/', 'financial_blog_url_en': 'https://www.c3s.cc/en/about-us//financing/', 'base_path': '.' } engine = engine_from_config(my_settings) DBSession.configure(bind=engine) Base.metadata.create_all(engine) self._insert_abos() with transaction.manager: # a group for accountants/staff accountants_group = Group(name=u"staff") try: DBSession.add(accountants_group) DBSession.flush() #print("adding group staff") except: print("could not add group staff.") # pass # staff personnel staffer1 = Staff( login=u"rut", password=u"berries", email=u"*****@*****.**", ) staffer1.groups = [accountants_group] try: DBSession.add(accountants_group) DBSession.add(staffer1) DBSession.flush() except: print("could not add staffer1") # pass from zabo import main import pyramid registry = pyramid.registry.Registry() app = main({}, registry=registry, **my_settings) from webtest import TestApp self.testapp = TestApp(app)