def setup_all_db(): """Sets up all databases""" create_database(CONFIG_DB['db_name']) run_migrations() setup_job_tracker_db() setup_error_db() setup_user_db() setup_validation_db() setup_static_data() setup_submission_type_db()
def full_database_setup(): """Sets up a clean database based on the model metadata. It also calculates the FK relationships between tables so we can delete them in order. It yields a tuple the _DB and ordered list of tables.""" rand_id = str(randint(1, 9999)) config = dataactcore.config.CONFIG_DB config['db_name'] = 'unittest{}_data_broker'.format(rand_id) dataactcore.config.CONFIG_DB = config create_database(config['db_name']) db = GlobalDB.db() run_migrations() creation_order = baseModel.Base.metadata.sorted_tables yield (db, list(reversed(creation_order))) # drop order GlobalDB.close() drop_database(config['db_name'])
def setUpClass(cls): """Set up resources to be shared within a test class""" # TODO: refactor into a pytest class fixtures and inject as necessary # update application's db config options so unittests # run against test databases configure_logging() suite = cls.__name__.lower() config = dataactcore.config.CONFIG_DB cls.num = randint(1, 9999) config['db_name'] = 'unittest{}_{}_data_broker'.format(cls.num, suite) dataactcore.config.CONFIG_DB = config create_database(CONFIG_DB['db_name']) run_migrations() app = create_app() app.config['TESTING'] = True app.config['DEBUG'] = False cls.app = TestApp(app) # Allow us to augment default test failure msg w/ more detail cls.longMessage = True # Upload files to S3 (False = skip re-uploading on subsequent runs) cls.uploadFiles = True # Run tests for local broker or not cls.local = CONFIG_BROKER['local'] # This needs to be set to the local directory for error reports if local is True cls.local_file_directory = CONFIG_SERVICES['error_report_path'] # drop and re-create test job db/tables setup_job_tracker_db() # drop and re-create test error db/tables setup_error_db() # drop and re-create test validation db setup_validation_db() cls.userId = None # constants to use for default submission start and end dates cls.SUBMISSION_START_DEFAULT = datetime(2015, 10, 1) cls.SUBMISSION_END_DEFAULT = datetime(2015, 10, 31)
def setUpClass(cls): """Set up resources to be shared within a test class""" # TODO: refactor into a pytest class fixtures and inject as necessary # update application's db config options so unittests # run against test databases suite = cls.__name__.lower() config = dataactcore.config.CONFIG_DB cls.num = randint(1, 9999) config['db_name'] = 'unittest{}_{}_data_broker'.format(cls.num, suite) dataactcore.config.CONFIG_DB = config create_database(CONFIG_DB['db_name']) run_migrations() app = create_app() app.config['TESTING'] = True app.config['DEBUG'] = False cls.app = TestApp(app) # Allow us to augment default test failure msg w/ more detail cls.longMessage = True # Upload files to S3 (False = skip re-uploading on subsequent runs) cls.uploadFiles = True # Run tests for local broker or not cls.local = CONFIG_BROKER['local'] # This needs to be set to the local directory for error reports if local is True cls.local_file_directory = CONFIG_SERVICES['error_report_path'] # drop and re-create test job db/tables setup_job_tracker_db() # drop and re-create test error db/tables setup_error_db() # drop and re-create test validation db setup_validation_db() cls.userId = None # constants to use for default submission start and end dates cls.SUBMISSION_START_DEFAULT = datetime(2015, 10, 1) cls.SUBMISSION_END_DEFAULT = datetime(2015, 10, 31)
def setup_all_db(db_name=None, no_data=False): """Sets up all databases""" logger.info("Invoking setup_all_db with db_name={} and no_data={}".format( db_name, no_data)) if db_name: # Ensure the config is set to setup the specified db CONFIG_DB['db_name'] = db_name create_database(CONFIG_DB['db_name']) logger.info("Created database (if not existing) {}".format( CONFIG_DB['db_name'])) logger.info("Running migrations in database {}".format( CONFIG_DB['db_name'])) run_migrations() if not no_data: logger.info("Setting up baseline data in database {}".format( CONFIG_DB['db_name'])) setup_job_tracker_db() setup_error_db() setup_user_db() setup_validation_db() setup_static_data() setup_submission_type_db()
def setUpClass(cls): """Set up resources to be shared within a test class""" # TODO: refactor into a pytest class fixtures and inject as necessary # update application's db config options so unittests # run against test databases configure_logging() suite = cls.__name__.lower() config = dataactcore.config.CONFIG_DB cls.num = randint(1, 9999) config['db_name'] = 'unittest{}_{}_data_broker'.format(cls.num, suite) dataactcore.config.CONFIG_DB = config create_database(CONFIG_DB['db_name']) run_migrations() app = create_app() app.config['TESTING'] = True app.config['DEBUG'] = False cls.app = TestApp(app) sess = GlobalDB.db().session # set up default e-mails for tests test_users = { 'admin_user': '******', 'agency_user': '******', 'agency_user_2': '*****@*****.**', 'no_permissions_user': '******', 'editfabs_user': '******' } admin_password = '******' cgac = CGAC(cgac_code='000', agency_name='Example Agency') sess.add(cgac) sess.commit() # Allow us to augment default test failure msg w/ more detail cls.longMessage = True # Upload files to S3 (False = skip re-uploading on subsequent runs) cls.uploadFiles = True # Run tests for local broker or not cls.local = CONFIG_BROKER['local'] # This needs to be set to the local directory for error reports if local is True cls.local_file_directory = CONFIG_SERVICES['error_report_path'] # drop and re-create test job db/tables setup_job_tracker_db() # drop and re-create test error db/tables setup_error_db() # drop and re-create test validation db setup_validation_db() # setup Schema SchemaLoader.load_all_from_path(validator_config_path) load_sql_rules() create_user_with_password(test_users["admin_user"], admin_password, Bcrypt(), website_admin=True) cls.userId = None cls.test_users = test_users # constants to use for default submission start and end dates cls.SUBMISSION_START_DEFAULT = datetime(2015, 10, 1) cls.SUBMISSION_END_DEFAULT = datetime(2015, 10, 31)
def setUpClass(cls): """Set up resources to be shared within a test class""" cls.session_id = "" with create_validator_app().app_context(): # update application's db config options so unittests # run against test databases suite = cls.__name__.lower() config = dataactcore.config.CONFIG_DB cls.num = randint(1, 9999) config['db_name'] = 'unittest{}_{}_data_broker'.format( cls.num, suite) dataactcore.config.CONFIG_DB = config create_database(CONFIG_DB['db_name']) run_migrations() # drop and re-create test user db/tables setup_user_db() # drop and re-create test job db/tables setup_job_tracker_db() # drop and re-create test error db/tables setup_error_db() # drop and re-create test validation db/tables setup_validation_db() # load e-mail templates setup_emails() # set up default e-mails for tests test_users = { 'admin_user': '******', 'agency_user': '******', 'agency_user_2': '*****@*****.**', 'no_permissions_user': '******', 'editfabs_user': '******' } user_password = '******' admin_password = '******' # get user info and save as class variables for use by tests sess = GlobalDB.db().session admin_cgac = CGAC(cgac_code='SYS', agency_name='Admin Agency') cls.admin_cgac_code = admin_cgac.cgac_code sess.add(admin_cgac) sess.commit() cgac = CGAC(cgac_code='000', agency_name='Example Agency') sess.add(cgac) sess.commit() frec = FREC(frec_code='0001', cgac_id=cgac.cgac_id, agency_name='Example FREC') sess.add(frec) sess.commit() sub_tier = SubTierAgency(cgac_id=cgac.cgac_id, frec_id=frec.frec_id, sub_tier_agency_code='0000', sub_tier_agency_name='Example Sub Tier') sess.add(sub_tier) # set up users for status tests def add_user(email, name, username, permission_type=ALL_PERMISSION_TYPES_DICT['writer'], website_admin=False): user = UserFactory(email=email, website_admin=website_admin, name=name, username=username, affiliations=[ UserAffiliation( cgac=cgac, permission_type_id=permission_type) ]) user.salt, user.password_hash = get_password_hash( user_password, Bcrypt()) sess.add(user) add_user(test_users['agency_user'], "Test User", "testUser") add_user(test_users['agency_user_2'], "Test User 2", "testUser2") add_user(test_users['editfabs_user'], "Fabs Writer", "fabsWriter", permission_type=ALL_PERMISSION_TYPES_DICT['editfabs']) # add new users create_user_with_password(test_users["admin_user"], admin_password, Bcrypt(), website_admin=True) create_user_with_password(test_users["no_permissions_user"], user_password, Bcrypt()) agency_user = sess.query(User).filter( User.email == test_users['agency_user']).one() cls.agency_user_id = agency_user.user_id sess.commit() # set up info needed by the individual test classes cls.test_users = test_users cls.user_password = user_password cls.admin_password = admin_password cls.local = CONFIG_BROKER['local']
def setUpClass(cls): """Set up resources to be shared within a test class""" cls.session_id = "" with create_validator_app().app_context(): # update application's db config options so unittests # run against test databases suite = cls.__name__.lower() config = dataactcore.config.CONFIG_DB cls.num = randint(1, 9999) config['db_name'] = 'unittest{}_{}_data_broker'.format(cls.num, suite) dataactcore.config.CONFIG_DB = config create_database(CONFIG_DB['db_name']) run_migrations() # drop and re-create test user db/tables setup_user_db() # drop and re-create test job db/tables setup_job_tracker_db() # drop and re-create test error db/tables setup_error_db() # drop and re-create test validation db/tables setup_validation_db() # load e-mail templates setup_emails() # set up default e-mails for tests test_users = { 'admin_user': '******', 'agency_user': '******', 'agency_user_2': '*****@*****.**', 'no_permissions_user': '******', 'editfabs_user': '******' } user_password = '******' admin_password = '******' # get user info and save as class variables for use by tests sess = GlobalDB.db().session admin_cgac = CGAC(cgac_code='SYS', agency_name='Admin Agency') cls.admin_cgac_code = admin_cgac.cgac_code sess.add(admin_cgac) sess.commit() cgac = CGAC(cgac_code='000', agency_name='Example Agency') sess.add(cgac) sess.commit() frec = FREC(frec_code='0001', cgac_id=cgac.cgac_id, agency_name='Example FREC') sess.add(frec) sess.commit() sub_tier = SubTierAgency(cgac_id=cgac.cgac_id, frec_id=frec.frec_id, sub_tier_agency_code='0000', sub_tier_agency_name='Example Sub Tier') sess.add(sub_tier) # set up users for status tests def add_user(email, name, username, permission_type=ALL_PERMISSION_TYPES_DICT['writer'], website_admin=False): user = UserFactory( email=email, website_admin=website_admin, name=name, username=username, affiliations=[UserAffiliation( cgac=cgac, permission_type_id=permission_type )] ) user.salt, user.password_hash = get_password_hash(user_password, Bcrypt()) sess.add(user) add_user(test_users['agency_user'], "Test User", "testUser") add_user(test_users['agency_user_2'], "Test User 2", "testUser2") add_user(test_users['editfabs_user'], "Fabs Writer", "fabsWriter", permission_type=ALL_PERMISSION_TYPES_DICT['editfabs']) # add new users create_user_with_password(test_users["admin_user"], admin_password, Bcrypt(), website_admin=True) create_user_with_password(test_users["no_permissions_user"], user_password, Bcrypt()) agency_user = sess.query(User).filter(User.email == test_users['agency_user']).one() cls.agency_user_id = agency_user.user_id sess.commit() # set up info needed by the individual test classes cls.test_users = test_users cls.user_password = user_password cls.admin_password = admin_password cls.local = CONFIG_BROKER['local']