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 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 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 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_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_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)