Browse Source

Redefine app as factory function

feature_tests
Burathar 5 years ago
parent
commit
ae5bf35d70
  1. 37
      app/__init__.py
  2. 2
      tests/test_routes.py
  3. 10
      the_hunt.py

37
app/__init__.py

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
from config import Config
import os
import logging
from logging.handlers import SMTPHandler
from logging.handlers import RotatingFileHandler
import os
from flask import Flask
from flask_bootstrap import Bootstrap
@ -11,19 +11,28 @@ from flask_migrate import Migrate @@ -11,19 +11,28 @@ from flask_migrate import Migrate
from flask_login import LoginManager
from flask_moment import Moment
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
db = SQLAlchemy()
bootstrap = Bootstrap()
migrate = Migrate()
login = LoginManager()
login.login_view = 'login'
moment = Moment(app)
login.login_message = 'Please log in to access this page.'
moment = Moment()
from app import routes, models, errors
def create_app(config_class=Config):
# pylint: disable=no-member
app = Flask(__name__)
app.config.from_object(config_class)
db.init_app(app)
bootstrap.init_app(app)
migrate.init_app(app, db)
login.init_app(app)
moment.init_app(app)
if not app.debug and not app.testing:
if not app.debug and not app.testing:
if app.config['MAIL_SERVER']:
auth = None
if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
@ -56,4 +65,8 @@ if not app.debug and not app.testing: @@ -56,4 +65,8 @@ if not app.debug and not app.testing:
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('Microblog startup')
app.logger.info('Microblog startup')
return app
from app import routes, models, errors

2
tests/test_routes.py

@ -27,7 +27,7 @@ class RoutesCase(unittest.TestCase): @@ -27,7 +27,7 @@ class RoutesCase(unittest.TestCase):
g.players.append(p2)
db.session.append(g)
db.session.commit()
self.assertEqual
self.assertEqual(True, True)
self.assertFalse('Foo'.isupper())
if __name__ == '__main__':

10
the_hunt.py

@ -1,10 +1,12 @@ @@ -1,10 +1,12 @@
from app import app, db
from app import create_app, db
from app.models import Game, Player, Objective, Location, Notification, GamePlayer, \
PlayerFoundObjective, NotificationPlayer, PlayerCaughtPlayer, Role, GameState
app = create_app()
@app.shell_context_processor
def make_shell_context():
return {'db': db, 'Game' : Game, 'Player' : Player, 'Objective' : Objective,
'Location' : Location, 'Notification' : Notification, 'GamePlayer' : GamePlayer,
'PlayerFoundObjective' : PlayerFoundObjective, 'NotificationPlayer' : NotificationPlayer,
'PlayerCaughtPlayer' : PlayerCaughtPlayer, 'Role' : Role, 'GameState' : GameState}
'Location' : Location, 'Notification' : Notification, 'GamePlayer' : GamePlayer,
'PlayerFoundObjective' : PlayerFoundObjective, 'NotificationPlayer' : NotificationPlayer,
'PlayerCaughtPlayer' : PlayerCaughtPlayer, 'Role' : Role, 'GameState' : GameState}

Loading…
Cancel
Save