コード例 #1
0
    def setUp(self):
        """Initialize test variables
        """
        self.app = create_app(config_name="testing")
        self.client = self.app.test_client
        self.user_data = {
            'name': 'guy',
            'email': '*****@*****.**',
            'password': '******'
        }
        self.bucketlist = {
            'name': 'list1',
            'date': '01012018',
            'description': 'Some description'
        }
        self.bucketlist_item1 = {
            'name': 'bucketlist_item1',
            'description': 'Do stuff'
        }
        self.bucketlist_item2 = {
            'name': 'bucketlist_item2',
            'description': 'Do a little more stuff'
        }

        with self.app.app_context():
            db.session.close()
            db.drop_all()
            db.create_all()
コード例 #2
0
ファイル: manage.py プロジェクト: simtb/user-graphql-app
def up():
    db.create_all()

    user: User = User(username="******")

    post: Post = Post()
    post.title: str = "Hello World"
    post.content: str = "Welcome to this GraphQL Demo"
    post.author: User = user

    info = Information()
    info.first_name: str = "User"
    info.last_name: str = "Demo"
    info.age: str = 25
    info.education: str = "University"
    info.company: str = "Company A"
    city: str = "London"
    info.favourite_hobby: str = "Running"
    info.favourite_song: str = "Billie Jean - Michael Jackson"
    info.favourite_movie: str = "Rush Hour 2"
    info.info_for_user: USER = user

    db.session.add(user)
    db.session.add(post)
    db.session.add(info)
    db.session.commit()

    return "Database and tables with dummy data has been created"
コード例 #3
0
    def setUp(self):
        app = create_app()
        with app.app_context():
            db.create_all()

        self.app = app.test_client
        self.app_context = app.app_context
コード例 #4
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = create_app(config_name="testing")
        #set up test client for the application
        self.client = self.app.test_client
        self.bucketlist = {'name': 'Go for skydiving'}

        # bind the app to the current context
        with self.app.app_context():
            # create all tables
            db.create_all()

        # Register a that we will use to test
        self.user_data = json.dumps(dict({
            "username": "******",
            "email": "*****@*****.**",
            "password": "******"}))
        self.client().post("/api/bucketlists/auth/register/", data=self.user_data,
                           content_type="application/json")

        self.login_info = json.dumps(dict({
            "email": "*****@*****.**",
            "password": "******"
        }))
        # Log is as the test user and get a token
        self.login_result = self.client().post("/api/bucketlists/auth/login/",
                                               data=self.login_info,
                                               content_type="application/json")
        self.access_token = json.loads(
            self.login_result.data.decode())['access_token']
        self.headers = dict(Authorization="Bearer "+ self.access_token,
                            content_type="application/json")
コード例 #5
0
ファイル: conftest.py プロジェクト: alysivji/flask-rq-example
def db(app):
    """Session-wide test database."""
    _db.app = app
    _db.create_all()
    yield _db

    _db.drop_all()
コード例 #6
0
	def setUp(self):
		"""Initialise app and define test variables"""
		self.app = create_app(config_name="testing")
		self.client = self.app.test_client
		self.user = {
			'username': '******',
			'email': '*****@*****.**',
			'password': '******',
			'confirm_password': '******'
		}
		self.shoppinglist = {
		'owner_id': '1',
		'title': "My favorite meal",
		'description': 'Items to cook my favorite meal'
		}
		self.shoppinglistitem = {
		'owner_id': '1',
		'shoppinglist_id': '1',
		'item_title': "Vegetables",
		'item_description': 'Carrots and Cabbages'
		}

		with self.app.app_context():
			# create all tables
			db.create_all()
コード例 #7
0
ファイル: __init__.py プロジェクト: TianhuiXu/Kanban-Board
    def setUp(self):
        app.config.update(TESTING=True)
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()

        db.create_all()
        db.session.commit()
コード例 #8
0
    def setUp(self):
        app = create_app()
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
        with app.app_context():
            db.create_all()

        self.app = app.test_client()
        self.app_context = app.app_context
コード例 #9
0
ファイル: test_models.py プロジェクト: j33n/ShoppingListApi
	def setUp(self):
		self.app = create_app(config_name="testing")
		self.user = Users(username="******", email="*****@*****.**", password="******")
		self.shoppinglist = ShoppingList(owner_id="1", title="Yellow Bananas", description="*****@*****.**")
		self.shoppinglistitem = ShoppingListItem(owner_id="1", shoppinglist_id="1", item_title="Yellow Bananas with green", item_description="And maracuja")
		self.usertoken = UserToken(token="a_certain_token")
		with self.app.app_context():
			# create all tables
			db.create_all()
