def createdb(): print 'creating db..' db.drop_all() db.create_all() Role.insert_roles() print 'adding feed sources..' with open('sources.yaml', 'r') as f: feed_sources = yaml.load(f) # Insert feedprovider for site in feed_sources: provider_name = unicode(site['name']) provider_domain = site['domain'] provider = FeedProvider(name = provider_name, domain = provider_domain, favicon = site['favicon']) db.session.add(provider) db.session.commit() # Add feedsource for channel_name in site['channels']: source_name = unicode(site['name'] + ' - ' + channel_name) source_href = site['channels'][channel_name] fs = FeedSource(name=source_name, url=source_href, provider=provider) db.session.add(fs) db.session.commit() print 'add feed articles..' from app.mod_crawler.fetch import update_db update_db()
def setUp(self): app = create_app('testing') self.app = app self.ctx = app.app_context() self.ctx.push() self.client = app.test_client() 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() self.client = self.app.test_client()
def create_dev_database(): """ Use this when running a development server. It creates tables without using db migration scripts, instead asking SQLAlchemy to create them directly from your models. Good for testing/iterating. When done, write proper db migration scripts and test. """ from app import db from app.models import Role, User db.drop_all() db.create_all() admin_role = Role(name='Admin') mod_role = Role(name='Moderator') user_role = Role(name='User') db.session.add(admin_role) db.session.add(mod_role) db.session.add(user_role) user_john = User(username='******', role=admin_role, password='******', email='*****@*****.**', confirmed=True) user_susan = User(username='******', role=user_role, password='******', email='*****@*****.**', confirmed=False) user_david = User(username='******', role=user_role, password='******', email='*****@*****.**', confirmed=False) db.session.add(user_john) db.session.add(user_susan) db.session.add(user_david) 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() self.client = self.app.test_client() self.url = api.url_for(RegisterResource)
def setUp(self): app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///'+\ os.path.join(basedir, TEST_DB) self.app = app.test_client() db.create_all()
def setUp(self): """ Initialize the test cases. """ self.app = create_app(TestConfiguration) self.client = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() self.request_context = self.app.test_request_context('/') self.request_context.push() db.create_all() # Add a few test models. role_1 = Role(name='A') role_2 = Role(name='B') role_3 = Role(name='C') role_4 = Role(name='D') role_5 = Role(name='E') role_6 = Role(name='F') role_7 = Role(name='G') db.session.add(role_1) db.session.add(role_2) db.session.add(role_3) db.session.add(role_4) db.session.add(role_5) db.session.add(role_6) db.session.add(role_7) db.session.commit()
def setUpClass(cls): #start Firefox try: cls.client = webdriver.Firefox() except: pass if cls.client: #create the application cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() #suppress logging to keep unitteset output clean import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") #create database with fake user and post db.create_all() u = User(username='******', password='******', role=1) db.session.add(u) p = Post(title='test_post', body='test_post_body', user_id=u.id) db.session.add(p) db.session.commit() #start the Flask server in a thread threading.Thread(target=cls.app.run).start()
def setUpClass(cls): try: cls.client = webdriver.Firefox() except: pass if cls.client: cls.app = create_app('testing') cls.app_context = cls.app_context() cls.app_context.push() import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") db.create_all() Role.insert_roles() User.generate_fake(10) Post.generate_fake(10) admin_role = Role.query.filter_by(permissions=0xff).first() admin = User(email='*****@*****.**', username='******', password='******', role=admin_role, confirmed=True) db.session.add(admin) db.session.commit() threading.Thread(target=cls.app.run).start() time.sleep(1)
def create_user(): db.create_all() user_datastore.create_user(email='*****@*****.**', password='******') user_datastore.create_role(name='user', description='default role') user_datastore.create_role(name='server_admin', description='Admin of a Go Server') user_datastore.create_role(name='ratings_admin', description='Admin of AGA-Online Ratings') db.session.commit()
def setUp(self): """ Initialize the test cases. """ self.app = create_app(TestConfiguration) self.app_context = self.app.app_context() self.app_context.push() self.request_context = self.app.test_request_context('/') self.request_context.push() db.create_all() # Add a few test models. self.model_1 = TestModel() self.model_2 = TestModel() self.model_3 = TestModel() self.model_4 = TestModel() self.model_5 = TestModel() self.model_6 = TestModel() self.model_7 = TestModel() db.session.add(self.model_1) db.session.add(self.model_2) db.session.add(self.model_3) db.session.add(self.model_4) db.session.add(self.model_5) db.session.add(self.model_6) db.session.add(self.model_7) db.session.commit()
def test_notification_list(self): db.create_all() u1 = User(email='*****@*****.**', username='******', password='******') u2 = User(email='*****@*****.**', username='******', password='******') t = Talk(title='t', description='d', author=u1) c1 = Comment(talk=t, body='c1', author_name='n1', author_email='*****@*****.**', approved=True) c2 = Comment(talk=t, body='c2', author_name='n2', author_email='*****@*****.**', approved=True, notify=False) c3 = Comment(talk=t, body='c3', author=u2, approved=True) c4 = Comment(talk=t, body='c4', author_name='n4', author_email='*****@*****.**', approved=False) c5 = Comment(talk=t, body='c5', author=u2, approved=True) c6 = Comment(talk=t, body='c6', author_name='n6', author_email='*****@*****.**', approved=True, notify=False) db.session.add_all([u1, u2, t, c1, c2, c3, c4, c5]) db.session.commit() email_list = c4.notification_list() self.assertTrue(('*****@*****.**', 'n1') in email_list) self.assertFalse(('*****@*****.**', 'n2') in email_list) # notify=False self.assertTrue(('*****@*****.**', 'susan') in email_list) self.assertFalse(('*****@*****.**', 'n4') in email_list) # comment author self.assertFalse(('*****@*****.**', 'n6') in email_list) email_list = c5.notification_list() self.assertFalse(('*****@*****.**', 'john') in email_list) self.assertTrue(('*****@*****.**', 'n4') in email_list) # comment author
def setup(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db') self.app = app.test_client() db.create_all() def teardown(self): db.session.remove() db.drop_all() def test_avatar(self): user = User(nickname='john', email='*****@*****.**') avatar = user.avatar(128) expected = 'http://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6' assert avatar[0:len(expected)] == expected def test_make_unique_nickname(self): user = User(nickname='john', email='*****@*****.**') db.session.add(user) db.session.commit() nickname = User.make_unique_nickname('john') assert nickname != 'john' u = User(nickname = nickname, email='*****@*****.**') db.session.add(u) db.session.commit() nickname2 = User.make_unique_nickname('john') assert nickname2 != 'john' assert nickname2 != nickname
def setUp(self): db.session.close() db.drop_all() db.create_all() self.app = app.test_client() if not os.path.exists('users/'): os.makedirs('users/')
def setup(self, app): self.db_bind = 'ivr' mydbplugindir = os.path.join(app.config['BASEDIR'],'app/plugins/ivr/db/ivr.db') app.config['SQLALCHEMY_BINDS'].update({self.db_bind : 'sqlite:///%s' % mydbplugindir}) with app.app_context(): db.create_all(bind=self.db_bind)
def recreate_tables(): """ dangerous """ if query_yes_no('This will erase all data in the database. Continue?', default='no'): db.drop_all() db.create_all()
def profile_view(id_num): encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') current_id = session['id_num'] profile = Myprofile.query.get(id_num) data = Mylist.query.filter_by(id_num=current_id).all() if request.method == 'GET': for each in data: if each.id_num == current_id: return render_template('profile_view.html', profile=profile, data=data) return render_template('profile_view.html', profile=profile) else: db.create_all() url = request.form['image'] description = request.form['description'] title = request.form['title'] id_num = session['id_num'] new_list = Mylist(id_num=id_num, description=description, url=url, title=title) db.session.add(new_list) db.session.commit() payload = {'some': 'data'} jwt_token = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256') #send data to database here return redirect(url_for('profile_view', profile=profile, id_num=current_id, encoded=encoded))
def setUpClass(cls): # 启动Firefox try: cls.client = webdriver.Firefox() except: pass # 如果无法启动浏览器,则跳过这些测试 if cls.client: # 创建程序 cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() # 禁止日志,保持输出简洁 import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") # 创建数据库 db.create_all() Role.insert_role() # 添加管理员 admin_role = Role.query.filter_by(permission=0xff).first() admin = User(email='*****@*****.**', username='******', pasword='cat', role=admin_role, confirmed=True) db.session.add(admin) db.session.commit() # 在一个线程中启动Flask服务器 threading.Thread(target=cls.app.run).start()
def setUp(self): db.create_all() db.session.add(Place(name='Testname', address="123 Test st.", city="Englewood", state="Florida", zip_="34224", website="http://fake.com", phone="123-456-7899", owner="Jeff Reiher", yrs_open=1)) db.session.add(Menu(name="burger", course="dinner", description="test description", price="$1.00", place_id=1)) db.session.add(Users(username="******", email="*****@*****.**", password=bcrypt.generate_password_hash("password"), avatar="picofjeff.jpg")) db.session.commit()
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \ os.path.join(basedir, 'test.db') self.app = app.test_client() db.create_all()
def setUp(self): """Before each test, set up a blank database""" try: shutil.rmtree(self.whoosh) except OSError as err: pass db.create_all()
def setUp(self): db.create_all() self.create_author_account() self.add_story() db.session.commit()
def setUpClass(cls): try: cls.client = webdriver.Firefox() except: pass if cls.client: # create app cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() # create log import logging logger = logging.getLogger('werkzeug') logger.setLevel(logging.ERROR) # create database db.create_all() Role.init_roles() User.generate_fake(count=10) Post.generate_fake(count=10) # add admin admin_role = Role.query.filter_by(permissions=0xff).first() admin = User(email='*****@*****.**', username='******', password='******', role=admin_role, confirmed=True) db.session.add(admin) db.session.commit() # run server in child thread Thread(target=cls.app.run).start()
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 db(app, request): _db.app = app _db.create_all() yield _db _db.drop_all()
def db_create(): db.create_all() if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository') api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) else: api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
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) #测试客户端对象 (启用cookie像浏览器一样可能接收和发半发送cookie)
def setUpClass(cls): try: cls.client = webdriver.Chrome(executable_path=chrome_driver) except: pass if cls.client: # 创建 app cls.app = create_app('test') cls.app_context = cls.app.app_context() cls.app_context.push() # 建立数据库 db.create_all() setting = Settings( site_admin_email='*****@*****.**', site_initiated=True, ) db.session.add(setting) db.session.commit() user = User( name='test_user', password='******', email='*****@*****.**' ) db.session.add(user) db.session.commit() cls.host = 'http://localhost:5000' import logging logger = logging.getLogger('werkzeug') logger.setLevel("ERROR") threading.Thread(target=cls.app.run).start()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def setUpClass(cls): #launch Firefox try: cls.client = webdriver.Chrome() except: pass if cls.client: cls.app = create_app('testing') cls.app_context = cls.app.app_context() cls.app_context.push() import logging logger = logging.getLogger('werkzeug') logger.setLevel('ERROR') # create database, and fill it up with some faked data db.create_all() Role.insert_roles() User.generate_fake(10) Post.generate_fake(10) # add administrater admin_role = Role.query.filter_by(permissions=0xff).first() admin = User(email='*****@*****.**', username='******', password='******', role=admin_role, confirmed=True) db.session.add(admin) db.session.commit() # launch Flask server in a thread threading.Thread(target=cls.app.run).start() # give the server a second to ensure it is up time.sleep(1)
def setUp(self) -> None: self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def create_app(self): db.init_app(app) db.create_all() app.config['TESTING'] return app
# Create the 2 table: Users and Activities table class Users(db.Model): # Users Table # 2 attributes: ### Username (VARCHAR): unique username, primary key <50 characters ### Password (VARCHAR): user's password <50 characters __tablename__ = 'Users' Username = db.Column(db.VARCHAR(50), primary_key=True) Password = db.Column(db.VARCHAR(50), nullable=False) class Activities(db.Model): # Activities Table # 4 Attributes: ### row_id (INT): Primary Key: unique + autoincrement ### Username (VARCHAR): unique username, primary key <50 characters ### Activity (VARCHAR): Descriptions of the task < 200 characters ### Status (INT): Status of the activity (1: do; 2: doing; 3: done) __tablename__ = 'Activities' row_id = db.Column(db.Integer, primary_key=True) Username = db.Column(db.VARCHAR(50)) Activity = db.Column(db.VARCHAR(200)) Status = db.Column(db.Integer) # Initialize database db.create_all() db.session.commit()
from app import db, Countries, Cities db.create_all() # Creates all table classes defined UK = Countries(name='United Kingdom') #Add example to countries table db.session.add(UK) db.session.commit() # Here we reference the country that london belongs to useing 'country', this is what we named the backref variable in db.relationship() ldn = Cities(name='London', country=UK) mcr = Cities(name='Manchester', country=Countries.query.filter_by(name='United Kingdom').first()) db.session.add(ldn) db.session.add(mcr) db.session.commit()
def setUp(self): db.create_all()
def deploy(): db.create_all() Role.preset_roles()
def start_project(): """ start project start-project >>>db.create_all() """ db.create_all()
def init_db_user(): db.create_all() user=User('admin','meitianhui') db.session.add(user) db.session.commit()
def save_todo(): db.create_all() todo_first = Todo(content="111") todo_second = Todo(content="222") db.session.add_all([todo_first, todo_second]) db.session.commit()
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' db.create_all()
def __init__(self): db.create_all()
def create_db(): """Create tables in SQL database from SQLAlchemy models. """ db.engine.execute("CREATE EXTENSION IF NOT EXISTS postgis;") db.create_all()
def setUp(self): '''在每个测试前运行, 初始化测试环境''' db.create_all()
def setUp(self): self.app = create_app('testing') # 创建测试app self.app_context = self.app.app_context() self.app_context.push() # 激活上下文 db.create_all() # 创建数据库
def setUp(self): self.app = app.test_client() self.app.application.config['TEST'] = True self.app.application.config[ 'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' db.create_all()
# coding:utf-8 #!/usr/bin/env python from app import create_app, db from app.models import User, Bullet from flask_script import Manager, Shell app = create_app('default') manager = Manager(app) def make_shell_context(): return dict(app=app, db=db, User=User, Bullet=Bullet) manager.add_command("shell", Shell(make_context=make_shell_context)) if __name__ == '__main__': with app.app_context(): # 这两句要加 不然会出现 relation does not exist 报错 db.create_all() # 或者提前建好表应该也可以 manager.run()
def setUpClass(self): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' self.app = app.test_client() db.create_all()
def createdb(): "Create database" if prompt_bool("Do you want to create a database?"): db.create_all()
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db') db.create_all()
def init_db(): db.drop_all() db.create_all()
def db_create(): db.create_all()
def setUp(): print("Rodando setup...\n") with app.app_context(): db.create_all()