def make_test_app(): clear_entry_services() app = Sanic(__name__) database = PostgresqlDatabase(database=DB) app.blueprint(bp, db=database, db_name=DB_NAME, loop=None) service = get_entry_service() service.dropdb() service.initdb() database.close() database.allow_sync = False app.db = database return app
def make_test_app(): clear_session_services() clear_user_services() app = Sanic(__name__) database = PostgresqlDatabase(database=DB) app.blueprint(session_blueprint, db=database, db_name=DB_SESSION_NAME, loop=None) app.blueprint(bp, db=database, db_name=DB_NAME, loop=None, sessions_db_name=DB_SESSION_NAME) service = get_user_service() service.dropdb() service.initdb() service = get_session_service() service.dropdb() service.initdb() database.close() database.allow_sync = False app.db = database return app
# let's create a simple key value store: class KeyValue(peewee.Model): key = peewee.CharField(max_length=40, unique=True) text = peewee.TextField(default='') class Meta: database = database # create table synchronously KeyValue.create_table(True) # OPTIONAL: close synchronous connection database.close() # OPTIONAL: disable any future syncronous calls objects.database.allow_sync = False # this will raise AssertionError on ANY sync call app = Sanic('peewee_example') @app.route('/post/<key>/<value>') async def post(request, key, value): """ Save get parameters to database """ obj = await objects.create(KeyValue, key=key, text=value) return json({'object_id': obj.id})