def test_set_login_view_without_blueprints(self): with self.app.app_context(): @self.app.route('/app_login') def app_login(): return 'Login Form Goes Here!' @self.app.route('/protected') @login_required def protected(): return u'Access Granted' set_login_view('app_login') with self.app.test_client() as c: result = c.get('/protected') self.assertEqual(result.status_code, 302) expected = 'http://localhost/app_login?next=%2Fprotected' self.assertEqual(result.location, expected)
def test_unauthorized_uses_blueprint_login_view(self): with self.app.app_context(): first = Blueprint('first', 'first') second = Blueprint('second', 'second') @self.app.route('/app_login') def app_login(): return 'Login Form Goes Here!' @self.app.route('/first_login') def first_login(): return 'Login Form Goes Here!' @self.app.route('/second_login') def second_login(): return 'Login Form Goes Here!' @self.app.route('/protected') @login_required def protected(): return u'Access Granted' @first.route('/protected') @login_required def first_protected(): return u'Access Granted' @second.route('/protected') @login_required def second_protected(): return u'Access Granted' self.app.register_blueprint(first, url_prefix='/first') self.app.register_blueprint(second, url_prefix='/second') set_login_view('app_login') set_login_view('first_login', blueprint=first) set_login_view('second_login', blueprint=second) with self.app.test_client() as c: result = c.get('/protected') self.assertEqual(result.status_code, 302) expected = ('http://localhost/' 'app_login?next=%2Fprotected') self.assertEqual(result.location, expected) result = c.get('/first/protected') self.assertEqual(result.status_code, 302) expected = ('http://localhost/' 'first_login?next=%2Ffirst%2Fprotected') self.assertEqual(result.location, expected) result = c.get('/second/protected') self.assertEqual(result.status_code, 302) expected = ('http://localhost/' 'second_login?next=%2Fsecond%2Fprotected') self.assertEqual(result.location, expected)
from flask_bcrypt import Bcrypt from GenerateGraph import plot_graph from WaterPumpFunctions import turnOnWaterForCorrectSeconds, turnOnRefillWaterPumpForNSecondsStandAloneMode import datetime import logging import os from os import path app = Flask(__name__, static_url_path='') login_manager = LoginManager() login_manager.init_app(app) bcrypt = Bcrypt(app) app.secret_key = appSecretKey with app.app_context(): set_login_view("login") app.config.__setitem__('SQLALCHEMY_DATABASE_URI', 'mysql+mysqldb://{0}:{1}@{2}:{3}/{4}'.format(dbUser, dbPass, dbHost, dbPort, dbSchema)) app.config.__setitem__('SQLALCHEMY_TRACK_MODIFICATIONS', True) db.init_app(app) phones = ["iphone", "android", "blackberry"] def loadAppConfigFormFromDB(): form = AppConfigForm(csrf_enabled=True) form.EnableEmailNotifications.data = str(getConfigValue('EnableEmailNotifications')) form.EnableSMSNotifications.data = str(getConfigValue('EnableSMSNotifications')) form.EnablePumpFunctions.data = str(getConfigValue('EnablePumpFunctions')) form.data_no_of_hours.data = getConfigValue('data_no_of_hours')