def test_register_no_phone(self): response = self.post('/user/register', dict( firstName='Bob', lastName='User', email='*****@*****.**', password='******' )) self.assertEqual(response.status_code, 200) with app.app_context() as context: data = response.get_json() user_id = auth.jwt.check_jwt(data['auth']) find_user = '''select * from Users where userId = %s;''' conn = db.conn() cursor = conn.cursor() cursor.execute(find_user, [user_id]) user = cursor.fetchall() self.assertEqual(1, len(user)) user = user[0] self.assertIn('Bob', user) self.assertIn('User', user) self.assertIn('*****@*****.**', user) self.assertIn(auth.hash_password('password123', '*****@*****.**'), user)
def test_reset_password_full(self): user = self.fake_user_object() response = self.post('/user/forgotPassword', dict(email=user['email'])) user['id'] = auth.jwt.check_jwt(user['jwt']) with app.app_context() as context: sql_stmt = '''select link from Links where userId=%s;''' conn = db.conn() cursor = conn.cursor() cursor.execute(sql_stmt, [user['id']]) token = cursor.fetchone()[0] response = self.post( '/user/resetPassword', dict(email=user['email'], newPassword='******', token=token)) self.assertEqual(response.status_code, 200) response = self.post( '/user/login', dict(email=user['email'], password='******')) self.assertEqual(response.status_code, 200)
def send_email(message): with app.app_context(): msg = Message('Interval Report', sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = TEMPLATE.format(message) mail.send(msg) return "Sent"
# coding: utf-8 import sys sys.path.append('..') from flaskapp.sproxy.nexmo_proxy import nexmo_proxy from flaskapp import app, mail from flask_mail import Message with app.app_context(): balance = nexmo_proxy().get_balance() if balance <= app.config.get("PROXY_BALANCE_THRESHOLD", 1000): app.logger.info("WARNING, NEXMO PROXY WITH LOW BALANCE! Balance: %s" % balance) msg = Message( "WARNING, NEXMO PROXY WITH LOW BALANCE!", ["*****@*****.**"], "WARNING, NEXMO PROXY WITH LOW BALANCE! Balance: %s" % balance) mail.send(msg)
def db_query(self, command, args): with app.app_context() as context: conn = db.conn() cursor = conn.cursor() cursor.execute(command, args) return cursor.fetchall()