def app(): return create_app(get_config('test'))
def run(self): if app.template_service.validate(): return 0 else: return 1 def find_assets(): """Yield paths for all static files and templates.""" for name in ['static', 'templates']: directory = os.path.join(app.config['PATH'], name) for entry in os.scandir(directory): if entry.is_file(): yield entry.path # Select app configuration from the environment config = get_config(os.getenv('FLASK_CONFIG', 'dev')) # Build the app using configuration from the environment app = create_app(config) # Configure the command-line interface manager = Manager(app) manager.add_command('validate', Validate()) manager.add_command('run', Server(host='0.0.0.0', extra_files=find_assets())) if __name__ == '__main__': manager.run()
def when_empty(expect): with expect.raises(AssertionError): get_config('')
def when_valid(expect): config = get_config('production') expect(config.ENV) == 'production'
def test_get_valid(self): config = get_config('prod') assert issubclass(config, Config)
def app(): app = create_app(get_config('test')) app.config['GOOGLE_ANALYTICS_TID'] = 'my_tid' return app
def app(): app = create_app(get_config("test")) app.config["GOOGLE_ANALYTICS_TID"] = "my_tid" return app
def test_get_none(self): with pytest.raises(AssertionError): get_config('')
def when_unknown(expect): with expect.raises(AssertionError): get_config('unknown')
def when_extended(expect): config = get_config('staging') expect(config.ENV) == 'staging'
"""Checks for issues in all templates.""" def run(self): # pylint: disable=method-hidden if app.template_service.validate(): return 0 else: return 1 def find_assets(): """Yield paths for all static files and templates.""" for name in ['static', 'templates']: directory = os.path.join(app.config['PATH'], name) for entry in os.scandir(directory): if entry.is_file(): yield entry.path # Select app configuration from the environment config = get_config(os.getenv('FLASK_ENV', 'local')) # Build the app using configuration from the environment app = create_app(config) # Configure the command-line interface manager = Manager(app) manager.add_command('validate', Validate()) manager.add_command('run', Server(extra_files=find_assets())) if __name__ == '__main__': manager.run()
def test_get_unknown(self): with pytest.raises(AssertionError): get_config('not_a_valid_config')
def run(self): # pylint: disable=method-hidden if app.template_service.validate(): return 0 else: return 1 def find_assets(): """Yield paths for all static files and templates.""" for name in ['static', 'templates']: directory = os.path.join(app.config['PATH'], name) for entry in os.scandir(directory): if entry.is_file(): yield entry.path # Select app configuration from the environment config = get_config(os.getenv('FLASK_ENV', 'local')) # Build the app using configuration from the environment app = create_app(config) # Configure the command-line interface manager = Manager(app) manager.add_command('validate', Validate()) manager.add_command('run', Server(extra_files=find_assets())) if __name__ == '__main__': manager.run()
def unset(name): config = get_config('test') if getattr(config, name): return dict(condition=False, reason="") else: return dict(condition=True, reason="{} unset".format(name))
#!env/bin/python import os import logging from flask_script import Manager, Server from memegen.settings import get_config from memegen.app import create_app config = get_config(os.getenv('CONFIG')) app = create_app(config) manager = Manager(app) @manager.command def validate(): if app.template_service.validate(): return 0 else: return 1 manager.add_command('server', Server(host='0.0.0.0')) if __name__ == '__main__': logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") logging.getLogger('yorm').setLevel(logging.WARNING)
def run(self): if app.template_service.validate(): return 0 else: return 1 def find_assets(): """Yield paths for all static files and templates.""" for name in ["static", "templates"]: directory = os.path.join(app.config["PATH"], name) for entry in os.scandir(directory): if entry.is_file(): yield entry.path # Select app configuration from the environment config = get_config(os.getenv("FLASK_CONFIG", "dev")) # Build the app using configuration from the environment app = create_app(config) # Configure the command-line interface manager = Manager(app) manager.add_command("validate", Validate()) manager.add_command("run", Server(host="0.0.0.0", extra_files=find_assets())) if __name__ == "__main__": manager.run()
#!env/bin/python import os import logging from flask_script import Manager, Server from memegen.settings import get_config from memegen.app import create_app config = get_config(os.getenv('CONFIG')) app = create_app(config) manager = Manager(app) @manager.command def validate(): if app.template_service.validate(): return 0 else: return 1 manager.add_command('server', Server(host='0.0.0.0')) if __name__ == '__main__': manager.run()
def app(): yield create_app(get_config('test'))
#!env/bin/python import os import logging from subprocess import check_output from flask_script import Manager, Server from flask_migrate import Migrate, MigrateCommand from memegen.settings import get_config from memegen.app import create_app # Select app configuration from the environment config = get_config(os.getenv('CONFIG', 'dev')) # Build the app using configuration from the environment app = create_app(config) # Populate unset environment variables for name, command in [ ('DEPLOY_DATE', "TZ=America/Detroit date '+%F %T'"), ]: output = check_output(command, shell=True, universal_newlines=True).strip() os.environ[name] = os.getenv(name, output) # Configure the command-line interface manager = Manager(app) @manager.command def validate():
def app(): app = create_app(get_config('test')) yield app
#!env/bin/python import os import subprocess import logging from flask_script import Manager, Server from flask_migrate import Migrate, MigrateCommand from whitenoise import WhiteNoise from memegen.settings import get_config from memegen.app import create_app # Select app configuration from the environment config = get_config(os.getenv('CONFIG', 'dev')) # Build the app using configuration from the environment _app = create_app(config) # Populate unset environment variables for name, command in [ ('DEPLOY_DATE', "TZ=America/Detroit date '+%F %T'"), ]: output = subprocess.run(command, shell=True, stdout=subprocess.PIPE, universal_newlines=True).stdout.strip() or "???" os.environ[name] = os.getenv(name, output) # Configure the command-line interface manager = Manager(_app)
def test_get_valid(self): config = get_config('prod') assert issubclass(config, Config) assert 'prod' == config.ENV
def app(postgres): app = create_app(get_config('test')) app.config['SQLALCHEMY_DATABASE_URI'] = postgres.url() yield app