Example #1
0
def resetdb():

    from app.utils import timedelta
    import datetime
    db.drop_all()
    db.create_all()
    Problem.import_from_hustoj()
    Role.insert_role()
    admin = User(email = '*****@*****.**', username = '******', password = '******', confirmed = True,
                role = Role.query.filter_by(name = "Administrator").first())
    db.session.add(admin)
    db.session.commit()

    judger = User(email = "*****@*****.**", username = "******", password = "******", confirmed = True, 
                role = Role.query.filter_by(name = "Judger").first())
    db.session.add(judger)
    db.session.commit()

    judger = User(email = "*****@*****.**", username = "******", password = "******", confirmed = True, 
                role = Role.query.filter_by(name = "Judger").first())
    db.session.add(judger)
    db.session.commit()

    contest = Contest(title = "test", 
                     begin_time = datetime.datetime.utcnow() - timedelta(hours = 10),
                     end_time = datetime.datetime.utcnow() + timedelta(hours = 10))

    db.session.add(contest)

    for i in range(8):
        cp = ContestProblem(contest_id = 1, problem_id = i + 1, problem_relative_id = i)
        db.session.add(cp)

    db.session.commit()
Example #2
0
 def tearDown(self):
     """
         Reset the test cases.
     """
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Example #3
0
 def tearDown(self):
     '''
     数据库和程序上下文在 tearDown() 方法中删除。
     '''
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Example #4
0
	def tearDown(self):
		"""Remove data from database"""
		assert self.cls_initialized
		db.drop_all()
		self.cls_initialized = False

		print('TestWeb Class Teardown\n')
def teardown():
    app = create_app('test')
    with app.app_context():
        db.session.remove()
        db.drop_all()
        db.engine.execute("drop table alembic_version")
        db.get_engine(app).dispose()
Example #6
0
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()
Example #7
0
 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/')
Example #8
0
def db(app, request):
    _db.app = app
    _db.create_all()

    yield _db

    _db.drop_all()
Example #9
0
	def tearDown(self):
		"""database removal"""
		assert self.cls_initialized
		db.drop_all()
		self.cls_initialized = False

		print('TestAPI Class Teardown\n')
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()
Example #11
0
 def teardown():
     _db.session.rollback()
     _db.session.remove()
     if _db.engine.dialect.name == 'postgresql':
         _db.engine.execute('drop schema if exists public cascade')
         _db.engine.execute('create schema public')
     _db.drop_all()
Example #12
0
 def tearDown(self):
     """ Flask will automatically remove database sessions at 
     the end of the request or when the application shuts down
     """
     db.session.remove() # close the session
     db.drop_all()
     self.app_context.pop()
Example #13
0
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()
Example #14
0
def dropdb():
    """Drops database tables"""
    if prompt_bool("Are you sure you want to lose all your data"):
        destroy_db()
        db.drop_all()
        db_setup()
        db.create_all()
Example #15
0
def recreate_data():
    """Generate fake data for development and testing"""
    print 'dropping existing tables...'
    db.drop_all()
    print 'creating tables...'
    db.create_all()
    print 'inserting roles...'
    Role.insert_roles()
    print 'creating admin user...'
    u1 = User(username='******', email='*****@*****.**', password='******',
              name='Ralph Wen', location='Hangzhou, China',
              about_me='This is the creator of everything', confirmed=True)
    db.session.add(u1)
    print 'creating moderate user...'
    u2 = User(username='******', email='*****@*****.**', password='******',
              name='Yadong Wen', location='Hangzhou, China',
              about_me='Yeah', confirmed=True)
    db.session.add(u2)
    db.session.commit()
    print 'generating 50 normal users...'
    User.generate_fake(50)
    print 'generating 500 posts...'
    Post.generate_fake(500)
    print 'generating follows...'
    User.generate_following()
    print 'generating comments...'
    Comment.generate_comments()
    print '...done'
Example #16
0
def teardown_func():
    "tear down test fixtures"
    db.session.remove()
    db.drop_all()
    app.config.from_object('config.DevelopmentConfig')
    app.config['WTF_CSRF_ENABLED'] = True
    app.config['CSRF_ENABLED'] = True
Example #17
0
def recreateDatabase():
    """
    Function to recreate database tables, make a user for testing,
    and create application roles.
    """
    print("Dropping and recreating database tables.")
    db.drop_all()
    db.create_all()
    print("Cleansing user uploads folder.")
    shutil.rmtree('app/static/uploads/1/')
    os.mkdir('app/static/uploads/1')
    os.chmod('app/static/uploads/1', mode=0o777)
    print("Creating application roles and first user.")
    user = User(password=bc.generate_password_hash('la73ralu5', rounds=12),
            user_name='cshaw')
    from app.roles import active_role, admin_role, verified_role
    db.session.add(admin_role)
    db.session.add(active_role)
    db.session.add(verified_role)
    db.session.flush()
    user.roles.append(admin_role)
    user.roles.append(active_role)
    user.roles.append(verified_role)
    db.session.add(user)
    db.session.commit()
