def test_create_duplicate_person(self): Dummy_smtplib.install() # create a fake user p = Person(email_address='*****@*****.**') p.activated = True self.dbsession.save(p) self.dbsession.flush() pid = p.id resp = self.app.get('/person/new') f = resp.form f['person.email_address'] = '*****@*****.**' f['person.firstname'] = 'Testguy' f['person.lastname'] = 'McTest' f['person.password'] = '******' f['person.password_confirm'] = 'test' f['person.phone'] = '1234' f['person.mobile'] = '1234' f['person.address1'] = 'Moo St' f['person.city'] = 'Tassie' f['person.country'] = 'Australia' f['person.postcode'] = '2000' resp = f.submit() resp.mustcontain('A person with this email already exists.') resp.click('recover your password') self.dbsession.delete(self.dbsession.query(Person).get(pid)) self.dbsession.flush()
def smtplib(): Dummy_smtplib.install() yield Dummy_smtplib if Dummy_smtplib.existing: Dummy_smtplib.existing.reset()
def test_duplicate_password_reset(self): """Try to reset a password twice. """ c = Person(email_address='*****@*****.**') self.dbsession.save(c) self.dbsession.flush() cid = c.id # email = '*****@*****.**' # trap smtp Dummy_smtplib.install() resp = self.app.get(url_for(controller='person', action='signin')) resp = resp.click('Forgotten your password?') f = resp.forms[0] f['email_address'] = email f.submit() crec = self.dbsession.query(PasswordResetConfirmation).filter_by(email_address=email).one() self.failIfEqual(None, crec) crecid = crec.id # submit a second time resp = f.submit() resp.mustcontain("password recovery process is already in progress") # clean up Dummy_smtplib.existing.reset() self.dbsession.delete(self.dbsession.query(PasswordResetConfirmation).get(crecid)) self.dbsession.delete(self.dbsession.query(Person).get(cid)) self.dbsession.flush()
def setUp(self): super(TestPaymentController, self).setUp() Dummy_smtplib.install() print Dummy_smtplib.existing self.params = dict(invoice_id=1, payment_amount=69001, bank_reference=5261, payment_number='SimProxy 54021550')
def setUp(self): super(TestRegistrationController, self).setUp() Dummy_smtplib.install() # create some accommodation self.al = model.registration.AccommodationLocation(name='foo', beds=1) self.ao = model.registration.AccommodationOption(name='', cost_per_night=1) self.ao.location = self.al self.dbsession.save(self.al) self.dbsession.save(self.ao) self.dbsession.flush() self.alid = self.al.id self.aoid = self.ao.id
def test_forgotten_password_no_person(self): """Test that an invalid email address doesn't start a password change. """ Dummy_smtplib.install() resp = self.app.get(url_for(controller='person', action='signin')) resp = resp.click('Forgotten your password?') f = resp.forms[0] f['email_address'] = '*****@*****.**' resp = f.submit() #print resp resp.mustcontain("Your supplied e-mail does not exist in our database") crecs = self.dbsession.query(PasswordResetConfirmation).filter_by(email_address='*****@*****.**').all() self.assertEqual(0, len(crecs), "contact records found: %r" % crecs) self.assertEqual(None, Dummy_smtplib.existing)
def test_forgotten_password_no_person(self): """Test that an invalid email address doesn't start a password change. """ Dummy_smtplib.install() resp = self.app.get(url_for(controller='person', action='signin')) resp = resp.click('Forgotten your password?') f = resp.forms[0] f['email_address'] = '*****@*****.**' resp = f.submit() #print resp resp.mustcontain("Your supplied e-mail does not exist in our database") crecs = self.dbsession.query(PasswordResetConfirmation).filter_by( email_address='*****@*****.**').all() self.assertEqual(0, len(crecs), "contact records found: %r" % crecs) self.assertEqual(None, Dummy_smtplib.existing)
def test_create_person(self): """Test the process of creating new persons. """ Dummy_smtplib.install() # get the home page resp = self.app.get('/person/signin') # click on the 'create new account' link resp = resp.click('Sign up') # fill out the form f = resp.form f['person.email_address'] = '*****@*****.**' f['person.firstname'] = 'Testguy' f['person.lastname'] = 'McTest' f['person.password'] = '******' f['person.password_confirm'] = 'test' f['person.phone'] = '123' f['person.mobile'] = '123' f['person.address1'] = 'here' f['person.city'] = 'there' f['person.postcode'] = '1234' f['person.country'] = 'Australia' resp = f.submit() # did we get an appropriate page? resp.mustcontain("follow the instructions in that message") # check our email self.failIfEqual(None, Dummy_smtplib.existing, "no message sent") message = Dummy_smtplib.existing # check that it went to the right place self.assertEqual("*****@*****.**", message.to_addresses) # check that the message has the to address in it to_match = re.match(r'^.*To:.*[email protected].*', message.message, re.DOTALL) self.failIfEqual(None, to_match, "to address not in headers") # check that the message has the user's name name_match = re.match(r'^.*Testguy.*McTest', message.message, re.DOTALL) self.failIfEqual(None, name_match, "user's name not in headers") # check that the message was renderered without HTML, i.e. # as a fragment and thus no autohandler crap html_match = re.match(r'^.*<!DOCTYPE', message.message, re.DOTALL) self.failUnlessEqual(None, html_match, "HTML in message!") # check that the message has a url hash in it match = re.match(r'^.*/person/confirm/(\S+)', message.message, re.DOTALL) self.failIfEqual(None, match, "url not found") # visit the url print "match: '''%s'''" % match.group(1) resp = self.app.get('/person/confirm/%s' % match.group(1)) #print resp # check the rego worked regs = self.dbsession.query(Person).all() self.failIfEqual([], regs) #print regs[0] self.assertEqual(True, regs[0].activated, "account was not activated!") rid = regs[0].id # ok, now try to log in resp = resp.click('sign in') f = resp.form f['email_address'] = '*****@*****.**' f['password'] = '******' resp = f.submit() self.failIf('details are incorrect' in resp) self.assertSignedIn(resp.session, rid) # clean up Dummy_smtplib.existing.reset() self.dbsession.delete(self.dbsession.query(Person).get(rid)) self.dbsession.flush()
def test_forgotten_password(self): p = model.Person(email_address='*****@*****.**') self.dbsession.save(p) self.dbsession.flush() pid = p.id # trap smtp Dummy_smtplib.install() # get the login page resp = self.app.get(url_for(controller='person', action='signin', id=None)) # click on the forgotten password link resp = resp.click('Forgotten your password?') f = resp.form f['email_address'] = '*****@*****.**' f.submit() # check that the confirmation record was created crecs = self.dbsession.query(PasswordResetConfirmation).filter_by(email_address='*****@*****.**').all() self.failIfEqual(0, len(crecs)) # check our email self.failIfEqual(None, Dummy_smtplib.existing, "no message sent from forgotten password action") print Dummy_smtplib.existing.message # check to address to_match = re.match(r'^.*To:.*[email protected]', Dummy_smtplib.existing.message, re.DOTALL) self.failIfEqual(None, to_match, "to address not in headers") # check that the email has no HTML in it and thus was not rendered # incorrectly html_match = re.match(r'^.*<!DOCTYPE', Dummy_smtplib.existing.message, re.DOTALL) self.assertEqual(None, html_match, "HTML in message") # check that the message has a url hash in it url_match = re.match(r'^.*(/person/reset_password/\S+)', Dummy_smtplib.existing.message, re.DOTALL) self.failIfEqual(None, url_match, "reset password url not found in message") # ok go to the URL, on treadmills resp = self.app.get(url_match.group(1)) # set password f = resp.form f['password'] = '******' f['password_confirm'] = 'passwdtest' f.submit() self.dbsession.clear() # check that the password was changed p_hash = md5.new('passwdtest').hexdigest() p = self.dbsession.get(Person, pid) self.assertEqual(p_hash, p.password_hash) # check that the confirmatin record is gone crecs = self.dbsession.query(PasswordResetConfirmation).filter_by(email_address='*****@*****.**').all() self.assertEqual(0, len(crecs)) # clean up Dummy_smtplib.existing.reset() self.dbsession.delete(p) self.dbsession.flush()
def test_forgotten_password(self): p = model.Person(email_address='*****@*****.**') self.dbsession.save(p) self.dbsession.flush() pid = p.id # trap smtp Dummy_smtplib.install() # get the login page resp = self.app.get( url_for(controller='person', action='signin', id=None)) # click on the forgotten password link resp = resp.click('Forgotten your password?') f = resp.form f['email_address'] = '*****@*****.**' f.submit() # check that the confirmation record was created crecs = self.dbsession.query(PasswordResetConfirmation).filter_by( email_address='*****@*****.**').all() self.failIfEqual(0, len(crecs)) # check our email self.failIfEqual(None, Dummy_smtplib.existing, "no message sent from forgotten password action") print Dummy_smtplib.existing.message # check to address to_match = re.match(r'^.*To:.*[email protected]', Dummy_smtplib.existing.message, re.DOTALL) self.failIfEqual(None, to_match, "to address not in headers") # check that the email has no HTML in it and thus was not rendered # incorrectly html_match = re.match(r'^.*<!DOCTYPE', Dummy_smtplib.existing.message, re.DOTALL) self.assertEqual(None, html_match, "HTML in message") # check that the message has a url hash in it url_match = re.match(r'^.*(/person/reset_password/\S+)', Dummy_smtplib.existing.message, re.DOTALL) self.failIfEqual(None, url_match, "reset password url not found in message") # ok go to the URL, on treadmills resp = self.app.get(url_match.group(1)) # set password f = resp.form f['password'] = '******' f['password_confirm'] = 'passwdtest' f.submit() self.dbsession.clear() # check that the password was changed p_hash = md5.new('passwdtest').hexdigest() p = self.dbsession.get(Person, pid) self.assertEqual(p_hash, p.password_hash) # check that the confirmatin record is gone crecs = self.dbsession.query(PasswordResetConfirmation).filter_by( email_address='*****@*****.**').all() self.assertEqual(0, len(crecs)) # clean up Dummy_smtplib.existing.reset() self.dbsession.delete(p) self.dbsession.flush()