Esempio n. 1
0
def setupAllDB():
    """Sets up all databases"""
    setupJobTrackerDB()
    setupErrorDB()
    setupUserDB()
    setupJobQueueDB()
    setupValidationDB()
    setupStagingDB()
def setupAllDB():
    """Sets up all databases"""
    setupJobTrackerDB()
    setupErrorDB()
    setupUserDB()
    setupJobQueueDB()
    setupValidationDB()
    setupStagingDB()
def setupAllDB():
    """Sets up all databases"""
    createDatabase(CONFIG_DB['db_name'])
    runMigrations()
    setupJobTrackerDB()
    setupErrorDB()
    setupUserDB()
    setupJobQueueDB()
    setupValidationDB()
    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['error_db_name'] = 'unittest{}_{}_error_data'.format(
            cls.num, suite)
        config['job_db_name'] = 'unittest{}_{}_job_tracker'.format(
            cls.num, suite)
        config['user_db_name'] = 'unittest{}_{}_user_manager'.format(
            cls.num, suite)
        config['validator_db_name'] = 'unittest{}_{}_validator'.format(
            cls.num, suite)
        config['staging_db_name'] = 'unittest{}_{}_staging'.format(
            cls.num, suite)
        dataactcore.config.CONFIG_DB = config

        app = createApp()
        app.config['TESTING'] = True
        cls.app = TestApp(app)

        # Allow us to augment default test failure msg w/ more detail
        cls.longMessage = True
        # Flag for each route call to launch a new thread
        cls.useThreads = False
        # 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
        setupJobTrackerDB()
        # drop and re-create test error db/tables
        setupErrorDB()
        # drop and re-create test staging db
        setupStagingDB()
        # drop and re-create test vaidation db
        setupValidationDB()

        cls.interfaces = InterfaceHolder()
        cls.jobTracker = cls.interfaces.jobDb
        cls.stagingDb = cls.interfaces.stagingDb
        cls.errorInterface = cls.interfaces.errorDb
        cls.validationDb = cls.interfaces.validationDb
        cls.userId = 1
Esempio n. 5
0
    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['error_db_name'] = 'unittest{}_{}_error_data'.format(
            cls.num, suite)
        config['job_db_name'] = 'unittest{}_{}_job_tracker'.format(
            cls.num, suite)
        config['user_db_name'] = 'unittest{}_{}_user_manager'.format(
            cls.num, suite)
        config['validator_db_name'] = 'unittest{}_{}_validator'.format(
            cls.num, suite)
        config['staging_db_name'] = 'unittest{}_{}_staging'.format(
            cls.num, suite)
        dataactcore.config.CONFIG_DB = config

        app = createApp()
        app.config['TESTING'] = True
        cls.app = TestApp(app)

        # Allow us to augment default test failure msg w/ more detail
        cls.longMessage = True
        # Flag for each route call to launch a new thread
        cls.useThreads = False
        # 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
        setupJobTrackerDB()
        # drop and re-create test error db/tables
        setupErrorDB()
        # drop and re-create test staging db
        setupStagingDB()
        # drop and re-create test vaidation db
        setupValidationDB()

        cls.interfaces = InterfaceHolder()
        cls.jobTracker = cls.interfaces.jobDb
        cls.stagingDb = cls.interfaces.stagingDb
        cls.errorInterface = cls.interfaces.errorDb
        cls.validationDb = cls.interfaces.validationDb
        cls.userId = 1
