コード例 #1
0
ファイル: manage.py プロジェクト: shawnjots/eventcity
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."
            )
コード例 #2
0
ファイル: tests.py プロジェクト: nikizh/stashurlinks
    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())
コード例 #3
0
 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()
コード例 #4
0
 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()
コード例 #5
0
    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()
コード例 #6
0
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()
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
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()
コード例 #10
0
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()
コード例 #11
0
    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)
コード例 #12
0
    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()
コード例 #13
0
    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)
コード例 #14
0
 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)
コード例 #15
0
 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)
コード例 #16
0
    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()
コード例 #17
0
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."
コード例 #18
0
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.")
コード例 #19
0
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)
    
コード例 #20
0
 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)
コード例 #21
0
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()
コード例 #22
0
    def test_populate(self):
        """Method to test populate command"""

        with self.app.test_request_context():
            populate()
コード例 #23
0
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
コード例 #24
0
                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()
コード例 #25
0
def initialize_db(credentials):
    with app.app_context():
        db.create_all()
        credentials = credentials.split(":")
        DataManager.create_super_admin(credentials[0], credentials[1])
        populate()
コード例 #26
0
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()
コード例 #27
0
ファイル: app.py プロジェクト: xNJL/quotes-backend
def create_tables():
    db.drop_all()
    db.create_all()
    populate()
コード例 #28
0
import populate_db
populate_db.populate()
import tests

コード例 #29
0
ファイル: webapp.py プロジェクト: thomasballinger/Utok
    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)
コード例 #30
0
def populate_db():
    populate()
コード例 #31
0
def populate_tables():

    populate_db.populate()
    create_data()
コード例 #32
0
def initialize_db(credentials):
    with app.app_context():
        db.create_all()
        credentials = credentials.split(":")
        DataManager.create_super_admin(credentials[0], credentials[1])
        populate()