コード例 #10
0
    def setUp(self) -> None:
        os.environ["APP_CONFIG"] = "config/test.cfg"
        self.app = create_app()
        self.client = self.app.test_client
        self.author = {'name': 'Rabindranath Tagore'}
        self.headers = {'content-type': 'application/json'}

        with self.app.app_context():
            db.create_all()
コード例 #11
0
def client():
    basedir = os.path.abspath(os.path.dirname(__file__))
    test_db_dir = os.path.join(basedir, "test.db")
    
    app = create_app("testing", "sqlite:///" + test_db_dir)
    test_client = app.test_client()
    with app.app_context():
        db.create_all()
        yield test_client
        db.drop_all()
コード例 #12
0
 def setUp(self):
     '''
     Define test variables and initialize app.
     '''
     self.app = create_app(config_name="testing")
     self.client = self.app.test_client
     with self.app.app_context():
         db.session.close()
         db.drop_all()
         db.create_all()
コード例 #13
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = POSTGRESQL_TEST_DB
     self.app = app.test_client()
     db.drop_all()
     db.get_engine(app).connect().execute(
         'DROP FUNCTION IF EXISTS post_search_vector_update();')
     db.create_all()
     self._populate_db_with_users()
コード例 #14
0
 def setUp(self):
     self.app = create_app('testing')
     # To allow assertions and errorrs to be propagated up.
     self.app.testing = True
     self.app_context = self.app.app_context()
     self.app_context.push()
     print("Creating test tables")
     db.create_all()
     self.client = self.app.test_client(use_cookies=True)
     self._ctx = self.app.test_request_context()
     self._ctx.push()
コード例 #15
0
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()
コード例 #16
0
ファイル: test_items.py プロジェクト: ro6ley/bucketlist
    def setUp(self):
        self.app = create_app("testing")
        # set up the test client
        self.client = self.app.test_client
        self.bucketlist = json.dumps(dict({"name": "Go to Dar"}))
        self.item = json.dumps(dict({"name": "I need to go soon"}))

        # bind the app to the current context
        with self.app.app_context():
            # create all tables
            db.create_all()

        # Register a test user
        self.user_data = json.dumps(
            dict({
                "username": "******",
                "email": "*****@*****.**",
                "password": "******"
            }))
        self.client().post("/auth/register/",
                           data=self.user_data,
                           content_type="application/json")

        self.login_data = json.dumps(
            dict({
                "username": "******",
                "email": "*****@*****.**",
                "password": "******"
            }))
        # Log is as the test user and get a token
        self.login_result = self.client().post("/auth/login/",
                                               data=self.login_data,
                                               content_type="application/json")
        self.access_token = json.loads(
            self.login_result.data.decode())['access_token']

        # Create a bucket list
        result = self.client().post("/api/v1/bucketlists/",
                                    headers=dict(Authorization="Bearer " +
                                                 self.access_token),
                                    data=self.bucketlist,
                                    content_type="application/json")
        # Confirm that the bucket list has been
        self.assertEqual(result.status_code, 201)

        # Add an item
        item_result = self.client().post("/api/v1/bucketlists/1/items/",
                                         headers=dict(Authorization="Bearer " +
                                                      self.access_token),
                                         data=self.item,
                                         content_type="application/json")
        self.assertEqual(item_result.status_code, 201)
コード例 #17
0
def session(application, docker_container):
    assert db.get_app().config['TESTING']
    db.session.rollback()
    db.drop_all()
    db.create_all()
    try:
        yield db.session
    except Exception:
        raise
    finally:
        # Roll back any trasactions that are in place before continuing
        db.session.rollback()
        db.drop_all()
コード例 #18
0
    def setUp(self):
        self.app = create_app(config_name="testing")
        # Set up the test client
        self.client = self.app.test_client
        self.user_data = json.dumps(
            dict({
                "username": "******",
                "email": "*****@*****.**",
                "password": "******"
            }))

        with self.app.app_context():
            # create all tables
            db.create_all()
コード例 #19
0
    def setUp(self):
        self.app = app

        self.client = self.app.test_client
        self.user = {'name': 'testuser', 'password': '******'}
        self.wrong_user = {
            'name': 'testuser_wrong',
            'password': '******'
        }

        with self.app.app_context():
            db.create_all()
            user = User(name="test_user", password="******")
            db.session.add(user)
            db.session.commit()
