def create_db(): #第二课新增 """ Recreates a local database. You probably should not use this on production. """ db.create_all() db.session.commit()
def setUp(self): self.app = create_app(TestConfig) self.app_client = self.app.test_client() self.app_client.testing = True db.create_all() self.user = user_factoryboy.UserModelFactory() db.session.commit()
def recreate_db(): # 第二课新增 """ Recreates a local database. You probably should not use this on production. """ db.drop_all() db.create_all() db.session.commit() Role.insert_roles()
def setUp(self): self.app = self.create_app().test_client() db.create_all() res = self.app.post("/api/create_user", data=json.dumps(self.default_user), content_type='application/json') self.token = json.loads(res.data.decode("utf-8"))["token"]
def setUp(self): self.app = create_app(TestConfig) self.app_client = self.app.test_client() self.app_client.testing = True db.create_all() response = self.app_client.post( "/registration", data="{\"username\": \"test\", \"password\": \"password\"}", content_type="application/json")
def setUp(self): app.config['SECRET_KEY'] = "TestKey" app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(BASE_DIR, TEST_DB) self.app = app.test_client() db.create_all() self.joke = Joke("Sample text", 1) self.joke.save()
def setUp(self): self.client = app.test_client() # we instantiate a flask test client- db.create_all() # create the database objects # add some fixtures to the database self.user1 = User(username='******', password='******', firstname='Philip', lastname='GeLinas', isOwner=False, phone='1234567890') self.user2 = User(username='******', password='******', firstname='Tom', lastname='Brady', isOwner=True, phone='0987654321') self.property1 = Property(name='Sunset Hotel', address='1234 Pullman Ave', description='Nice place to live!', price='500', rating=4.2) self.property2 = Property(name='Bates Motel', address='9876 Cougar Dr', description='A filthy place!', price='275', rating=2.2) self.thread1 = Thread(id=7, user1='*****@*****.**', user2='*****@*****.**', subject='Classmates') self.thread2 = Thread(id=4, user1='*****@*****.**', user2='*****@*****.**', subject='Football') self.message1 = Message(id=5, threadId=7, content='Whats up!', sender='Joe', receiver='Philip') self.message2 = Message(id=8, threadId=4, content='Hey dude!', sender='Cam', receiver='Josh') db.session.add(self.user1) db.session.add(self.user2) db.session.add(self.property1) db.session.add(self.property2) db.session.add(self.thread1) db.session.add(self.thread2) db.session.add(self.message1) db.session.add(self.message2) db.session.commit()
def forge(): db.create_all() movies = [ { 'title': 'My Neighbor Totoro', 'year': '1988' }, { 'title': 'Dead Poets Society', 'year': '1989' }, { 'title': 'A Perfect World', 'year': '1993' }, { 'title': 'Leon', 'year': '1994' }, { 'title': 'Mahjong', 'year': '1996' }, { 'title': 'Swallowtail Butterfly', 'year': '1996' }, { 'title': 'King of Comedy', 'year': '1999' }, { 'title': 'Devils on the Doorstep', 'year': '1999' }, { 'title': 'WALL-E', 'year': '2008' }, { 'title': 'The Pork of Music', 'year': '2012' }, ] for item in movies: movie = Movie(title=item['title'], year=item['year']) db.session.add(movie) db.session.commit() click.echo('Done.')
def setUp(self): db.create_all() db.session.add( Event(id=1, eb_id='5', name='Check', image='https://png.pngtree.com/svg/20161216/5935bddf9c.png', desc='Check check', html='<p>Check check</p>', url='https://png.pngtree.com/svg/20161216/5935bddf9c.png', address='Check city, Atlanta', lat=0, lng=0)) db.session.commit()
def db(test_app: flask.Flask) -> flask_sqlalchemy.SQLAlchemy: from backend import db connected = False while not connected: try: db.drop_all() db.create_all() except (sqlalchemy.exc.OperationalError, psycopg2.OperationalError): time.sleep(1) else: connected = True yield db db.session.close()
def setUp(self): self.app = create_app(TestConfig) self.app_client = self.app.test_client() self.app_client.testing = True db.create_all() response = self.app_client.post( "/registration", data="{\"username\": \"test_4222\", \"password\": \"password\"}", content_type="application/json") data = json.loads(response.data) print data self.access_token = data["access_token"] self.authorization = "Bearer {}".format(self.access_token) self.headers = { "Authorization": self.authorization, "Content-Type": "application/json" }
def db(request): if not real_app.config["SQLALCHEMY_DATABASE_URI"]: pytest.skip("Database not configured") # pragma: nocover ctx = real_app.app_context() def fin(): real_db.session.close_all() real_db.drop_all() # This is a bit of a hack, since we can't use `with` ctx.__exit__(None, None, None) ctx.__enter__() request.addfinalizer(fin) real_db.session.close_all() real_db.drop_all() real_db.create_all() return real_db
def init_db(forge): """ 初始化数据库(包括生成初始数据) """ db.drop_all() db.create_all() default_data = get_default_data() db.session.add_all(default_data) if forge is True: click.confirm( "This operation will generate the todo forge data, " "do you want to continue?", abort=True) forge_data = get_forge_data() db.session.add_all(forge_data) db.session.commit() click.echo("\nInitialized database success!")
def create_db(): db.create_all()
def run(self): db.drop_all() db.create_all()
def init(): db.create_all()
def create_app(): db.init_app(app) with app.app_context(): db.create_all() return True
def setUp(self): db.create_all() backend.util.add_user(db, default_user())
def create(): """Creates all of the tables in the database.""" db.create_all() click.echo('Created all of the tables in the database.')
def create(): """Creates all of the tables in the database.""" db.create_all() print('Created all of the tables in the database.')
def setUp(self): self.app = create_app(TestConfig) self.app_client = self.app.test_client() self.app_client.testing = True db.create_all()
def recreate(): """Drops and recreates the tables in the database.""" db.drop_all() db.create_all() click.echo('Recreated all of the tables in the database.')
def test_create_db(): db.create_all()
def test_create_table(): db.create_all()
def submit_citizen_informations(): start_time = time.clock() values = request.get_json() print(values, type(values)) citizen_name = values["citizen_name"] citizen_code = values["citizen_code"] citizen_CIN = values["citizen_CIN"] citizen_id = values["citizen_id"] print('Pinging redis ... ', redis.ping()) try: db.create_all() print('Starting db ...') y = redis.get(citizen_id) a = str(citizen_code) + str(citizen_CIN) + "__id" + str(citizen_id) b = a * 9 c = base64.b64encode(hashlib.sha256(b.encode('UTF-8')).digest()) hashed_code = fbcrypt.generate_password_hash(c).decode("utf-8") if (y is None or len(y) <= 1): print('data not in the cache ...') x = Citizen.query.filter_by(citizenname=citizen_name).all() print('cheking data in db ..', x) if not x: print('Adding citizen to database ... ') citizen = Citizen(ID=citizen_id, citizenname=citizen_name, citizencin=citizen_CIN, citizenpass=hashed_code) print(citizen) db.session.add(citizen) db.session.commit() print('Setting citizen in cache ...') citizen_object = { 'citizenname': citizen_name, 'citizenpass': hashed_code, 'citizencin': citizen_CIN, } redis.set(citizen_id, json.dumps(citizen_object)) print(time.clock() - start_time) return render_template('error.html', Current_error=Citizen.query.filter_by( ID=citizen_id).first()) else: c = Citizen.query.filter_by(citizenpass=hashed_code).first() print('fetching data from database ...') citizen_object = { 'citizenname': citizen_name, 'citizenpass': hashed_code, 'citizencin': citizen_CIN, } redis.set(c.ID, json.dumps(citizen_object)) print(time.clock() - start_time) return render_template('error.html', Current_error=Citizen.query.filter_by( ID=citizen_id).first()) print('Returning data from the cache ... ') print(time.clock() - start_time) return render_template('error.html', Current_error=str( json.loads(redis.get(citizen_id)))) except Exception as e: return {'Error ': 'Message : {}'.format(e)}
#!venv/bin/python from flask.ext.script import Manager from backend import app,db from flask.ext.migrate import Migrate, MigrateCommand app.host = '0.0.0.0' app.debug = False migrate= Migrate(app,db) manager = Manager(app) manager.add_command('db',MigrateCommand) @manager.command def runapp(debug=True): if debug: host = '0.0.0.0' else: host = '127.0.0.1' return app.run(debug=debug,host=host,port=8080) #app.run(debug=True) if __name__ == "__main__": db.create_all() manager.run()
def create_db(): """Creates the db tables.""" db.create_all()
def run(self): db.create_all()
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('Initialized database')
def create_new_db(): with app.app_context(): db.create_all() db.session.commit() print("Database created successfully.")
from flask import Blueprint from flask_restful import Api from backend import server, db from backend.core import build_routes from backend.extensions import admin about_bp = Blueprint('about_bp', __name__) about_api = Api(about_bp) with server.app_context(): import backend.about.models import backend.about.views db.create_all() admin.add_view( views.AboutImageView( models.AboutImageModel, db.session, name='About Images', category='About Page' ) ) admin.add_view( views.AboutView( models.AboutPageInfo, db.session, name='About Info', category='About Page' ) ) # Inject module routes build_routes(server, about_api, "about")
def create_db(): db.drop_all() db.create_all() db.session.commit()
def init_database(): db.create_all() echo("Initialization of database.")
def init(): """Initialize empty database with tables""" db.create_all()