Example #18
0
	def recreate_schema(test_class):
		# print 'Re-creating db schema for environmet %s'%flapp.config['REDIS_PREFIX']
		db.session.remove()
		db.drop_all()
		db.create_all()
		# setup_func(test_class)
		return setup_func
Example #19
0
def forged():
    from forgery_py import basic, lorem_ipsum, name, internet, date
    from random import randint
    db.drop_all()
    db.create_all()
    Role.seed()
    guests = Role.query.first()
    def generate_comment(func_author, func_post):
        return Comment(body=lorem_ipsum.paragraphs(),
                       created=date.date(past=True),
                       author=func_author(),
                       post=func_post())
    def generate_post(func_author):
        return Post(title=lorem_ipsum.title(),
                    body=lorem_ipsum.paragraphs(),
                    created=date.date(),
                    author=func_author())
    def generate_user():
        return User(name=internet.user_name(),
                    email=internet.email_address(),
                    password=basic.text(6, at_least=6, spaces=False),
                    role=guests)
    users = [generate_user() for i in range(0, 5)]
    db.session.add_all(users)
    random_user = lambda: users[randint(0, 4)]
    posts = [generate_post(random_user) for i in range(0, randint(50, 200))]
    db.session.add_all(posts)
    random_post = lambda: posts[randint(0, len(posts) - 1)]
    comments = [generate_comment(random_user, random_post) for i in range(0, randint(2, 100))]
    db.session.add_all(comments)
    db.session.commit()
Example #20
0
 def tearDown(self):
     # ?
     db.session.remove()
     # drop tables
     db.drop_all()
     # pop app context
     self.app_context.pop()
Example #21
0
    def setUp(self):
        self.app = create_app('testing')

        # app context
        self.app_context = self.app.app_context()
        self.app_context.push()

        # drop database in case it exissts, and create new version
        db.drop_all()
        db.create_all()

        # test client
        self.client = self.app.test_client()

        # stormpath client
        self.sp_client = Client(
            id=environ.get('STORMPATH_API_KEY_ID'),
            secret=environ.get('STORMPATH_API_KEY_SECRET'),
        )

        # retrieve photog_test application instance
        href = 'https://api.stormpath.com/v1/applications/Nq2qQQegOh9a9qJRekxeA'
        self.application = self.sp_client.applications.get(href)

        self.test_email = '*****@*****.**'
        self.test_password = '******'

        self.user = self.create_default_user()
Example #22
0
def rebuild():
    if config == 'development':
        with app.app_context():
            db.drop_all()
            db.create_all()
            Role.insert_roles()
            admin_me = User(email=app.config['FLASKR_ADMIN'],
                            username=app.config['MY_USERNAME'],
                            password=app.config['MY_PASSWORD'],
                            confirmed=True,
                            name=forgery_py.name.full_name(),
                            location=forgery_py.address.city(),
                            about_me=forgery_py.lorem_ipsum.sentences(10),
                            member_since=forgery_py.date.date(True,
                                                              min_delta=10))
            db.session.add(admin_me)
            ordinary_me = User(email=forgery_py.internet.email_address(),
                               username='******',
                               password='******',
                               confirmed=True,
                               name=forgery_py.name.full_name(),
                               location=forgery_py.address.city(),
                               about_me=forgery_py.lorem_ipsum.sentences(10),
                               member_since=forgery_py.date.date(True,
                                                                 min_delta=10))
            db.session.add(ordinary_me)
            db.session.commit()
            User.generate_fake(30)
            Post.generate_fake(500)
            Follow.generate_fake(500)
            Comment.generate_fake(500)
    else:
        print('Permission denied.')
Example #23
0
def init_data():
    from app import db
    db.drop_all()
    db.create_all()
    User.init_data()
    Category.init_data()
    return 'ok'
Example #24
0
def init():
    """ Fixture for test initialisation
    """
    # App configuration overide
    app.config['TESTING'] = True
    app.config['WTF_CSRF_ENABLED'] = False
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
    app.config['SERVER_NAME'] = 'localhost'
    # DB creation
    db.create_all()
    user = User(nickname='utest',
                email='*****@*****.**',
                password='******',
                active=True,
                confirmed_at=datetime.utcnow(),
                auth_token='ddg56@dgfdG°dkjvk,')
    db.session.add(user)
    db.session.commit()
    # Context setup
    context = app.app_context()
    context.push()
    yield
    db.session.remove()
    db.drop_all()
    context.pop()
