def app_login_disabled(): """An application for the tests.""" with patch.object(LdapClient, 'is_authenticated', return_value=True): _app_nologin = create_app(Config(environment='test', login_disabled=True)) ctx = _app_nologin.test_request_context() ctx.push() yield _app_nologin ctx.pop()
def test_invalid_environment(): """get ValueError when pass an invalid env.""" with pytest.raises(ValueError) as ve: app = create_app(Config(environment='sTaGe')) assert str(ve.value) == 'unknown environment: stage'
def test_dev_config(): """Development config.""" app = create_app(Config(environment='dev')) assert app.config['ENV'] == 'dev' assert app.config['DEBUG'] is True assert app.config['ASSETS_DEBUG'] is True
from subprocess import call from flask_migrate import Migrate, MigrateCommand from flask_script import Command, Manager, Option, Server, Shell from flask_script.commands import Clean, ShowUrls from cadash.app import create_app from cadash.database import db from cadash.settings import Config from cadash.user.models import BaseUser CONFIG = Config(environment=os.environ.get('CADASH_ENV')) HERE = os.path.abspath(os.path.dirname(__file__)) TEST_PATH = os.path.join(HERE, 'tests') app = create_app(CONFIG, 'cadash') manager = Manager(app) migrate = Migrate(app, db) def _make_context(): """Return context dict for a shell session so you can access app, db, and the User model by default.""" return {'app': app, 'db': db, 'User': BaseUser} @manager.command def test(): """Run the tests.""" import pytest exit_code = pytest.main([TEST_PATH, '--verbose']) return exit_code