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 test_payment_received(self): ''' test the 'payment_received' view in backend_views.py login, go to dashboard, where the buttons to toggle reception of payment are located. ''' self._login_and_dashboard() self.config.add_route('paym_recd', '/') res = self.testapp.get('/login', status=302) res3 = res.follow() self.failUnless('Dashboard' in res3.body) #print res3.body ''' set to yes ''' res = self.testapp.get('/paym_recd/2', status=302) res2 = res.follow() #print res2.body self.failUnless('class="btn btn-default">ok</a>' in res2.body) abo2 = Abo.get_by_id(2) self.assertEquals(abo2.payment_received, True) #print abo2.linkcode #print type(abo2.name) _url = '/verify/' + abo2.linkcode + '.html' _html = self.testapp.get(_url, status=200) print _html.body self.assertTrue(abo2.name.encode('utf8') in _html.body) #self.assertTrue(str(abo2.amount) in _html.body) self.assertTrue(str(abo2.linkcode) in _html.body) ''' set to no ''' res = self.testapp.get('/paym_recd/2', status=302) res2 = res.follow() res = self.testapp.get('/abo_detail/2', status=200) # print '#'*80 # print '#'*80 # print res.body # print '#'*80 # print '#'*80 # self.failUnless('class="btn btn-primary">Nein</a>' in res2.body) # snippet = """<td>payment received? (erster Zahlungseingang)</td> # <td> # <div> # <div class="btn btn-danger">Nein</div>""" # self.failUnless(snippet in res2.body) abo2 = Abo.get_by_id(2) self.assertEquals(abo2.payment_received, False) _html = self.testapp.get(_url, status=200) #print _html.body self.assertTrue(abo2.name.encode('utf8') in _html.body) #self.assertTrue(str(abo2.amount) in _html.body) self.assertTrue(str(abo2.linkcode) in _html.body)
def test_autocomplete_codes(self): self._login_and_dashboard() # to be logged in code1 = Abo.get_by_id(1).refcode code2 = Abo.get_by_id(2).refcode res = self.testapp.get('/ariv/', status=200) #print res.body self.assertTrue(code1 in res.body) self.assertTrue(code2 in res.body)
def payment_received_again(request): """ This view lets accountants update abo payment info has their payment arrived? """ abo_id = request.matchdict['abo_id'] dashboard_page = request.cookies['on_page'] _abo = Abo.get_by_id(abo_id) _referer = request.headers.get('Referer') print _referer if isinstance(_abo, NoneType): return HTTPFound(request.route_url('dash')) #print '#'*80 #print request.POST #print '#'*80 # TODO: set date of last payment if 'repayment_date' in request.POST: 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'))
def test_send_mail_view(self): ''' test the 'send_mail_view' view in backend_views.py i.e. confirm paymant and send out links. login, go to dashboard, where the buttons to send the mail are located. ''' self._login_and_dashboard() res = self.testapp.get('/login', status=302) res3 = res.follow() self.failUnless('Dashboard' in res3.body) ''' set to yes ''' # try with invalid id, be redirected to dashboard res = self.testapp.get('/mail_mail_conf/foobar', status=302) res2 = res.follow() self.failUnless('Dashboard' in res2.body) res = self.testapp.get('/mail_mail_conf/2', status=302) res2 = res.follow() #print res2.body self.failUnless('class="btn btn-default">ok</a>' in res2.body) abo2 = Abo.get_by_id(2) #print "abo2.payment_confirmed_email: {}".format( # abo2.payment_confirmed_email) self.assertEquals(abo2.payment_confirmed_email, True)
def test_stats_view(self): """ login and go to stats view """ # login res = self.testapp.get('/login', status=200) self.failUnless('login' in res.body) # try invalid user form = res.form form['login'] = '******' form['password'] = '******' res3 = form.submit('submit', status=302) # # being logged in ... res4 = res3.follow() self.failUnless( 'Dashboard' in res4.body) abo1 = Abo.get_by_id(1) abo1.payment_received = True # now that we are logged in, test the stats view res = self.testapp.get('/stats', status=200) #print res.body self.failUnless('2 DB-Einträge' in res.body) self.failUnless('42 Euro, die noch nicht bezahlt sind.' in res.body) self.failUnless('23 Euro, die schon bezahlt sind.' in res.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 test_dashboard_jump_to_detail_by_refcode(self): ''' use the autocomplete form in the dashboard (without the outocomplete functionality) to get to a specific entry. ''' self._login_and_dashboard() self.config.add_route('switch_pay', '/') res = self.testapp.post( '/dash', params={'code_to_show': u'56789'}) # invalid code code1 = Abo.get_by_id(1).refcode res = self.testapp.post( '/dash', params={'code_to_show': code1}) # valid code res2 = res.follow() name1 = Abo.get_by_id(1).name self.assertTrue(name1.encode('utf8') in str(res2.body))
def test_delete_entry_view(self): self._login_and_dashboard() res = self.testapp.get('/login', status=302) res3 = res.follow() self.failUnless('Dashboard' in res3.body) number = Abo.get_number() left = number print "# Abos in DB: {}".format(number) for i in range(1, number+1): print "the i: {}".format(i) res = self.testapp.get('/del_entry/{}'.format(i), status=302) left += -1 self.assertEqual(Abo.get_number(), left) # check there are no items left in the DB self.assertEqual(Abo.get_number(), 0)
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 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 test_dashboard_jump_to_detail(self): self._login_and_dashboard() code1 = Abo.get_by_id(1).refcode res = self.testapp.get('/dash', status=200) self.assertTrue(str(code1) in res.body) res = self.testapp.get('/abo_detail/1', status=200) self.assertTrue(str(code1) in res.body) # try to get non-existing id resX = self.testapp.get('/abo_detail/1000', status=302) resY = resX.follow() self.assertTrue('Dashboard' in resY.body)
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 test_get_sponsorshipGrade(self): for i in range(1, 8): # use range(1, 9) if there is a 7th grade abo = Abo.get_by_id(i) res = abo.get_sponsorshipGrade() #print "{}: amount: {} grade: {}".format(i, abo.amount, res) self.assertEqual(int(res), i-1)
def abo_edit(request): ''' show details about one contribution ''' _id = request.matchdict['_id'] _abo = Abo.get_by_id(_id) # check abo exists or redirect to dashboard if isinstance(_abo, NoneType): request.session.flash( 'this abo id was not found in the DB', 'messages' ) return HTTPFound(location=request.route_url( 'dash')) else: class AboForm(colander.MappingSchema): name = colander.SchemaNode( colander.String(), title=_(u'Name or pseudonym'), ) email = colander.SchemaNode( colander.String(), title=_(u'E-mail'), validator=colander.Email(), ) amount = colander.SchemaNode( colander.Integer(), #widget=deform.widget.MoneyInputWidget( # options={'allowZero': False}), title=_(u'Amount (in full Euro)'), validator=Range( min=5, max=10000, min_err=_( u'at least 5 Euro, or the cost of transfer ' u'is too high.'), ) ) schema = AboForm() zform = deform.Form( schema, buttons=[ deform.Button('submit', _(u'Verspeichern')), ], renderer=zpt_renderer, ) # if the form has been used and SUBMITTED, check contents if 'submit' in request.POST: controls = request.POST.items() #print "we got {}".format(request.POST.items()) try: appstruct = zform.validate(controls) #print("the appstruct from the form: %s \n") % appstruct #for thing in appstruct: # print("the thing: %s") % thing # print("type: %s") % type(thing) except ValidationFailure, e: #print("the appstruct from the form: %s \n") % appstruct #for thing in appstruct: # print("the thing: %s") % thing # print("type: %s") % type(thing) print(e) #message.append( request.session.flash( _(u"Please note: There were errors, " u"please check the form below."), 'message_above_form', allow_duplicate=False) return{ 'zform': e.render(), 'abo': _abo, 'transfers': Transfers.get_all_transfers_by_aboid(_abo.id), } # validation worked. now do something # store information in the database # check if values are correct listing = [ ('name', appstruct['name']), ('email', appstruct['email']), ('amount', appstruct['amount']), ] for thing in listing: v = thing[0] if _abo.__getattribute__(v) == thing[1]: #print "no change for %s" % thing[0] pass else: #print ("change in %s:" % thing[0]) log.info( # XXX this needs to go into the logs "%s changes %s of id %s to %s" % ( authenticated_userid(request), thing[0], _abo.id, thing[1] ) ) setattr(_abo, v, thing[1]) return HTTPFound(request.route_url('abo_detail', _id=_abo.id)) else: # not submit in request.POST
def test_abo_edit(self): ''' test the 'abo_edit' view login, go to dashboard, then edit an entry ''' self._login_and_dashboard() self.config.add_route('paym_recd', '/') res = self.testapp.get('/login', status=302) res3 = res.follow() self.failUnless('Dashboard' in res3.body) #print res3.body ''' try to edit some non-existing entry ''' res = self.testapp.get('/abo_edit/2001', status=302) res2 = res.follow() self.failUnless('Dashboard' in res2.body) ''' edit some entry :: check missing form info (name) ''' res = self.testapp.get('/abo_edit/2', status=200) #res2 = res.follow() #print res.forms form = res.forms[0] form['name'] = '' form['email'] = '*****@*****.**' form['amount'] = 2342 res3 = form.submit('submit') #print res3.body ''' edit some entry :: check missing form info (email) ''' res = self.testapp.get('/abo_edit/2', status=200) #res2 = res.follow() #print res.forms form = res.forms[0] form['name'] = 'näme' form['email'] = '' form['amount'] = 2342 res3 = form.submit('submit') #print res3.body ''' edit some entry ''' res = self.testapp.get('/abo_edit/2', status=200) #res2 = res.follow() #print res.forms form = res.forms[0] form['name'] = 'näme' #form['email'] = '*****@*****.**' form['amount'] = 2342 res3 = form.submit('submit') #print res3.body ''' edit some entry :: all fields ''' res = self.testapp.get('/abo_edit/2', status=200) #res2 = res.follow() #print res.forms form = res.forms[0] form['name'] = u'näme' form['email'] = '*****@*****.**' form['amount'] = 2342 res3 = form.submit('submit') #print res3.body # check values from DB abo2 = Abo.get_by_id(2) #print (type(abo2.name), type(abo2.email), type(abo2.amount)) self.failUnless(abo2.name == u'näme') self.failUnless(abo2.email == u'*****@*****.**') self.failUnless(abo2.amount == 2342)