def setUp(self): self.app = create_app('TESTING_CONFIG') self.app_context = self.app.app_context() self.app_context.push() from sqlalchemy.orm.mapper import configure_mappers configure_mappers() db.create_all() test_username = '******' test_password = '******' Organization.insert_org() User.insert_user(username=test_username, password=test_password, email='*****@*****.**') OperatorEventType.insert_operator_event_types() self.client = self.app.test_client(use_cookies=False) UserScope.insert_scopes() admin = User.query.filter_by(user_name='admin').first() scope = UserScope.query.filter_by(scope_name='asset_manager').first() admin.scopes.append(scope) db.session.add(admin) db.session.commit() joe = User.insert_user(username='******', password='******', email='*****@*****.**') bob = User.insert_user(username='******', password='******', email='*****@*****.**')
def setUp(self): self.app = create_app('TESTING_CONFIG') self.app_context = self.app.app_context() self.app_context.push() from sqlalchemy.orm.mapper import configure_mappers configure_mappers() db.create_all() test_username = '******' test_password = '******' Organization.insert_org() User.insert_user(username=test_username, password=test_password, email='*****@*****.**') OperatorEventType.insert_operator_event_types() self.client = self.app.test_client(use_cookies=False) UserScope.insert_scopes() admin = User.query.filter_by(user_name='admin').first() scope = UserScope.query.filter_by(scope_name='user_admin').first() admin.scopes.append(scope) db.session.add(admin) db.session.commit() joe = User.insert_user(username='******', password='******', email='*****@*****.**') bob = User.insert_user(username='******', password='******', email='*****@*****.**')
def setup_and_teardown_database(app): """Setups and teardowns for the database.""" with app.app_context(): configure_mappers() db.create_all() yield db db.drop_all()
def __missing__(self, key): """ python.org: If a subclass of dict defines a method __missing__(), if the key is not present, the d[key] operation calls that method with the key as argument. :param key: Polymorphic name we want to load :return: (object) Polymorphic instance if found :since: v1.0.0 """ common_name = "dNG.database.instances.{0}".format(key) if ((not NamedLoader.is_defined(common_name, False)) and NamedLoader.is_defined(common_name) ): configure_mappers() return dict.__getitem__(self, key)
def deploy(password, bulkload): from flask.ext.migrate import upgrade from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink from sh import psql #Create the local database app.logger.info('Creating DEV and TEST Databases') psql('-c', 'create database ooiuidev;', '-U', 'postgres') psql('ooiuidev', '-c', 'create schema ooiui') psql('ooiuidev', '-c', 'create extension postgis') #Create the local test database psql('-c', 'create database ooiuitest;', '-U', 'postgres') psql('ooiuitest', '-c', 'create schema ooiui') psql('ooiuitest', '-c', 'create extension postgis') from sqlalchemy.orm.mapper import configure_mappers configure_mappers() db.create_all() if bulkload: with open('db/ooiui_schema_data.sql') as f: psql('ooiuidev', _in=f) app.logger.info('Bulk test data loaded.') # migrate database to latest revision #upgrade() if not os.getenv('TRAVIS'): Organization.insert_org() UserScope.insert_scopes() app.logger.info('Insert default user, name: admin') User.insert_user(password=password) admin = User.query.first() admin.scopes.append( UserScope.query.filter_by(scope_name='user_admin').first()) admin.scopes.append( UserScope.query.filter_by(scope_name='redmine').first()) db.session.add(admin) db.session.commit() if bulkload: with open('db/ooiui_schema_data_notifications.sql') as f: psql('ooiuidev', _in=f) app.logger.info('Bulk test data loaded for notifications.')
def deploy(password, bulkload): from flask.ext.migrate import upgrade from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink from sh import psql #Create the local database app.logger.info('Creating DEV and TEST Databases') psql('-c', 'create database ooiuidev;', '-U', 'postgres') psql('ooiuidev', '-c', 'create schema ooiui') psql('ooiuidev', '-c', 'create extension postgis') #Create the local test database psql('-c', 'create database ooiuitest;', '-U', 'postgres') psql('ooiuitest', '-c', 'create schema ooiui') psql('ooiuitest', '-c', 'create extension postgis') from sqlalchemy.orm.mapper import configure_mappers configure_mappers() db.create_all() if bulkload: with open('db/ooiui_schema_data.sql') as f: psql('ooiuidev', _in=f) app.logger.info('Bulk test data loaded.') # migrate database to latest revision #upgrade() if not os.getenv('TRAVIS'): Organization.insert_org() UserScope.insert_scopes() app.logger.info('Insert default user, name: admin') User.insert_user(password=password) admin = User.query.first() admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first()) admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first()) db.session.add(admin) db.session.commit() if bulkload: with open('db/ooiui_schema_data_notifications.sql') as f: psql('ooiuidev', _in=f) app.logger.info('Bulk test data loaded for notifications.')
from app import db from sqlalchemy.orm.mapper import configure_mappers # create the database and the db table db.create_all() configure_mappers() # commit the changes db.session.commit()
import sqlite3 from app import db # from datetime import datetime from app.config import DATABASE_PATH from sqlalchemy.orm.mapper import configure_mappers #NEED if search breaks with sqlite3.connect(DATABASE_PATH) as connection: db.session.remove() db.drop_all() configure_mappers() db.create_all()
def deploy(password, production, psqluser): from flask.ext.migrate import upgrade from ooiservices.app.models import User, UserScope, UserScopeLink, Array, Organization from ooiservices.app.models import PlatformDeployment, InstrumentDeployment, Stream, StreamParameterLink from sh import psql if production: app.logger.info('Creating PRODUCTION Database') try: psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER') except: pass psql('-c', 'create database ooiuiprod;', '-U', psqluser) psql('ooiuiprod', '-c', 'create schema ooiui', '-U', psqluser) psql('ooiuiprod', '-c', 'create extension postgis', '-U', psqluser) else: try: psql('-c', 'CREATE ROLE postgres LOGIN SUPERUSER') except: pass #Create the local database app.logger.info('Creating DEV and TEST Databases') psql('-c', 'create database ooiuidev;', '-U', psqluser) psql('ooiuidev', '-c', 'create schema ooiui', '-U', psqluser) psql('ooiuidev', '-c', 'create extension postgis', '-U', psqluser) #Create the local test database psql('-c', 'create database ooiuitest;', '-U', psqluser) psql('ooiuitest', '-c', 'create schema ooiui', '-U', psqluser) psql('ooiuitest', '-c', 'create extension postgis', '-U', psqluser) from sqlalchemy.orm.mapper import configure_mappers configure_mappers() db.create_all() if production: app.logger.info('Populating Production Database . . .') with open('db/ooiui_schema_data.sql') as f: psql('-U', psqluser, 'ooiuiprod', _in=f) with open('db/ooiui_params_streams_data.sql') as h: psql('-U', psqluser, 'ooiuiprod', _in=h) # with open('db/ooiui_vocab.sql') as i: # psql('-U', psqluser, 'ooiuiprod', _in=i) app.logger.info('Production Database loaded.') else: app.logger.info('Populating Dev Database . . .') with open('db/ooiui_schema_data.sql') as f: psql('-U', psqluser, 'ooiuidev', _in=f) with open('db/ooiui_params_streams_data.sql') as h: psql('-U', psqluser, 'ooiuidev', _in=h) # with open('db/ooiui_vocab.sql') as i: # psql('-U', psqluser, 'ooiuidev', _in=i) app.logger.info('Dev Database loaded.') # migrate database to latest revision #upgrade() if not os.getenv('TRAVIS'): UserScope.insert_scopes() app.logger.info('Insert default user, name: admin') User.insert_user(password=password) admin = User.query.first() admin.scopes.append(UserScope.query.filter_by(scope_name='user_admin').first()) admin.scopes.append(UserScope.query.filter_by(scope_name='sys_admin').first()) admin.scopes.append(UserScope.query.filter_by(scope_name='data_manager').first()) admin.scopes.append(UserScope.query.filter_by(scope_name='redmine').first()) db.session.add(admin) db.session.commit()
def get_relationship_from_object(self, ob, k): mapper = self.get_mapper_from_object(ob) if mapper.__class__._new_mappers: configure_mappers() return mapper._props[k]