diff --git a/pytest_bdd_example/auth/__init__.py b/pytest_bdd_example/auth/__init__.py index 24ae2c4..1009455 100644 --- a/pytest_bdd_example/auth/__init__.py +++ b/pytest_bdd_example/auth/__init__.py @@ -1,20 +1,11 @@ -from flask import Blueprint - from .decorators import public_endpoint -from .manager import login_manager, check_valid_login from .models import db - -__all__ = ['bp', 'db', 'public_endpoint'] - -bp = Blueprint('auth', __name__, template_folder='auth') +from .blueprint import auth -@bp.record_once -def on_registered(state): - db.init_app(state.app) - - login_manager.init_app(state.app) - state.app.before_request(check_valid_login) +# Register views +import views +views -from .views import * +__all__ = ['auth', 'db', 'public_endpoint'] diff --git a/pytest_bdd_example/auth/blueprint.py b/pytest_bdd_example/auth/blueprint.py new file mode 100644 index 0000000..9fe4c43 --- /dev/null +++ b/pytest_bdd_example/auth/blueprint.py @@ -0,0 +1,14 @@ +from flask import Blueprint + +from .manager import login_manager, check_valid_login +from .models import db + +auth = Blueprint('auth', __name__, template_folder='auth') + + +@auth.record_once +def on_registered(state): + db.init_app(state.app) + + login_manager.init_app(state.app) + state.app.before_request(check_valid_login) diff --git a/pytest_bdd_example/auth/views.py b/pytest_bdd_example/auth/views.py index aacc550..6fba778 100644 --- a/pytest_bdd_example/auth/views.py +++ b/pytest_bdd_example/auth/views.py @@ -1,13 +1,13 @@ from flask import request, url_for, redirect, render_template from flask.ext.login import login_user -from . import bp +from .blueprint import auth from .decorators import public_endpoint from .forms import LoginForm from .models import User -@bp.route('/login/', methods=['GET', 'POST']) +@auth.route('/login/', methods=['GET', 'POST']) @public_endpoint def login(): form = LoginForm() diff --git a/pytest_bdd_example/dashboard/__init__.py b/pytest_bdd_example/dashboard/__init__.py index 36a97a5..11bec64 100644 --- a/pytest_bdd_example/dashboard/__init__.py +++ b/pytest_bdd_example/dashboard/__init__.py @@ -1,20 +1,4 @@ -from flask import Flask - -# from flask.ext.admin import Admin +from .app import app -from pytest_bdd_example.dashboard import settings - -from pytest_bdd_example import auth - - -app = Flask( - __name__, - static_folder=settings.MEDIA_ROOT, - template_folder=settings.TEMPLATES_ROOT, -) -app.config.from_object('pytest_bdd_example.dashboard.settings') -app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' - - -app.register_blueprint(auth.bp, url_prefix='/auth') +__all__ = ['app'] diff --git a/pytest_bdd_example/dashboard/app.py b/pytest_bdd_example/dashboard/app.py new file mode 100644 index 0000000..83c89ea --- /dev/null +++ b/pytest_bdd_example/dashboard/app.py @@ -0,0 +1,17 @@ +from flask import Flask + +from pytest_bdd_example.dashboard import settings + +from pytest_bdd_example.auth import auth + + +app = Flask( + __name__, + static_folder=settings.MEDIA_ROOT, + template_folder=settings.TEMPLATES_ROOT, +) +app.config.from_object('pytest_bdd_example.dashboard.settings') +app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' + + +app.register_blueprint(auth, url_prefix='/auth') diff --git a/pytest_bdd_example/dashboard/views.py b/pytest_bdd_example/dashboard/views.py index 93bfa33..2c3908c 100644 --- a/pytest_bdd_example/dashboard/views.py +++ b/pytest_bdd_example/dashboard/views.py @@ -1,5 +1,7 @@ from flask import render_template +from .app import app + @app.route('/') def index(template='dashboard.html'):