Esempio n. 6
0
    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
        createDatabase(CONFIG_DB['db_name'])
        runMigrations()

        app = createApp()
        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
        setupJobTrackerDB()
        # drop and re-create test error db/tables
        setupErrorDB()
        # drop and re-create test validation db
        setupValidationDB()

        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"""
        cls.session_id = ""

        with createValidatorApp().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
            createDatabase(CONFIG_DB['db_name'])
            runMigrations()

            # drop and re-create test user db/tables
            setupUserDB()
            # drop and re-create test job db/tables
            setupJobTrackerDB()
            # drop and re-create test error db/tables
            setupErrorDB()
            # drop and re-create test validation db/tables
            setupValidationDB()
            # load e-mail templates
            setupEmails()

            # set up default e-mails for tests
            test_users = {}
            test_users['admin_email'] = '*****@*****.**'
            test_users['change_user_email'] = '*****@*****.**'
            test_users['password_reset_email'] = '*****@*****.**'
            test_users['inactive_email'] = '*****@*****.**'
            test_users['password_lock_email'] = '*****@*****.**'
            test_users['expired_lock_email'] = '*****@*****.**'
            test_users['agency_admin_email'] = '*****@*****.**'

            # this email is for a regular agency_user email that is to be used for
            # testing functionality expected by a normal, base user
            test_users['agency_user'] = '******'
            test_users['approved_email'] = '*****@*****.**'
            test_users['submission_email'] = '*****@*****.**'
            user_password = '******'
            admin_password = '******'

            # set up users for status tests
            StatusTestUser = namedtuple(
                'StatusTestUser',
                ['email', 'user_status', 'permissions', 'user_type'])
            StatusTestUser.__new__.__defaults__ = (None, None,
                                                   AccountType.AGENCY_USER,
                                                   None)
            status_test_users = []
            status_test_users.append(
                StatusTestUser('*****@*****.**', 'awaiting_confirmation', 0))
            status_test_users.append(
                StatusTestUser('*****@*****.**', 'email_confirmed'))
            status_test_users.append(
                StatusTestUser('*****@*****.**', 'awaiting_approval'))
            status_test_users.append(
                StatusTestUser('*****@*****.**', 'awaiting_approval'))
            status_test_users.append(
                StatusTestUser('*****@*****.**',
                               'awaiting_approval'))
            status_test_users.append(
                StatusTestUser(
                    test_users['admin_email'], 'approved',
                    AccountType.WEBSITE_ADMIN + AccountType.AGENCY_USER))
            status_test_users.append(
                StatusTestUser(test_users['approved_email'], 'approved'))
            status_test_users.append(
                StatusTestUser('*****@*****.**', 'denied'))

            # add new users
            createUserWithPassword(test_users["submission_email"],
                                   user_password, Bcrypt())
            createUserWithPassword(test_users["change_user_email"],
                                   user_password, Bcrypt())
            createUserWithPassword(test_users["password_reset_email"],
                                   user_password, Bcrypt())
            createUserWithPassword(test_users["inactive_email"], user_password,
                                   Bcrypt())
            createUserWithPassword(test_users["password_lock_email"],
                                   user_password, Bcrypt())
            createUserWithPassword(test_users['expired_lock_email'],
                                   user_password, Bcrypt())
            createUserWithPassword(test_users['agency_admin_email'],
                                   admin_password,
                                   Bcrypt(),
                                   permission=4)
            createUserWithPassword(test_users['agency_user'], user_password,
                                   Bcrypt())

            # get user info and save as class variables for use by tests

            sess = GlobalDB.db().session

            agencyUser = sess.query(User).filter(
                User.email == test_users['agency_user']).one()
            cls.agency_user_id = agencyUser.user_id

            # set the specified account to be expired
            expiredUser = sess.query(User).filter(
                User.email == test_users['expired_lock_email']).one()
            today = parse(time.strftime("%c"))
            expiredUser.last_login_date = (today -
                                           timedelta(days=120)).strftime("%c")
            sess.add(expiredUser)

            # create users for status testing
            for u in status_test_users:
                user = User(email=u.email,
                            permissions=u.permissions,
                            user_status=sess.query(UserStatus).filter(
                                UserStatus.name == u.user_status).one())
                sess.add(user)

            # set up approved user
            user = sess.query(User).filter(
                User.email == test_users['approved_email']).one()
            user.username = "******"
            user.cgac_code = "000"
            user.salt, user.password_hash = getPasswordHash(
                user_password, Bcrypt())
            sess.add(user)
            cls.approved_user_id = user.user_id

            # set up admin user
            admin = sess.query(User).filter(
                User.email == test_users['admin_email']).one()
            admin.salt, admin.password_hash = getPasswordHash(
                admin_password, Bcrypt())
            admin.name = "Mr. Manager"
            admin.cgac_code = "SYS"
            sess.add(admin)

            # set up status changed user
            statusChangedUser = sess.query(User).filter(
                User.email == test_users['change_user_email']).one()
            statusChangedUser.name = "Test User"
            statusChangedUser.user_status = sess.query(UserStatus).filter(
                UserStatus.name == 'email_confirmed').one()
            sess.add(statusChangedUser)
            cls.status_change_user_id = statusChangedUser.user_id

            # set up deactivated user
            deactivated_user = sess.query(User).filter(
                User.email == test_users['inactive_email']).one()
            deactivated_user.last_login_date = time.strftime("%c")
            deactivated_user.is_active = False
            sess.add(deactivated_user)

            sess.commit()

        # get lookup dictionaries
        cls.jobStatusDict = lookups.JOB_STATUS_DICT
        cls.jobTypeDict = lookups.JOB_TYPE_DICT
        cls.fileTypeDict = lookups.FILE_TYPE_DICT
        cls.fileStatusDict = lookups.FILE_STATUS_DICT
        cls.ruleSeverityDict = lookups.RULE_SEVERITY_DICT
        cls.errorTypeDict = lookups.ERROR_TYPE_DICT
        cls.publishStatusDict = lookups.PUBLISH_STATUS_DICT
        cls.userStatusDict = lookups.USER_STATUS_DICT

        # 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

        # Create an empty session ID
        cls.session_id = ""

        # 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['error_db_name'] = 'unittest{}_{}_error_data'.format(
            cls.num, suite)
        config['job_db_name'] = 'unittest{}_{}_job_tracker'.format(
            cls.num, suite)
        config['user_db_name'] = 'unittest{}_{}_user_manager'.format(
            cls.num, suite)
        config['validator_db_name'] = 'unittest{}_{}_validator'.format(
            cls.num, suite)
        config['staging_db_name'] = 'unittest{}_{}_staging'.format(
            cls.num, suite)
        dataactcore.config.CONFIG_DB = config

        # drop and re-create test user db/tables
        setupUserDB()
        # drop and re-create test job db/tables
        setupJobTrackerDB()
        # drop and re-create test error db/tables
        setupErrorDB()
        # drop and re-create test validation db/tables
        setupValidationDB()
        # load e-mail templates
        setupEmails()

        #get test users
        try:
            with open('test.json') as test_users_file:
                test_users = json.load(test_users_file)
            test_users = test_users
        except:
            #if no test.json, provide some default e-mail accounts for tests
            test_users = {}
            test_users['admin_email'] = '*****@*****.**'
            test_users['change_user_email'] = '*****@*****.**'
            test_users['password_reset_email'] = '*****@*****.**'
            test_users['inactive_email'] = '*****@*****.**'
            test_users['password_lock_email'] = '*****@*****.**'
            test_users['expired_lock_email'] = '*****@*****.**'
            test_users['agency_admin_email'] = '*****@*****.**'

            # This email is for a regular agency_user email that is to be used for testing functionality
            # expected by a normal, base user
            test_users['agency_user'] = '******'
        if 'approved_email' not in test_users:
            test_users['approved_email'] = '*****@*****.**'
        if 'submission_email' not in test_users:
            test_users['submission_email'] = '*****@*****.**'
        user_password = '******'
        admin_password = '******'

        #setup test users
        userEmails = ["*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**",
            "*****@*****.**", test_users["admin_email"],
            test_users["approved_email"], "*****@*****.**"]
        userStatus = ["awaiting_confirmation",
            "email_confirmed", "awaiting_approval",
            "awaiting_approval", "awaiting_approval",
            "approved", "approved", "denied"]
        userPermissions = [0, AccountType.AGENCY_USER,
            AccountType.AGENCY_USER, AccountType.AGENCY_USER,
            AccountType.AGENCY_USER,
            AccountType.WEBSITE_ADMIN+AccountType.AGENCY_USER,
            AccountType.AGENCY_USER, AccountType.AGENCY_USER]

        # Add new users
        userDb = UserHandler()
        userDb.createUserWithPassword(
            test_users["submission_email"], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users["change_user_email"], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users["password_reset_email"], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users["inactive_email"], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users["password_lock_email"], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users['expired_lock_email'], user_password, Bcrypt())
        userDb.createUserWithPassword(
            test_users['agency_admin_email'], admin_password, Bcrypt(), permission=4)
        userDb.createUserWithPassword(
            test_users['agency_user'], user_password, Bcrypt())

        # Set the Agency for the agency user
        agencyUser = userDb.getUserByEmail(test_users['agency_user'])
        userDb.session.commit()
        cls.agency_user_id = agencyUser.user_id

        # Set the specified account to be expired
        expiredUser = userDb.getUserByEmail(test_users['expired_lock_email'])
        today = parse(time.strftime("%c"))
        expiredUser.last_login_date = (today-timedelta(days=120)).strftime("%c")
        userDb.session.commit()

        # Create users for status testing
        for index in range(len(userEmails)):
            email = userEmails[index]
            userDb.addUnconfirmedEmail(email)
            user = userDb.getUserByEmail(email)
            userDb.changeStatus(user, userStatus[index])
            userDb.setPermission(user, userPermissions[index])

        #set up approved user
        user = userDb.getUserByEmail(test_users['approved_email'])
        user.username = "******"
        userDb.setPassword(user, user_password, Bcrypt())
        cls.approved_user_id = user.user_id

        #set up admin user
        admin = userDb.getUserByEmail(test_users['admin_email'])
        userDb.setPassword(admin, admin_password, Bcrypt())
        admin.name = "Mr. Manager"
        admin.cgac_code = "SYS"
        userDb.session.commit()

        #set up status changed user
        statusChangedUser = userDb.getUserByEmail(
            test_users["change_user_email"])
        cls.status_change_user_id = statusChangedUser.user_id
        statusChangedUser.name = "Test User"
        statusChangedUser.user_status_id = userDb.getUserStatusId(
            "email_confirmed")
        userDb.session.commit()

        #set up deactivated user
        user = userDb.getUserByEmail(test_users["inactive_email"])
        user.last_login_date = time.strftime("%c")
        user.is_active = False
        userDb.session.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.interfaces = InterfaceHolder()
        cls.jobTracker = cls.interfaces.jobDb
        cls.errorDatabase = cls.interfaces.errorDb
        cls.userDb = cls.interfaces.userDb
        cls.local = CONFIG_BROKER['local']
Esempio n. 9
0
    def setUpClass(cls):
        """Set up resources to be shared within a test class"""
        #TODO: refactor into a pytest class fixtures and inject as necessary

        # Create an empty session ID
        cls.session_id = ""

        # 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['error_db_name'] = 'unittest{}_{}_error_data'.format(
            cls.num, suite)
        config['job_db_name'] = 'unittest{}_{}_job_tracker'.format(
            cls.num, suite)
        config['user_db_name'] = 'unittest{}_{}_user_manager'.format(
            cls.num, suite)
        config['validator_db_name'] = 'unittest{}_{}_validator'.format(
            cls.num, suite)
        config['staging_db_name'] = 'unittest{}_{}_staging'.format(
            cls.num, suite)
        dataactcore.config.CONFIG_DB = config

        # drop and re-create test user db/tables
        setupUserDB()
        # drop and re-create test job db/tables
        setupJobTrackerDB()
        # drop and re-create test error db/tables
        setupErrorDB()
        # drop and re-create test validation db/tables
        setupValidationDB()
        # load e-mail templates
        setupEmails()

        #get test users
        try:
            with open('test.json') as test_users_file:
                test_users = json.load(test_users_file)
            test_users = test_users
        except:
            #if no test.json, provide some default e-mail accounts for tests
            test_users = {}
            test_users['admin_email'] = '*****@*****.**'
            test_users['change_user_email'] = '*****@*****.**'
            test_users['password_reset_email'] = '*****@*****.**'
            test_users['inactive_email'] = '*****@*****.**'
            test_users['password_lock_email'] = '*****@*****.**'
            test_users['expired_lock_email'] = '*****@*****.**'
            test_users['agency_admin_email'] = '*****@*****.**'

            # This email is for a regular agency_user email that is to be used for testing functionality
            # expected by a normal, base user
            test_users['agency_user'] = '******'
        if 'approved_email' not in test_users:
            test_users['approved_email'] = '*****@*****.**'
        if 'submission_email' not in test_users:
            test_users['submission_email'] = '*****@*****.**'
        user_password = '******'
        admin_password = '******'

        #setup test users
        userEmails = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**",
            test_users["admin_email"], test_users["approved_email"],
            "*****@*****.**"
        ]
        userStatus = [
            "awaiting_confirmation", "email_confirmed", "awaiting_approval",
            "awaiting_approval", "awaiting_approval", "approved", "approved",
            "denied"
        ]
        userPermissions = [
            0, AccountType.AGENCY_USER, AccountType.AGENCY_USER,
            AccountType.AGENCY_USER, AccountType.AGENCY_USER,
            AccountType.WEBSITE_ADMIN + AccountType.AGENCY_USER,
            AccountType.AGENCY_USER, AccountType.AGENCY_USER
        ]

        # Add new users
        userDb = UserHandler()
        userDb.createUserWithPassword(test_users["submission_email"],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users["change_user_email"],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users["password_reset_email"],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users["inactive_email"],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users["password_lock_email"],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users['expired_lock_email'],
                                      user_password, Bcrypt())
        userDb.createUserWithPassword(test_users['agency_admin_email'],
                                      admin_password,
                                      Bcrypt(),
                                      permission=4)
        userDb.createUserWithPassword(test_users['agency_user'], user_password,
                                      Bcrypt())

        # Set the Agency for the agency user
        agencyUser = userDb.getUserByEmail(test_users['agency_user'])
        userDb.session.commit()
        cls.agency_user_id = agencyUser.user_id

        # Set the specified account to be expired
        expiredUser = userDb.getUserByEmail(test_users['expired_lock_email'])
        today = parse(time.strftime("%c"))
        expiredUser.last_login_date = (today -
                                       timedelta(days=120)).strftime("%c")
        userDb.session.commit()

        # Create users for status testing
        for index in range(len(userEmails)):
            email = userEmails[index]
            userDb.addUnconfirmedEmail(email)
            user = userDb.getUserByEmail(email)
            userDb.changeStatus(user, userStatus[index])
            userDb.setPermission(user, userPermissions[index])

        #set up approved user
        user = userDb.getUserByEmail(test_users['approved_email'])
        user.username = "******"
        userDb.setPassword(user, user_password, Bcrypt())
        cls.approved_user_id = user.user_id

        #set up admin user
        admin = userDb.getUserByEmail(test_users['admin_email'])
        userDb.setPassword(admin, admin_password, Bcrypt())
        admin.name = "Mr. Manager"
        admin.cgac_code = "SYS"
        userDb.session.commit()

        #set up status changed user
        statusChangedUser = userDb.getUserByEmail(
            test_users["change_user_email"])
        cls.status_change_user_id = statusChangedUser.user_id
        statusChangedUser.name = "Test User"
        statusChangedUser.user_status_id = userDb.getUserStatusId(
            "email_confirmed")
        userDb.session.commit()

        #set up deactivated user
        user = userDb.getUserByEmail(test_users["inactive_email"])
        user.last_login_date = time.strftime("%c")
        user.is_active = False
        userDb.session.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.interfaces = InterfaceHolder()
        cls.jobTracker = cls.interfaces.jobDb
        cls.errorDatabase = cls.interfaces.errorDb
        cls.userDb = cls.interfaces.userDb
        cls.local = CONFIG_BROKER['local']