python类create_all()的实例源码

manage.py 文件源码 项目:InfoSub 作者: CoderHito 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def initdb():
    """
    init database, create all tables, create user plan and create admin.
    """
    print("init database...")
    try:
        from app.model.user import UserPlan, User, PlanUsage
        from app.model.info import WebSite, Article, SiteType, Tag, tags
        from app.model.subscribe import UserSub
        db.create_all()
    except Exception as e:
        print e

    try:
        init_user()
    except Exception:
        pass

    print "finish."
basecase.py 文件源码 项目:mybookshelf2 作者: izderadicka 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def setUp(self):
        db.drop_all()
        db.create_all()
        connection = db.engine.raw_connection()
        try:
            c = connection.cursor()

            for f in self.INIT_FILES:
                script = open(
                    os.path.join(os.path.dirname(__file__), self.SQL_DIR, f), 'rt', encoding='utf-8-sig').read()
                # print(script)
                res = c.execute(script)
                connection.commit()

        finally:
            pass
            connection.close()
tests.py 文件源码 项目:project-dream-team-three 作者: mbithenzomo 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setUp(self):
        """
        Will be called before every test
        """

        db.create_all()

        # create test admin user
        admin = Employee(username="admin", password="admin2016", is_admin=True)

        # create test non-admin user
        employee = Employee(username="test_user", password="test2016")

        # save users to database
        db.session.add(admin)
        db.session.add(employee)
        db.session.commit()
environment.py 文件源码 项目:backend 作者: gitplaylist 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def before_all(context):
    """Create the context bag."""
    # Change the configuration on the fly
    os.environ['ENV'] = 'testing'

    # Import this now because the environment variable
    # should be changed before this happens.

    context.app = create_app()

    # Create all the tables in memory.
    with context.app.app_context():
        db.create_all()

    # Create the test client.
    context.client = context.app.test_client()
test_back_end.py 文件源码 项目:flask-selenium-webdriver-part-one 作者: mbithenzomo 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setUp(self):
        """
        Will be called before every test
        """
        db.session.commit()
        db.drop_all()
        db.create_all()

        # create test admin user
        admin = Employee(username="admin", password="admin2016", is_admin=True)

        # create test non-admin user
        employee = Employee(username="test_user", password="test2016")

        # save users to database
        db.session.add(admin)
        db.session.add(employee)
        db.session.commit()
tasks.py 文件源码 项目:it-jira-bamboohr 作者: saucelabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def initdb(ctx):
    from app import app, db
    with app.app_context():
        db.create_all()
tasks.py 文件源码 项目:it-jira-bamboohr 作者: saucelabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def resetdb(ctx):
    from app import app, db
    with app.app_context():
        db.drop_all()
        db.create_all()
pub.py 文件源码 项目:oadoi 作者: Impactstory 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def to_dict_v2(self):
        response = {
            "doi": self.doi,
            "doi_url": self.url,
            "is_oa": self.is_oa,
            "best_oa_location": self.best_oa_location_dict,
            "oa_locations": self.all_oa_location_dicts(),
            "data_standard": self.data_standard,
            "title": self.best_title,
            "year": self.year,
            "journal_is_oa": self.oa_is_open_journal,
            "journal_is_in_doaj": self.oa_is_doaj_journal,
            "journal_issns": self.display_issns,
            "journal_name": self.journal,
            "publisher": self.publisher,
            "published_date": self.issued,
            "updated": self.display_updated,
            "genre": self.genre,
            "z_authors": self.authors,
            # "crossref_api_modified": self.crossref_api_modified,

            # need this one for Unpaywall
            "x_reported_noncompliant_copies": self.reported_noncompliant_copies,

            # "x_crossref_api_raw": self.crossref_api_modified

        }

        if self.error:
            response["x_error"] = True

        return response





# db.create_all()
# commit_success = safe_commit(db)
# if not commit_success:
#     logger.info(u"COMMIT fail making objects")
test_client.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
test_api.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
test_basics.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
test_user_model.py 文件源码 项目:circleci-demo-python-flask 作者: CircleCI-Public 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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()
tests.py 文件源码 项目:microflack_messages 作者: miguelgrinberg 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setUp(self):
        self.ctx = app.app_context()
        self.ctx.push()
        db.drop_all()  # just in case
        db.create_all()
        self.client = app.test_client()