Example #25
0
def remove_database(app, db):
    db.session.remove()
    db.drop_all()
    try:
        os.remove(app.config['TEST_DB_FILEPATH'])
    except FileNotFoundError:
        pass
Example #26
0
 def tearDown(self):
     try:
         shutil.rmtree(app.config['UPLOAD_FOLDER'])
     except OSError:
         pass
     db.session.remove()
     db.drop_all()
Example #27
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.client = self.app.test_client()
     self.app_context.push()
     db.drop_all()
     db.create_all()
Example #28
0
 def tearDown(self):
     shutil.rmtree(app.config['UPLOADED_IMAGES_DEST'])
     shutil.rmtree(app.config['THUMBNAIL_DIR'])
     shutil.rmtree(app.config['IMAGE_ROOT_DIR'])
     db.session.remove()
     db.drop_all()
     os.unlink(os.path.join(basedir, testDbPath))
Example #29
0
    def tearDown(self):
        # Wipes the testing database and remove the test application
        # context.

        db.session.remove()
        db.drop_all()
        self.app_context.pop()
Example #30
0
 def setUp(self):
     _app = create_app("config.TestConfig")
     ctx = _app.test_request_context()
     ctx.push()
     db.session.commit()
     db.drop_all()
     db.create_all()
 def setUp(self):
     db.drop_all()
     db.create_all()
Example #32
0
def recreate_db():
    # Recreates local db. Do not use in production
    db.drop_all()
    db.create_all()
    db.session.commit()
Example #33
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
Example #34
0
from app import db, Users

db.drop_all()
db.create_all()

testuser = Users(first_name='Grooty', last_name='Toot')
db.session.add(testuser)
db.session.commit()
Example #35
0
def app():
    with flask_app.app_context():
        # db.reflect()  # https://github.com/sqlalchemy/sqlalchemy/wiki/DropEverything
        db.drop_all()
        db.create_all()
    yield flask_app
Example #36
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
def init_db():
    """ Initialize the database."""
    db.drop_all()
    db.create_all()
    create_users()
    create_feeds()
Example #38
0
    def tearDown(self):  #pylint: disable=invalid-name
        """Remove our instance of the app and the associated in-memory database."""

        db.session.remove()
        db.drop_all()
        self.app_context.pop()
Example #39
0
 def tearDown(self):
     '''teardown all initialized variables.'''
     with self.app.app_context():
         # drop all tables
         db.session.remove()
         db.drop_all()
Example #40
0
 def tearDown(self):
     """Destroy a blank temp database before each test."""
     db.drop_all()
Example #41
0
def dropdb():
    if prompt_bool('Are you sure you eant to lose all your data'):
        db.drop_all()
Example #42
0
def drop_db():
    """Drop all rows and tables from SQL database.
    """
    db.engine.execute("DROP EXTENSION IF EXISTS postgis CASCADE;")
    db.drop_all()
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
Example #44
0
 def tearDown(selfs):
     # 清除数据库会话
     db.session.remove()
     # 删除数据库
     db.drop_all()
def drop():
    "Drops database tables"
    if prompt_bool("Are you sure to lose all your data?"):
        db.drop_all()
Example #46
0
 def tearDownClass(cls):
     db.session.remove()
     db.drop_all()
     cls.app_context.pop()
Example #47
0
def init_db():
    db.drop_all()
    db.create_all()
Example #48
0
 def tearDown(self):
     '''在每个测试后运行, 清理测试环境'''
     db.session.remove()
     db.drop_all()
 def tearDownClass(self):
     db.drop_all()
Example #50
0
 def tearDown(self):
     """
     Will be called after every test
     """
     db.session.remove()
     db.drop_all()
Example #51
0
 def teardown():
     _db.drop_all()
     os.unlink(test_db_file)
Example #52
0
def deleteAll():
    """delete database"""
    db.drop_all()
Example #53
0
 def tearDown(self):
     db.drop_all()
Example #54
0
 def tearDown(self):
     with self.app.app_context():
         db.session.remove()
         db.reflect()
         db.drop_all() 
 def tearDown(self):
     shutil.rmtree(self.path)
     db.session.remove()
     db.drop_all()
Example #56
0
 def tearDown():
     print("Rodando tear down...\n")
     db.drop_all()
Example #57
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
Example #58
0
def drop():
    """
    drop the database
    """
    db.drop_all()  
    db.create_all()