def initialize_db(credentials): with app.app_context(): populate_data = True inspector = reflection.Inspector.from_engine(db.engine) table_name = 'events' table_names = inspector.get_table_names() print("[LOG] Existing tables:") print("[LOG] " + ','.join(table_names)) if table_name not in table_names: print("[LOG] Table not found. Attempting creation") try: db.create_all() stamp() except Exception: populate_data = False print( "[LOG] Could not create tables. Either database does not exist or tables already created" ) if populate_data: credentials = credentials.split(":") admin_email = os.environ.get('SUPER_ADMIN_EMAIL', credentials[0]) admin_password = os.environ.get('SUPER_ADMIN_PASSWORD', credentials[1]) create_super_admin(admin_email, admin_password) populate() else: print( "[LOG] Tables already exist. Skipping data population & creation." )
def setUp(self): populate_db.populate() if 'allauth.socialaccount' in stashmarksProj.settings.INSTALLED_APPS: # Otherwise ImproperlyConfigured exceptions may occur from allauth.socialaccount.models import SocialApp sa = SocialApp.objects.create(name='testfb', provider='facebook') sa.sites.add(Site.objects.get_current())
def setUp(self): self.app = Setup.create_app() app.config['TESTING'] = True app.secret_key = 'super secret key' app.config['PROFILE'] = True app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) with app.test_request_context(): db.create_all() populate()
def create_app(): app.config.from_object('config.TestingConfig') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() set_settings(secret='super secret key', app_name='Open Event', app_environment=Environment.TESTING) return app.test_client()
def initialize_db(): with app.app_context(): populate_data = True try: db.drop_all() db.create_all() stamp() except Exception: populate_data = False print("[LOG] Could not create tables. Either database does not exist or tables already created") if populate_data: populate()
def test_role_delete(self): with app.test_request_context(): event = ObjectMother.get_event() event.creator = self.super_admin save_to_db(event, "Event saved") user = ObjectMother.get_user() save_to_db(user, "New user saved") populate() role = Role.query.filter_by(name='coorganizer').first() uer = UsersEventsRoles(user, event, role) save_to_db(uer, "UER Saved") rv = self.app.get(url_for('event_roles.delete_view', uer_id=uer.id, event_id=event.id), follow_redirects=True) uer = UsersEventsRoles.query.get(uer.id) self.assertTrue(uer is None, msg=rv.data)
def initialize_db(credentials): with app.app_context(): populate_data = True inspector = reflection.Inspector.from_engine(db.engine) table_name = 'events' table_names = inspector.get_table_names() if table_name not in table_names: try: db.create_all() stamp() except: populate_data = False print "Could not create tables. Either database does not exist or tables already created" if populate_data: credentials = credentials.split(":") DataManager.create_super_admin(credentials[0], credentials[1]) populate()
def test_role_create_post(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") user = ObjectMother.get_user() save_to_db(user, "New user saved") populate() data = { 'user_email': user.email, 'user_role': 'coorganizer' } rv = self.app.post(url_for('event_roles.create_view', event_id=event.id), follow_redirects=True, data=data) # Check if user has been sent a Role Invite role = Role.query.filter_by(name='coorganizer').first() ri = RoleInvite.query.filter_by(email=user.email, event=event, role=role).first() self.assertTrue(ri is not None, msg=rv.data)
def create_app(): # app.config.from_object('config.TestingConfig') app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG_TB_ENABLED'] = False app.config['CELERY_ALWAYS_EAGER'] = True app.config['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = True app.config['BROKER_BACKEND'] = 'memory' # app.config['CELERY_BROKER_URL'] = '' # app.config['CELERY_RESULT_BACKEND'] = '' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(_basedir, 'test.db') app.secret_key = 'super secret key' celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() return app.test_client()
def test_role_create_post(self): with app.test_request_context(): event = ObjectMother.get_event() event.creator = self.super_admin save_to_db(event, "Event saved") user = ObjectMother.get_user() save_to_db(user, "New user saved") populate() data = { 'user_email': user.email, 'user_role': 'coorganizer' } rv = self.app.post(url_for('event_roles.create_view', event_id=event.id), follow_redirects=True, data=data) # Check if user has been sent a Role Invite role = Role.query.filter_by(name='coorganizer').first() ri = RoleInvite.query.filter_by(email=user.email, event=event, role=role).first() self.assertTrue(ri is not None, msg=rv.data)
def test_role_update(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") user = ObjectMother.get_user() save_to_db(user, "New user saved") populate() role = Role.query.filter_by(name='coorganizer').first() uer = UsersEventsRoles(user, event, role) save_to_db(uer, "UER Saved") data = { 'user_email': user.email, 'user_role': 'track_organizer' } rv = self.app.post(url_for('event_roles.edit_view', uer_id=uer.id, event_id=event.id), data=data, follow_redirects=True) uer = DataGetter.get_user_event_roles_by_role_name(event.id, 'track_organizer').first() self.assertTrue(uer is not None, msg=rv.data)
def test_role_update(self): with app.test_request_context(): event = ObjectMother.get_event() event.creator = self.super_admin save_to_db(event, "Event saved") user = ObjectMother.get_user() save_to_db(user, "New user saved") populate() role = Role.query.filter_by(name='coorganizer').first() uer = UsersEventsRoles(user, event, role) save_to_db(uer, "UER Saved") data = { 'user_email': user.email, 'user_role': 'track_organizer' } rv = self.app.post(url_for('event_roles.edit_view', uer_id=uer.id, event_id=event.id, data=data), follow_redirects=True) uer = DataGetter.get_user_event_roles_by_role_name(event.id, 'track_organizer').first() self.assertTrue(uer is not None, msg=rv.data)
def create_app(): # app.config.from_object('config.TestingConfig') app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG_TB_ENABLED'] = False app.config['CELERY_ALWAYS_EAGER'] = True app.config['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = True app.config['BROKER_BACKEND'] = 'memory' # app.config['CELERY_BROKER_URL'] = '' # app.config['CELERY_RESULT_BACKEND'] = '' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(_basedir, 'test.db') app.secret_key = 'super secret key' app.logger.addHandler(logging.StreamHandler(sys.stdout)) app.logger.setLevel(logging.ERROR) celery.conf.update(app.config) with app.test_request_context(): db.create_all() populate() set_settings(secret='super secret key', app_name='Open Event') return app.test_client()
def initialize_db(credentials): with app.app_context(): populate_data = True inspector = reflection.Inspector.from_engine(db.engine) table_name = 'events' table_names = inspector.get_table_names() print "[LOG] Existing tables:" print "[LOG] " + ','.join(table_names) if table_name not in table_names: print "[LOG] Table not found. Attempting creation" try: db.create_all() stamp() except: populate_data = False print "[LOG] Could not create tables. Either database does not exist or tables already created" if populate_data: credentials = credentials.split(":") create_super_admin(credentials[0], credentials[1]) populate() else: print "[LOG] Tables already exist. Skipping data population & creation."
def initialize_db(credentials): with app.app_context(): populate_data = True inspector = reflection.Inspector.from_engine(db.engine) table_name = 'events' table_names = inspector.get_table_names() print("[LOG] Existing tables:") print("[LOG] " + ','.join(table_names)) if table_name not in table_names: print("[LOG] Table not found. Attempting creation") try: db.create_all() stamp() except Exception: populate_data = False print("[LOG] Could not create tables. Either database does not exist or tables already created") if populate_data: credentials = credentials.split(":") create_super_admin(credentials[0], credentials[1]) populate() else: print("[LOG] Tables already exist. Skipping data population & creation.")
Created on Nov 29, 2011 script for poplulating first image data @author: boyusun ''' import sys import populate_db import pymongo db_name = 'astro' cll_name = 'first_image' if __name__ == '__main__': if len(sys.argv) < 2: print "Error: please give a input file(json format)" sys.exit() from_file = sys.argv[1] conn = pymongo.Connection() db = conn[db_name] cll = db[cll_name] populate_db.drop(db_name, cll_name) assert(cll_name not in db.collection_names()) populate_db.populate(db_name, cll_name, from_file) assert(cll.count() > 0) cll.create_index([('loc', pymongo.GEO2D)], min=-90000, max = 90000) #create index assert(len(cll.index_information()) > 1)
def testPopulate(self): populate_db.drop(db_name, cll_name) populate_db.populate(db_name, cll_name, import_file) self.assertFalse(self.db.last_status()['err']) self.assertEqual(self.first_image_cll.count(), 10000)
from populate_db import populate from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from pandas.io.sql import read_sql # create_engine()用来初始化数据库连接。 # SQLAlchemy用一个字符串表示连接信息:'数据库类型+数据库驱动名称://用户名:口令@机器地址:端口号/数据库名' engine = create_engine( 'mysql+mysqlconnector://user:password@hostname:port/dbname') #找到Base下的所有子类,并在数据库中建立这些表 Base.metadata.create_all(engine) populate(engine) Base.metadata.bind = engine DBSession = sessionmaker() DBSession.bind = engine session = DBSession() print "进行读取操作" # 获取School对象中的第一条数据 print "第一条记录", session.query(School).first() # 获取所有数据 query = session.query(School) print "Query 1", query.all()
def test_populate(self): """Method to test populate command""" with self.app.test_request_context(): populate()
from alchemy_entities import Base, Sensor, Station from populate_db import populate from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import os from pandas.io.sql import read_sql engine = create_engine('sqlite:///demo.db') Base.metadata.create_all(engine) populate(engine) Base.metadata.bind = engine DBSession = sessionmaker() DBSession.bind = engine session = DBSession() station = session.query(Station).first() print "Query 1", session.query(Station).all() print "Query 2", session.query(Sensor).all() print "Query 3", session.query(Sensor).filter(Sensor.station == station).one() print read_sql("SELECT * FROM station", engine.raw_connection()) try: os.remove('demo.db') print "Deleted demo.db" except OSError: pass
continue ask_email = False if not password: ask_password = True while ask_password: password = getpass.getpass("Enter password for super_admin: ") if len(password) < 8: print('\nPassword should have minimum 8 characters') continue repassword = getpass.getpass("Enter your password again to confirm: ") if password != repassword: print('\nPassword did not match') continue ask_password = False create_super_admin(email, password) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("email", nargs='?', help="The email for super_admin.", default='') parser.add_argument( "password", nargs='?', help="The password for super_admin.", default='' ) parsed = parser.parse_args() with current_app.app_context(): db.engine.execute('create extension if not exists citext') db.create_all() stamp() create_default_user(parsed.email, parsed.password) populate()
def initialize_db(credentials): with app.app_context(): db.create_all() credentials = credentials.split(":") DataManager.create_super_admin(credentials[0], credentials[1]) populate()
from populate_db import populate def _validate_email(email): if not re.match(r'[^@]+@[^@]+\.[^@]+', email): print '\nInvalid email address' sys.exit(1) def _validate_password(password): if len(password) < 4: print '\nPassword should have minimum 4 characters' sys.exit(1) def create_default_user(): print "Your login is 'super_admin'." email = raw_input("Enter email for super_admin : ") _validate_email(email) password = getpass("Enter password for super_admin : ") _validate_password(password) DataManager.create_super_admin(email, password) if __name__ == "__main__": with current_app.app_context(): db.create_all() stamp() create_default_user() populate()
def create_tables(): db.drop_all() db.create_all() populate()
import populate_db populate_db.populate() import tests
else: cmd = None d = textDisplay.Display(g) s = d.get() return render_template('textgame.html', gameEntry=gameEntry, game=g, command=cmd, gamestring=s) @app.route('/game/<int:game_id>/cmd/<path:command>') def input_command(game_id, command): words = command.split('/') gameEntry = models.GameEntry(game_id) g = gameEntry.game g = play_cli.run_command_on_game(g, ' '.join(words)) gameEntry.update_game(g) d = textDisplay.Display(g) s = d.get() return render_template('textgame.html', gameEntry=gameEntry, game=g, command=' '.join(words), gamestring=s) @app.route('/game/graphics/<int:game_id>/') def display_game_graphics(game_id): pass if __name__ == '__main__': import populate_db populate_db.populate() port = int(os.environ.get("PORT", 5000)) app.run('0.0.0.0', port=port)
def populate_db(): populate()
def populate_tables(): populate_db.populate() create_data()