helper.py 文件源码 项目:plexivity 作者: mutschler 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def startScheduler():
    db.create_all()
    #create default roles!
    if not db.session.query(models.Role).filter(models.Role.name == "admin").first():
        admin_role = models.Role(name='admin', description='Administrator Role')
        user_role = models.Role(name='user', description='User Role')
        db.session.add(admin_role)
        db.session.add(user_role)
        db.session.commit()

    try:
        import tzlocal

        tz = tzlocal.get_localzone()
        logger.info("local timezone: %s" % tz)
    except:
        tz = None

    if not tz or tz.zone == "local":
        logger.error('Local timezone name could not be determined. Scheduler will display times in UTC for any log'
                 'messages. To resolve this set up /etc/timezone with correct time zone name.')
        tz = pytz.utc
    #in debug mode this is executed twice :(
    #DONT run flask in auto reload mode when testing this!
    scheduler = BackgroundScheduler(logger=sched_logger, timezone=tz)
    scheduler.add_job(notify.task, 'interval', seconds=config.SCAN_INTERVAL, max_instances=1,
                      start_date=datetime.datetime.now(tz) + datetime.timedelta(seconds=2))
    scheduler.start()
    sched = scheduler
    #notify.task()
plexivity.py 文件源码 项目:plexivity 作者: mutschler 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run_app():
    from subprocess import Popen
    import sys
    os.chdir(os.path.abspath(os.path.dirname(__file__)))
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "manage.py")
    args = [sys.executable, path, "db"]
    if not os.path.exists(os.path.join(config.DATA_DIR, "plexivity.db")):
        from app import db
        db.create_all()
        args.append("stamp")
        args.append("head")
    else:
        args.append("upgrade")

    Popen(args)

    helper.startScheduler()

    if config.USE_SSL:
        helper.generateSSLCert()
        try:
            from OpenSSL import SSL
            context = SSL.Context(SSL.SSLv23_METHOD)
            context.use_privatekey_file(os.path.join(config.DATA_DIR, "plexivity.key"))
            context.use_certificate_file(os.path.join(config.DATA_DIR, "plexivity.crt"))
            app.run(host="0.0.0.0", port=config.PORT, debug=False, ssl_context=context)
        except:
            logger.error("plexivity should use SSL but OpenSSL was not found, starting without SSL")
            app.run(host="0.0.0.0", port=config.PORT, debug=False)
    else:
        app.run(host="0.0.0.0", port=config.PORT, debug=False)
conftest.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def db(request, app):
    """Create test database tables"""
    _db.drop_all()
    # Create the tables based on the current model
    _db.create_all()

    user = User.create_test_user()
    TestClient.test_user = user
    app.test_client_class = TestClient
    app.response_class = TestResponse

    _db.session.commit()
test_basic.py 文件源码 项目:FMBlog 作者: vc12345679 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
test_client.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
test_api.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
test_basics.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
test_user_model.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
test_basics.py 文件源码 项目:GWMMS 作者: lvhuiyang 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
base.py 文件源码 项目:bucket_api 作者: jokamjohn 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUp(self):
        """
        Create the database
        :return:
        """
        db.create_all()
        db.session.commit()
test_basic.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

    # ?????
test_user_model.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.context = self.app.app_context()
        self.context.push()
        db.create_all()
        Role.insert_roles()
test_basics.py 文件源码 项目:pyetje 作者: rorlika 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
test_app.py 文件源码 项目:Adventure-Insecure 作者: colinnewell 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def setUp(self):
        self.db_fd, self.db_filename = tempfile.mkstemp()
        # FIXME: this isn't actually working.
        app.config['DATABASE_URI'] = 'sqlite:///' + self.db_filename
        self.app = app.test_client()
        db.create_all()
test_client.py 文件源码 项目:smart-iiot 作者: quanpower 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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)
test_api.py 文件源码 项目:smart-iiot 作者: quanpower 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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()
test_basics.py 文件源码 项目:smart-iiot 作者: quanpower 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()


问题


面经


文章

微信
公众号

扫码关注公众号