def initdb(): """Init/reset database.""" if not prompt_bool("Are you sure? You will lose all your data!"): return db.drop_all() db.create_all() demo = User( username=u'demo', email='*****@*****.**', password='******', role_id=USER, status_id=ACTIVE, user_detail=UserDetail( first_name=u'Demo', last_name=u'Dude', gender=u'female', dob=datetime.date(1985, 02, 17), phone=1234567890, bio=u'Demo dude is pretty sweet.', url=u'http://www.example.com/demo', ), )
def initdb(): """Init/reset database.""" db.drop_all(bind=None) db.create_all(bind=None) admin = User( first_name=u"admin", last_name=u"admin", user_name=u"admin", password=u"123456", role_code=ADMIN, status_code=ACTIVE, user_settings=UserSettings( sex_code=MALE, age=10, phone="555-555-5555", bio=u"admin Guy is ... hmm ... just a admin guy." ), ) email = Email(address="*****@*****.**", is_primary=True, status_code=VERIFIED) admin.add_email(email) db.session.add(admin) db.session.add(email) db.session.commit() hashtag = None """Add in all post hashtag""" for (key, id) in CATEGORIES.iteritems(): hashtag = Hashtag(id=id, name=key) db.session.add(hashtag) db.session.commit() # generate 1000 random post """ for x in range(0,1000): post = Post(name='test-'+str(x), price=10, description='AOH LALAL') post.user_id = admin.id post.add_hashtag(hashtag) db.session.add(post) db.session.commit() chat = Chat(buyer= admin) msg = ChatMessage(body = "TEST MESSAGE", created_by = admin.id) post.add_chat(chat) chat.add_message(msg) db.session.commit() db.session.commit() """ # Add in ucla circle ucla = Circle(name=u"ucla", description=u"ucla.edu emails only") ucla.add_member(admin) db.session.add(ucla) db.session.commit() ucla_info = CollegeInfo( circle_id=ucla.id, domain=u"ucla.edu", fb_group_id=267279833349705, fb_sell_id=267375200006835 ) db.session.add(ucla_info) db.session.commit()
def clear_db(): """Drops and creates all db tables. (DESTRUCTIVE).""" if prompt_bool("May I drop and re-create all database tables"): app.logger.info('dropping all tables...') db.drop_all() app.logger.info('creating all tables...') db.create_all()
def flask_app(): app = create_app(flask_config='testing') from app.extensions import db with app.app_context(): db.create_all() yield app db.drop_all()
def db(app, request): _db.app = app _db.create_all() yield _db _db.drop_all() os.unlink(TESTDB_PATH)
def resetdb(): """Init/reset database.""" if not prompt_bool("Are you sure? You will lose all your data!"): return db.drop_all() db.create_all() db.session.commit()
def import_db_from_json(): """Imports a collection of links from a 'db.json' file (DESTRUCTIVE).""" app.logger.info(app.config.get('SQLALCHEMY_DATABASE_URI')) with open('db.json') as f: if prompt_bool("May I import links from 'db.json'"): app.logger.info('dropping all tables...') db.drop_all() app.logger.info('creating all tables...') db.create_all() content = json.load(f) app.logger.info('importing users...') if 'users' in content: for u in content['users']: user = User(email=u['email']) g.user = user user.locale = u.get('locale', '') user.timezone = u.get('timezone', '') user.is_active = u.get('is_active', True) db.session.add(user) db.session.commit() app.logger.info('importing tags...') tags = [] for t in content.get('links', []): tagname = t.get('tag', '') if not tagname in tags: tags.append(tagname) for tagname in tags: tag = Tag.query.filter_by(name=tagname).first() if tag is None: try: tag = Tag(name=tagname) db.session.add(tag) except Exception, e: app.logger.error('error creating tag "%s"' % e) continue db.session.commit() app.logger.info('importing bookmarks...') for l in content.get('links', []): link = Bookmark(name=l['name'], url=l['url']) link.menu = l.get('menu', None) link.public = l.get('public', False) link.clicks = l.get('clicks', 0) if 'user_email' in l: user = User.query.filter_by(email=l['user_email']).first() link.user_id = user.id # for tagname in l.get('tags', []): tagname = l.get('tag', '') tag = Tag.query.filter_by(name=tagname).first() link.tags.append(tag) db.session.add(link) db.session.commit()
def init_db(): """ Clean up and create database. """ app = Flask(__name__) load_config(app) db.init_app(app) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'app.sqlite') with app.app_context(): db.drop_all() db.create_all()
def initdb(): db.drop_all(bind=None) db.create_all(bind=None) # add sample user user = Models.User( first_name=u'Sam', last_name=u'Chuang', user_name=u'spchuang', password=u'123456', email=u"*****@*****.**") db.session.add(user) db.session.commit()
def initdb(): "Reinitialise the database" db.drop_all(bind=None) db.create_all(bind=None) # add sample user user = Models.User( first_name=u'Admin', last_name=u'Root', user_name=u'admin', password=u'123456', email=u"*****@*****.**", role_code=1) db.session.add(user) db.session.commit()
def forge(tags, post, comment): """Generate fake data.""" from app.faker import fake_admin, fake_tags, fake_posts, fake_comments db.drop_all() db.create_all() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d categories...' % tags) fake_tags(tags) click.echo('Generating %d posts...' % post) fake_posts(post) click.echo('Generating %d comments...' % comment) fake_comments(comment) click.echo('Done.')
def db(app): """ Setup our database , this only gets executed once per session. :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() #create a single user because a lot of tests do not mutatate this user. #It will result in faster tests. # Create new entries in the database admin = User(app.config['SEED_ADMIN_EMAIL'],"admin",app.config['SEED_ADMIN_PASSWORD'],True) _db.session.add(admin) _db.session.commit() return _db
def setup_environment(fake_data): """Cli command to setup the development environment. Starts up Elasticsearch, sets up the database and inserts fake data into the database if request. """ app.sqlalchemy_search_middleware._elasticsearch_client.delete_index( Event.__tablename__) db.drop_all() db.create_all() # create or update roles, event types, categories, and image types Role.insert_roles() EventType.insert_event_types() EventCategory.insert_event_categories() ImageType.insert_image_types() # add fake data to the database if fake_data: fake = FakeDataGenerator(48, 48) fake.add_all()
def initdb(): """Init/reset database.""" db.drop_all(bind=None) db.create_all(bind=None) admin = User( first_name=u'admin', last_name=u'admin', user_name=u'admin', password=u'gFcPU5XB', role_code=ADMIN, status_code=ACTIVE, user_settings=UserSettings( sex_code=MALE, age=10, phone='555-555-5555', bio=u'')) email = Email(address= "*****@*****.**", is_primary=True, status_code=VERIFIED) admin.add_email(email) db.session.add(admin) db.session.add(email) db.session.commit() hashtag = None """Add in all post hashtag""" for (key,id) in CATEGORIES.iteritems(): hashtag = Hashtag(id=id, name = key) db.session.add(hashtag) db.session.commit() #Add in ucla circle ucla = Circle(name=u'ucla', description=u'ucla.edu emails only') ucla.add_member(admin) db.session.add(ucla) db.session.commit() ucla_info = CollegeInfo(circle_id = ucla.id, domain=u'ucla.edu',fb_group_id=267279833349705, fb_sell_id=267375200006835) db.session.add(ucla_info) db.session.commit()
def init(with_testdb): """ Initialize the database. :param with_testdb: Create a test database :return: None """ db.drop_all() from app.blueprints.api.apps.app_functions import get_apps, create_db_apps db.create_all() if with_testdb: db_uri = '{0}_test'.format(app.config['SQLALCHEMY_DATABASE_URI']) if not database_exists(db_uri): create_database(db_uri) apps = get_apps() create_db_apps(apps)
def setUp(self): """ Setup the test driver and create test users """ self.driver = webdriver.Chrome() # Gets the home URL self.driver.get(self.get_server_url()) db.session.commit() db.drop_all() db.create_all() # Create test admin user self.admin = Employee(username=test_admin_username, email=test_admin_email, password=test_admin_password, is_admin=True) # Create test employee user self.employee = Employee(username=test_employee1_username, first_name=test_employee1_first_name, last_name=test_employee1_last_name, email=test_employee1_email, password=test_employee1_password) # create test department self.department = Department(name=test_department1_name, description=test_department1_description) # create test role self.role = Role(name=test_role1_name, description=test_role1_description) # save users to database db.session.add(self.admin) db.session.add(self.employee) db.session.add(self.department) db.session.add(self.role) db.session.commit()
def forge(user, photo, tag, comment, collect, follow): """Generate fake data.""" from app.fakes import fake_admin, fake_user, fake_photo, fake_user_diff_kinds,\ fake_tag, fake_comment, fake_collect, fake_follow db.drop_all() db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d users...' % user) fake_user(user) click.echo('Generating users with special status...') fake_user_diff_kinds() click.echo('Generating %d follows...' % follow) fake_follow(follow) click.echo('Generating %d tag...' % tag) fake_tag(tag) click.echo('Generating %d photo...' % photo) fake_photo(photo) click.echo('Generating %d comment...' % comment) fake_comment(comment) click.echo('Generating %d collect... ' % collect) fake_collect(collect) click.echo('Done.')
def db(app): """ Setup our database, this only gets executed once per session. :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() # Create a single user because a lot of tests do not mutate this user. # It will result in faster tests. params = { 'role': 'admin', 'email': '*****@*****.**', 'password': '******' } admin = User(**params) _db.session.add(admin) _db.session.commit() return _db
def reset_bi(): """ ReCreate Database and Seed """ db.drop_all(bind=None) db.create_all(bind=None) init_bi_user_import_config() init_bi_user_bill_import_config() init_bi_user_currency_import_config() init_bi_clubwpt_user_import_config() user = AdminUser(email='*****@*****.**', password='******', timezone='EST') user.name = "Test Account" db.session.add(user) user = AdminUser(email='*****@*****.**', password='******', timezone='EST') user.name = "Test1 Account" db.session.add(user) db.session.commit()
def fake(user, follow, collect, post, category, comment): """生成假数据""" from app.fake import fake_admin, fake_user, fake_comment, \ fake_follow, fake_post, fake_category, fake_collect db.drop_all() db.create_all() click.echo('初始化用户角色与权限...') Role.init_role() click.echo('生成管理员...') fake_admin() click.echo('生成%d个用户...' % user) fake_user(user) click.echo('生成%d个关注...' % follow) fake_follow(follow) click.echo('生成%d个类别...' % category) fake_category(category) click.echo('生成%d篇博文......' % post) fake_post(post) click.echo('生成%d条评论...' % comment) fake_comment(comment) click.echo('生成%d个收藏...' % collect) fake_collect(collect) click.echo('数据生成完毕。')
def refresh(): db.drop_all() db.create_all() make_test_data()
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
def tearDown(self): db.session_remove() db.drop_all()
def tearDown(self): db.drop_all() os.unlink(self.app.config['DATABASE']) self.browser.quit()
def teardown(): db.session.commit() db.drop_all() mysql_engine.execute('DROP DATABASE {}'.format( app.config.get('DB_NAME')))
def tearDown(self): db.drop_all() self.context.pop()
def dropdb(): "Drops all database tables" if prompt_bool("Are you sure ? You will lose all your data!"): db.drop_all()
def setUp(self): db.drop_all() db.create_all()
def drop_tables(self): db.drop_all() db.session.commit()
def drop_db(): "Drops the current database" db.drop_all(bind=None)
def tearDown(self): """Clean db session and drop all tables.""" db.drop_all() self.ctx.pop()
def initdb(): """ Initialize database setup. """ db.drop_all() db.create_all()
def tearDown(self): """测试用例执行完毕后启动""" db.session.remove() db.drop_all() self.app_context.pop()
def tearDown(self): with self.app.app_context(): db.session.remove() db.drop_all()
def restartdb(): " Drop every entry on DB and create new tables " db.drop_all(bind=None) db.create_all(bind=None)
def tearDown(self): """Clean db session and drop all tables.""" db.session.remove() db.drop_all()
def initdb(): db.drop_all() db.create_all()
def initdb(): db.drop_all(bind=None) db.create_all(bind=None)
def rebuild(): db.drop_all() db.create_all()
def setUp(self): super(CLITestCase, self).setUp() db.drop_all()
def dropdb(): """Deletes the database.""" db.drop_all()
def initdb(): """Init/reset database.""" db.init_app(app) metadata = MetaData(db.engine) metadata.reflect() for table in metadata.tables.values(): for fk in table.foreign_keys: db.engine.execute(DropConstraint(fk.constraint)) db.drop_all() db.create_all() # create tasks db.session.add_all([ Task(identifier='mass_m', name='Mass - Metric'), Task(identifier='mass_i', name='Mass - Imperial'), Task(identifier='mass_c', name='Mass - Combined'), Task(identifier='length_m', name='Length - Metric'), Task(identifier='length_i', name='Length - Imperial'), Task(identifier='length_c', name='Length - Combined'), Task(identifier='area', name='Area'), Task(identifier='temperature_m', name='Temperature'), Task(identifier='temperature_i', name='Temperature'), Task(identifier='temperature_c', name='Temperature'), Task(identifier='currency_czk', name='Currency - CZK'), Task(identifier='currency_eur', name='Currency - EUR'), Task(identifier='currency_usd', name='Currency - USD'), ]) # create test data test_task = Task(identifier='test', name='Test') sortA1 = SortAnswer(value="36", unit="in", presented_pos=0) sortA2 = SortAnswer(value="1", unit="ft", presented_pos=1) sortA3 = SortAnswer(value="12", unit="m", presented_pos=2) sortA4 = SortAnswer(value="1", unit="km", presented_pos=3) closeA1 = CloseEndedAnswer(value="3", unit="yd", correct=False) closeA2 = CloseEndedAnswer(value="10", unit="in", correct=False) closeA3 = CloseEndedAnswer(value="1", unit="yd", correct=True) closeA4 = CloseEndedAnswer(value="1", unit="yd", correct=True) closeA5 = CloseEndedAnswer(value="11", unit="cm", correct=False) db.session.add_all([ test_task, ScaleQuestion(scale_min=0, scale_max=10, from_value=6, from_unit="lb", to_unit="kg", tasks=[test_task]), CurrencyQuestion(from_value=300, from_unit="CZK", to_unit="EUR", tasks=[test_task]), NumericQuestion(from_value=5, from_unit="m", to_unit="ft", tasks=[test_task], image_name="car"), NumericQuestion(from_value=5, from_unit="m", to_unit="ft", tasks=[test_task]), sortA1, sortA2, sortA3, sortA4, SortQuestion(dimensionality="length", order="asc", answers=[sortA1, sortA2, sortA3, sortA4], tasks=[test_task]), closeA1, closeA2, closeA3, CloseEndedQuestion(question_en="bicycle", question_type="estimate_height", answers=[closeA1, closeA2, closeA3], tasks=[test_task]), CloseEndedQuestion(question_en="bicycle", question_type="estimate_height", answers=[closeA4, closeA5], tasks=[test_task], image_name="bicycle"), ]) db.session.commit()
def initialize_database(): db.drop_all() # delete on production. should insert a condition here db.create_all()
def drop_all(): db.drop_all()
def test_datbase(): db.create_all() yield db db.session.remove() db.drop_all()
def dropdb(): if prompt_bool("Are you sure? You will lose all your data!"): db.drop_all()
def tearDown(self): db.session.remove() db.drop_all() db.create_all()
def tearDown(self): '''每个测试之后执行''' db.session.remove() db.drop_all() # 删除所有数据库表 self.app_context.pop() # 退出Flask应用上下文
def tearDown(self): with self.app.app_context(): db.drop_all()
def db(app): database.create_all() yield database database.drop_all()
def setUp(self): self.app = create_app("testing") with self.app.app_context(): db.drop_all() db.create_all() self.create_fixtures()
def initdb(): """Init/reset database.""" db.drop_all() db.create_all()
def tearDown(self): """Очистка параметров после каждого теста""" db.session.remove() db.drop_all()
def teardown_class(cls): with cls.app.app_context(): db.drop_all()
def run(self): db.drop_all() db.create_all() generator = InitDataGenerator() generator.init_all()
def tearDown(self): self.app.logger.debug('tearDown') db.session.remove() db.drop_all()