当前位置: 首页>>代码示例>>Python>>正文


Python db.create_all方法代码示例

本文整理汇总了Python中app.db.create_all方法的典型用法代码示例。如果您正苦于以下问题:Python db.create_all方法的具体用法?Python db.create_all怎么用?Python db.create_all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.db的用法示例。


在下文中一共展示了db.create_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_moderation

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def test_moderation(self):
        db.create_all()
        u1 = User(email='john@example.com', username='john', password='cat')
        u2 = User(email='susan@example.com', username='susan', password='cat',
                  is_admin=True)
        t = Talk(title='t', description='d', author=u1)
        c1 = Comment(talk=t, body='c1', author_name='n',
                     author_email='e@e.com', approved=True)
        c2 = Comment(talk=t, body='c2', author_name='n',
                     author_email='e@e.com', approved=False)
        db.session.add_all([u1, u2, t, c1, c2])
        db.session.commit()
        for_mod1 = u1.for_moderation().all()
        for_mod1_admin = u1.for_moderation(True).all()
        for_mod2 = u2.for_moderation().all()
        for_mod2_admin = u2.for_moderation(True).all()
        self.assertTrue(len(for_mod1) == 1)
        self.assertTrue(for_mod1[0] == c2)
        self.assertTrue(for_mod1_admin == for_mod1)
        self.assertTrue(len(for_mod2) == 0)
        self.assertTrue(len(for_mod2_admin) == 1)
        self.assertTrue(for_mod2_admin[0] == c2) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:24,代码来源:test_user_model.py

示例2: test_unsubscribe

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def test_unsubscribe(self):
        db.create_all()
        u = User(email='john@example.com', username='john', password='cat')
        t = Talk(title='t', description='d', author=u)
        c1 = Comment(talk=t, body='c1', author_name='n',
                     author_email='e@e.com', approved=True, notify=True)
        c2 = Comment(talk=t, body='c2', author_name='n',
                     author_email='e2@e2.com', approved=False, notify=True)
        c3 = Comment(talk=t, body='c3', author_name='n',
                     author_email='e@e.com', approved=False, notify=True)
        db.session.add_all([u, t, c1, c2, c3])
        db.session.commit()
        token = t.get_unsubscribe_token(u'e@e.com')
        Talk.unsubscribe_user(token)
        comments = t.comments.all()
        for comment in comments:
            if comment.author_email == 'e@e.com':
                self.assertTrue(comment.notify == False)
            else:
                self.assertTrue(comment.notify == True) 
开发者ID:miguelgrinberg,项目名称:flask-pycon2014,代码行数:22,代码来源:test_talk_model.py

示例3: setUpClass

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        if cls.client:
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()


            db.drop_all()
            db.create_all()
            todo = Todo(title='title1', body='body1')
            db.session.add(todo)
            db.session.commit()


            threading.Thread(target=cls.app.run).start() 
开发者ID:vahidR,项目名称:restful-todo,代码行数:23,代码来源:test_integration.py

示例4: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
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() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_api.py

示例5: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
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() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:8,代码来源:test_user_model.py

示例6: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:7,代码来源:test_basics.py

示例7: setUpClass

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUpClass(cls):
        # start Chrome
        try:
            cls.client = webdriver.Chrome(service_args=["--verbose", "--log-path=test-reports/chrome.log"])
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='john@example.com',
                         username='john', password='cat',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:40,代码来源:test_selenium.py

示例8: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_client.py

示例9: to_dict_search

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def to_dict_search(self):

        response = self.to_dict_v2()

        response["abstracts"] = self.display_abstracts

        del response["z_authors"]
        if self.authors:
            response["author_lastnames"] = [author.get("family", None) for author in self.authors]
        else:
            response["author_lastnames"] = []

        if not hasattr(self, "score"):
            self.score = None
        response["score"] = self.score

        if not hasattr(self, "snippet"):
            self.snippet = None
        response["snippet"] = self.snippet

        return response


# db.create_all()
# commit_success = safe_commit(db)
# if not commit_success:
#     logger.info(u"COMMIT fail making objects") 
开发者ID:ourresearch,项目名称:oadoi,代码行数:29,代码来源:pub.py

示例10: create_user

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def create_user():
    db.create_all()
    #user_datastore.create_user(email='matt@nobien.net', password='password')
    print '111'
    #db.session.commit()


# Views 
开发者ID:torpedoallen,项目名称:wechat-admin,代码行数:10,代码来源:views.py

示例11: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        self.app = app.test_client()
        db.drop_all()
        db.create_all() 
开发者ID:LibrIT,项目名称:passhport,代码行数:10,代码来源:test_user.py

示例12: setup_class

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setup_class(cls):
        """Initialize configuration and create an empty database before
        testing
        """
        app.config["TESTING"] = True
        app.config["WTF_CSRF_ENABLED"] = False
        app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"# /" + \
#            os.path.join("/tmp/", "test.db")
        cls.app = app.test_client()
        db.create_all() 
开发者ID:LibrIT,项目名称:passhport,代码行数:12,代码来源:test_target.py

示例13: setup_class

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setup_class(cls):
        """Initialize configuration and create an empty database before
        testing
        """
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///:memory:"
        cls.app = app.test_client()
        db.create_all() 
开发者ID:LibrIT,项目名称:passhport,代码行数:11,代码来源:test_user.py

示例14: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUp(self):
        """Set up a blank temp database before each test"""
        basedir = os.path.abspath(os.path.dirname(__file__))
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
                                                os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all() 
开发者ID:Akagi201,项目名称:learning-python,代码行数:10,代码来源:app-test.py

示例15: setUp

# 需要导入模块: from app import db [as 别名]
# 或者: from app.db import create_all [as 别名]
def setUp(self):
        app.config['TESTING'] = True
        app.config['DEBUG'] = True
        self.app = app.test_client()
        db.create_all() 
开发者ID:projectweekend,项目名称:Flask-PostgreSQL-API-Seed,代码行数:7,代码来源:testing.py


注:本文中的app.db.create_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。