def test_mismatch_new_passwords(self): body = urllib.parse.urlencode({ "current_password": "******", "new_password": "******", "new_password_confirm": "orange", "new_email": "*****@*****.**" }) with patch('classrank.handlers.BaseHandler.get_current_user' ) as get_current_user: get_current_user.return_value = b'"andrew"' response = self.fetch("/settings", method="POST", body=body) self.assertEqual(response.code, 200) self.assertIn(b"Passwords did not match", response.body) with Query(self._app.db) as q: user = q.query( self._app.db.account).filter_by(username="******").one() self.assertEqual( user.password_hash, authenticate.hash_pw("password", user.password_salt)) # Did not update.. Even though entering new email wasn't erroneous, either ALL # updates should go through or NONE. Since new passwords didn't match, NO # updates should go through, so don't update email. self.assertEqual(user.email_address, "*****@*****.**")
def test_update_email_and_password(self): body = urllib.parse.urlencode({"current_password": "******", "new_password": "******", "new_password_confirm": "newpass", "new_email": "*****@*****.**"}) with patch('classrank.handlers.BaseHandler.get_current_user') as get_current_user: get_current_user.return_value = b'"andrew"' response = self.fetch("/settings", method="POST", body=body) self.assertEqual(response.code, 200) self.assertIn(b"Your information has been updated", response.body) with Query(self._app.db) as q: user = q.query(self._app.db.account).filter_by(username="******").one() self.assertEqual(user.password_hash, authenticate.hash_pw("newpass", user.password_salt)) self.assertEqual(user.email_address, "*****@*****.**")
def test_mismatch_new_passwords(self): body = urllib.parse.urlencode({"current_password": "******", "new_password": "******", "new_password_confirm": "orange", "new_email": "*****@*****.**"}) with patch('classrank.handlers.BaseHandler.get_current_user') as get_current_user: get_current_user.return_value = b'"andrew"' response = self.fetch("/settings", method="POST", body=body) self.assertEqual(response.code, 200) self.assertIn(b"Passwords did not match", response.body) with Query(self._app.db) as q: user = q.query(self._app.db.account).filter_by(username="******").one() self.assertEqual(user.password_hash, authenticate.hash_pw("password", user.password_salt)) # Did not update.. Even though entering new email wasn't erroneous, either ALL # updates should go through or NONE. Since new passwords didn't match, NO # updates should go through, so don't update email. self.assertEqual(user.email_address, "*****@*****.**")
def test_update_email_only(self): body = urllib.parse.urlencode({ "current_password": "******", "new_password": "", "new_password_confirm": "", "new_email": "*****@*****.**" }) with patch('classrank.handlers.BaseHandler.get_current_user' ) as get_current_user: get_current_user.return_value = b'"andrew"' response = self.fetch("/settings", method="POST", body=body) self.assertEqual(response.code, 200) self.assertIn(b"Your information has been updated", response.body) with Query(self._app.db) as q: user = q.query( self._app.db.account).filter_by(username="******").one() self.assertEqual( user.password_hash, authenticate.hash_pw("password", user.password_salt)) self.assertEqual(user.email_address, "*****@*****.**")