Python app.db.create_all() Examples

The following are 30 code examples of app.db.create_all(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module app.db , or try the search function .
Example #1
Source File: test_user_model.py    From flask-pycon2014 with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: test_client.py    From circleci-demo-python-flask with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: test_talk_model.py    From flask-pycon2014 with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: test_integration.py    From restful-todo with GNU General Public License v2.0 6 votes vote down vote up
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() 
Example #5
Source File: test_basics.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #6
Source File: manage.py    From flask-skeleton with Do What The F*ck You Want To Public License 5 votes vote down vote up
def create_db():
    db.create_all() 
Example #7
Source File: test_login.py    From oreilly-intro-to-flask-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        self.client = self.app.test_client(use_cookies=True)
        db.create_all()
        User.register('john', 'cat') 
Example #8
Source File: test_user_model.py    From oreilly-intro-to-flask-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        db.create_all() 
Example #9
Source File: test_login.py    From oreilly-intro-to-flask-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        self.client = self.app.test_client(use_cookies=True)
        db.create_all()
        User.register('john', 'cat') 
Example #10
Source File: test_user_model.py    From flask-blog with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #11
Source File: test_user_model.py    From flasky-with-celery with MIT License 5 votes vote down vote up
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() 
Example #12
Source File: test_bucketlist.py    From flask-rest-api with MIT License 5 votes vote down vote up
def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        self.bucketlist = {'name': 'Go to Borabora for vacay'}

        # binds the app to the current context
        with self.app.app_context():
            # create all tables
            db.session.close()
            db.drop_all()
            db.create_all() 
Example #13
Source File: test_selenium.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        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) 
Example #14
Source File: test_client.py    From flasky-with-celery with MIT License 5 votes vote down vote up
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) 
Example #15
Source File: test_auth.py    From flask-rest-api with MIT License 5 votes vote down vote up
def setUp(self):
        """Set up test variables."""
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        self.user_data = {
            'email': 'test@example.com',
            'password': 'test_password'
        }

        with self.app.app_context():
            # create all tables
            db.session.close()
            db.drop_all()
            db.create_all() 
Example #16
Source File: manage.py    From fitbit-api-example-python with Apache License 2.0 5 votes vote down vote up
def create_db():
    db.init_app(app)
    db.create_all() 
Example #17
Source File: test_user_model.py    From oreilly-intro-to-flask-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_ctx = self.app.app_context()
        self.app_ctx.push()
        db.create_all() 
Example #18
Source File: manage.py    From flask-boilerplate with MIT License 5 votes vote down vote up
def initdb():
    ''' Create the SQL database. '''
    db.create_all()
    print(colored('The SQL database has been created', 'green')) 
Example #19
Source File: __init__.py    From tutorial-flask with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app(settings_module="config.testing")
        self.client = self.app.test_client()

        # Crea un contexto de aplicaciĆ³n
        with self.app.app_context():
            # Crea las tablas de la base de datos
            db.create_all()
            # Creamos un usuario administrador
            BaseTestClass.create_user('admin', 'admin@xyz.com', '1111', True)
            # Creamos un usuario invitado
            BaseTestClass.create_user('guest', 'guest@xyz.com', '1111', False) 
Example #20
Source File: tests.py    From oreilly-flask-apis-video with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.ctx = self.app.app_context()
        self.ctx.push()
        db.drop_all()
        db.create_all()
        u = User(username=self.default_username)
        u.set_password(self.default_password)
        db.session.add(u)
        db.session.commit()
        self.client = TestClient(self.app, u.generate_auth_token(), '') 
Example #21
Source File: test_client.py    From flasky-first-edition with MIT License 5 votes vote down vote up
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) 
Example #22
Source File: test_selenium.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        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) 
Example #23
Source File: test_basics.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #24
Source File: test_user_model.py    From flasky-first-edition with MIT License 5 votes vote down vote up
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() 
Example #25
Source File: test_api.py    From flasky-first-edition with MIT License 5 votes vote down vote up
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() 
Example #26
Source File: test_apis.py    From restful-todo with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        self.client = self.app.test_client() 
Example #27
Source File: test_skeleton.py    From restful-todo with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #28
Source File: manage.py    From restful-todo with GNU General Public License v2.0 5 votes vote down vote up
def createall():
  """ creats the table."""
  db.create_all() 
Example #29
Source File: test_basics.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all() 
Example #30
Source File: test_user_model.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()