我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用app.create_app()。
def before_all(context): """Create the context bag.""" # Change the configuration on the fly os.environ['ENV'] = 'testing' # Import this now because the environment variable # should be changed before this happens. context.app = create_app() # Create all the tables in memory. with context.app.app_context(): db.create_all() # Create the test client. context.client = context.app.test_client()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() descriptor = json.loads(open('fixtures/datapackage.json').read()) readme = open('fixtures/README.md').read() publisher = Publisher(name=self.publisher) package = Package(name=self.package,descriptor=descriptor, readme=readme) publisher.packages.append(package) db.session.add(publisher) db.session.commit()
def setUp(self): self.publisher = 'demo' self.package = 'demo-package' self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() user = User(id=11, name=self.publisher, secret='supersecret') publisher = Publisher(name=self.publisher) association = PublisherUser(role=UserRoleEnum.owner) association.publisher = publisher user.publishers.append(association) db.session.add(user) db.session.commit()
def setUp(self): self.publisher = 'test_publisher' self.package1 = 'test_package1' self.package2 = 'test_package2' self.app = create_app() self.client = self.app.test_client() with self.app.app_context(): db.drop_all() db.create_all() publisher = Publisher(name=self.publisher) metadata1 = Package(name=self.package1) metadata2 = Package(name=self.package2) publisher.packages.append(metadata1) publisher.packages.append(metadata2) db.session.add(publisher) db.session.commit()
def setUp(self): self.publisher = 'demo' self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() user = User(name=self.publisher) publisher = Publisher(name=self.publisher) association = PublisherUser(role=UserRoleEnum.owner) association.publisher = publisher user.publishers.append(association) db.session.add(user) db.session.commit()
def setUp(self): self.user_name = 'demo' self.app = create_app() self.app.app_context().push() with self.app.test_request_context(): db.drop_all() db.create_all() user = User(id=11, name=self.user_name, secret='supersecret') publisher = Publisher(name='test_pub_id') association = PublisherUser(role=UserRoleEnum.owner) association.publisher = publisher user.publishers.append(association) db.session.add(user) db.session.commit()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() Role.insert_roles() self.client = self.app.test_client(use_cookies=True)
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() Role.insert_roles() self.client = self.app.test_client()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() Role.insert_roles()
def create_cli_app(info): return create_app(os.getenv('DO_CONFIG') or 'default')
def app(request): """Build an application""" app = create_app('testing') ctx = app.app_context() ctx.push() request.addfinalizer(ctx.pop) return app
def app(): # app = Flask(__name__) app = create_app() return app
def setUp(self): self.app = create_app('development') # TODO add test config self.app_context = self.app.app_context() self.app_context.push()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() # ?????
def setUp(self): self.app = create_app('testing') self.context = self.app.app_context() self.context.push() db.create_all() Role.insert_roles()
def setUp(self): app = create_app() self.app = app.test_client()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client(use_cookies=True) # ??????
def setUp(self): self.app = create_app() self.app_context = self.app.app_context() self.app_context.push() db.create_all() # ??????
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() # ??????
def app(): """Creates an app with test settings""" app = create_app() return app
def setUp(self): self.app = create_app('comment') self.app_context = self.app.app_context() self.app_context.push() db.init_app(self.app) db.create_all() table_structs = self.app.config.get('COMMENT_TABLE_STRUCTS') table_structs = copy.deepcopy(table_structs) table_structs.pop('__tablename__') self.proxy = CommentProxy([key for key, value in table_structs.items()])
def send_email(recipient, subject, template, **kwargs): app = create_app(os.getenv('FLASK_CONFIG') or 'default') with app.app_context(): msg = Message( app.config['EMAIL_SUBJECT_PREFIX'] + ' ' + subject, sender=app.config['EMAIL_SENDER'], recipients=[recipient]) msg.body = render_template(template + '.txt', **kwargs) msg.html = render_template(template + '.html', **kwargs) mail.send(msg)