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()
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"
def setUp(self): app = create_app() with app.app_context(): db.create_all() self.app = app.test_client self.app_context = app.app_context
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")
def db(app): """Session-wide test database.""" _db.app = app _db.create_all() yield _db _db.drop_all()
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()
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()
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
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()
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()
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()
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()
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()
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()
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()
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)
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()
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()
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()
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()
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()
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()
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()
def create_db(): """Creates the db tables.""" db.create_all()
from app.app import app,db if __name__ == '__main__': db.create_all() app.run(host='0.0.0.0',debug=True)
def main(): log(f'Attemping to create database ...') db.create_all()
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))
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()
def create_db(): db.create_all()
def db_create(): db.create_all() db.commit() print('create db tables')
def setup(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def main(): print('Attemping to create database ...', end='') db.create_all() print('done')
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()
def setUp(self): app = flask.Flask(__name__) app.config.from_object("config.DevelopmentConfig") db.create_all()
def setUp(self): app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@localhost/practiflask' db.create_all()