def create_admin(): """Create initial admin user.""" logger.info('Creating admin user') admin_email = CONFIG_BROKER['admin_email'] admin_pass = CONFIG_BROKER['admin_password'] with create_app().app_context(): sess = GlobalDB.db().session user = sess.query(User).filter(User.email == admin_email).one_or_none() if not user: # once the rest of the setup scripts are updated to use # GlobalDB instead of databaseSession, move the app_context # creation up to initialize() user = create_user_with_password(admin_email, admin_pass, Bcrypt(), website_admin=True) return user
def create_admin(): """Create initial admin user.""" logger.info('Creating admin user') admin_email = CONFIG_BROKER['admin_email'] admin_pass = CONFIG_BROKER['admin_password'] with create_app().app_context(): sess = GlobalDB.db().session user = sess.query(User).filter(User.email == admin_email).one_or_none() if not user: # once the rest of the setup scripts are updated to use # GlobalDB instead of databaseSession, move the app_context # creation up to initialize() user = create_user_with_password(admin_email, admin_pass, Bcrypt(), website_admin=True) return user
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': '******' } 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') # set up users for status tests def add_user(email, name, username, website_admin=False): user = UserFactory( email=email, website_admin=website_admin, name=name, username=username, affiliations=[UserAffiliation( cgac=cgac, permission_type_id=PERMISSION_TYPE_DICT['writer'] )] ) 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 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""" # 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']