コード例 #20
0
ファイル: test_auth.py プロジェクト: ro6ley/bucketlist
    def setUp(self):
        self.app = create_app(config_name="testing")
        # Set up the test client
        self.client = self.app.test_client
        self.user_data = json.dumps(
            dict({
                "username": "******",
                "email": "*****@*****.**",
                "password": "******"
            }))

        with self.app.app_context():
            # create all tables
            db.session.close()
            db.drop_all()
            db.create_all()
コード例 #21
0
ファイル: main.py プロジェクト: xtream1101/scraper-monitor
def before_first_request():

    # Create any database tables that don't exist yet.
    db.create_all()

    # Create the Roles "admin" and "end-user" -- unless they already exist
    user_datastore.find_or_create_role(name='admin', description='Administrator')
    user_datastore.find_or_create_role(name='end-user', description='End user')

    # Create two Users for testing purposes -- unless they already exists.
    # In each case, use Flask-Security utility function to encrypt the password.
    # encrypted_password = utils.encrypt_password('password')
    # if not user_datastore.get_user('*****@*****.**'):
    #     user_datastore.create_user(email='*****@*****.**', password=encrypted_password, username='******')

    # Commit any database changes; the User and Roles must exist before we can add a Role to the User
    db.session.commit()
コード例 #22
0
ファイル: test_metron.py プロジェクト: MChrys/Metron
def init_database():
    #db = SQLAlchemy()
    # Create the database and the database table

    db.create_all()

    # Insert user data
    data = {'Name': 'Dog', 'Age': 5, 'Weight': 60, 'Human': False, 'Hat': None}

    character_schema = CharacterSchema()
    chara1 = Character(**data)

    db.session.add(chara1)

    # Commit the changes for the users
    db.session.commit()

    yield db
    db.session.close()
    db.drop_all()
コード例 #23
0
def initdb():
    db.drop_all(bind=None)
    db.create_all(bind=None)

    # add sample user
    user = User(username="******",
                email="*****@*****.**",
                active=True,
                password='******',
                confirmed=True)
    user_role = Role(name='user')
    db.session.add(user_role)
    admin_role = Role(name='admin')
    db.session.add(admin_role)
    user.roles.append(fetch_admin_role())
    user.roles.append(fetch_user_role())
    db.session.add(user)
    db.session.commit()
    config = BrowseConfig(name="config-test",
                          address='ws://172.0.0.3:8888',
                          user_id=user.id)
    db.session.add(config)
    db.session.commit()
コード例 #24
0
def create_db():
    """Creates the db tables."""
    db.create_all()
コード例 #25
0
ファイル: run.py プロジェクト: Saberlion/sml
from app.app import app,db

if __name__ == '__main__':
    db.create_all()
    app.run(host='0.0.0.0',debug=True)
コード例 #26
0
def main():
    log(f'Attemping to create database ...')
    db.create_all()
コード例 #27
0
from migrate.versioning import api
from app.config import SQLALCHEMY_DATABASE_URI,SQLALCHEMY_MIGRATE_REPO
from app.app import db
import os.path
db.create_all()

if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
コード例 #28
0
ファイル: layers.py プロジェクト: BartKrol/tvmanager
 def testSetUp(cls, test):
     """Set up the database per test case"""
     db.create_all()
     test.user = User(email='*****@*****.**', password='******')
     db.session.add(test.user)
     db.session.commit()
コード例 #29
0
def create_db():
    db.create_all()
コード例 #30
0
def db_create():
    db.create_all()
    db.commit()
    print('create db tables')
コード例 #31
0
 def setup(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
コード例 #32
0
def main():
    print('Attemping to create database ...', end='')
    db.create_all()
    print('done')
コード例 #33
0
ファイル: manage.py プロジェクト: xtream1101/scraper-monitor
import os
from app.app import app, db
from app.models import *
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

os.environ['TZ'] = 'UTC'


# Create tables if they do not already exist
db.create_all()  # Used on fresh installs

migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
コード例 #34
0
 def setUp(self):
     app = flask.Flask(__name__)
     app.config.from_object("config.DevelopmentConfig")
     db.create_all()
コード例 #35
0
ファイル: test.py プロジェクト: juanvaes/microblog
 def setUp(self):
     app.config[
         'SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@localhost/practiflask'
     db.create_all()