Exemplo n.º 1
0
def test_success(database):
    """ If both are submitted, AwardingSubTierAgencyCode and AwardingOfficeCode must belong to the same
        AwardingAgencyCode (per the Federal Hierarchy). Ignored if one or both are missing. """

    cgac = CGAC(cgac_id=1, cgac_code='001', agency_name='test')
    frec = FREC(frec_id=1, cgac_id=1, frec_code='0001', agency_name='test2')
    # sub tier codes are different on these offices to prove that we don't care if the office is under that sub tier
    # as long as the top tier codes match
    office_1 = OfficeFactory(office_code='12345a', sub_tier_code='abcd', agency_code=cgac.cgac_code)
    office_2 = OfficeFactory(office_code='123457', sub_tier_code='efgh', agency_code=frec.frec_code)
    agency_1 = SubTierAgency(sub_tier_agency_code='0000', cgac_id=1, frec_id=1, is_frec=False)
    agency_2 = SubTierAgency(sub_tier_agency_code='0001', cgac_id=1, frec_id=1, is_frec=True)

    # Same agency for cgac
    det_award_1 = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
                                                          awarding_office_code=office_1.office_code)
    # Same agency for cgac (uppercased)
    det_award_2 = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
                                                          awarding_office_code=office_1.office_code.upper())
    # Same agency for frec
    det_award_3 = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c=agency_2.sub_tier_agency_code,
                                                          awarding_office_code=office_2.office_code)
    # Missing sub tier code
    det_award_4 = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c='',
                                                          awarding_office_code=office_2.office_code)
    # Missing office code
    det_award_5 = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
                                                          awarding_office_code=None)

    errors = number_of_errors(_FILE, database, models=[cgac, frec, office_1, office_2, agency_1, agency_2, det_award_1,
                                                       det_award_2, det_award_3, det_award_4, det_award_5])
    assert errors == 0
    def insert_agency_user_submission_data(sess, submission_id):
        """Insert jobs for the submission, and create a CGAC, FREC, and SubTierAgency"""
        for job_type in ['file_upload', 'csv_record_validation', 'validation']:
            sess.add(
                Job(file_type_id=FILE_TYPE_DICT['fabs'],
                    job_status_id=FILE_STATUS_DICT['complete'],
                    job_type_id=JOB_TYPE_DICT[job_type],
                    submission_id=submission_id,
                    original_filename=None,
                    file_size=None,
                    number_of_rows=None))
            sess.commit()

        cgac = CGAC(cgac_code="NOT")
        sess.add(cgac)
        sess.commit()
        frec = FREC(cgac_id=cgac.cgac_id, frec_code="BLAH")
        sess.add(frec)
        sess.commit()
        sub = SubTierAgency(sub_tier_agency_code="WRONG",
                            cgac_id=cgac.cgac_id,
                            frec_id=frec.frec_id,
                            is_frec=False)
        sess.add(sub)
        sess.commit()
def update_frecs(models, new_data, cgac_dict):
    """Modify existing models or create new ones"""
    for _, row in new_data.iterrows():
        if row['cgac_code'] not in cgac_dict:
            new_data.drop(_)
            continue
        row['cgac_id'] = cgac_dict[row['cgac_code']]
        frec_code = row['frec_code']
        agency_abbreviation = row['agency_abbreviation']
        if frec_code not in models:
            models[frec_code] = FREC()
        for field, value in row.items():
            if field == 'agency_name' and agency_abbreviation:
                value = ("%s (%s)" % (value, agency_abbreviation))
            setattr(models[frec_code], field, value)
Exemplo n.º 4
0
def test_failure(database):
    """ Test failure if both are submitted, AwardingSubTierAgencyCode and AwardingOfficeCode must belong to the same
        AwardingAgencyCode (per the Federal Hierarchy). """

    cgac = CGAC(cgac_id=1, cgac_code='001', agency_name='test')
    frec = FREC(frec_id=1, cgac_id=1, frec_code='0001', agency_name='test2')
    office = OfficeFactory(office_code='123456', sub_tier_code='abcd', agency_code=cgac.cgac_code)
    agency = SubTierAgency(sub_tier_agency_code='0000', frec_id=1, cgac_id=1, is_frec=True)

    # Sub tier is FREC, office is based on CGAC, the numbers are different
    det_award = DetachedAwardFinancialAssistanceFactory(awarding_sub_tier_agency_c=agency.sub_tier_agency_code,
                                                        awarding_office_code=office.office_code)

    errors = number_of_errors(_FILE, database, models=[det_award, cgac, frec, office, agency])
    assert errors == 1
Exemplo n.º 5
0
def update_frecs(models, new_data, cgac_dict):
    """ Modify existing models or create new ones.

        Args
            models: all existing frec models in the database
            new_data: All the entries gathered from the agency file
            cgac_dict: A dictionary of all cgacs in the database
    """
    for _, row in new_data.iterrows():
        if row['cgac_code'] not in cgac_dict:
            new_data.drop(_)
            continue
        row['cgac_id'] = cgac_dict[row['cgac_code']]
        frec_code = row['frec_code']
        agency_abbreviation = row['agency_abbreviation']
        if frec_code not in models:
            models[frec_code] = FREC()
        for field, value in row.items():
            if field == 'agency_name' and agency_abbreviation:
                value = ("%s (%s)" % (value, agency_abbreviation))
            setattr(models[frec_code], field, value)
def test_failure(database):
    """ Test failure if both are submitted, FundingSubTierAgencyCode and FundingOfficeCode must belong to the same
        FundingAgencyCode (per the Federal Hierarchy).
    """
    cgac = CGAC(cgac_id=1, cgac_code='001', agency_name='test')
    frec = FREC(frec_id=1, cgac_id=1, frec_code='0001', agency_name='test2')
    office = OfficeFactory(office_code='123456',
                           sub_tier_code='abcd',
                           agency_code=cgac.cgac_code)
    agency = SubTierAgency(sub_tier_agency_code='0000',
                           frec_id=1,
                           cgac_id=1,
                           is_frec=True)

    # Sub tier is FREC, office is based on CGAC, the numbers are different
    fabs = FABSFactory(funding_sub_tier_agency_co=agency.sub_tier_agency_code,
                       funding_office_code=office.office_code,
                       correction_delete_indicatr='')

    errors = number_of_errors(_FILE,
                              database,
                              models=[fabs, cgac, frec, office, agency])
    assert errors == 1
def test_success(database):
    """ If both are submitted, AwardingSubTierAgencyCode and AwardingOfficeCode must belong to the same
        AwardingAgencyCode (per the Federal Hierarchy). Ignored if one or both are missing.
    """
    cgac = CGAC(cgac_id=1, cgac_code='001', agency_name='test')
    frec = FREC(frec_id=1, cgac_id=1, frec_code='0001', agency_name='test2')
    # sub tier codes are different on these offices to prove that we don't care if the office is under that sub tier
    # as long as the top tier codes match
    office_1 = OfficeFactory(office_code='12345a',
                             sub_tier_code='abcd',
                             agency_code=cgac.cgac_code)
    office_2 = OfficeFactory(office_code='123457',
                             sub_tier_code='efgh',
                             agency_code=frec.frec_code)
    agency_1 = SubTierAgency(sub_tier_agency_code='a000',
                             cgac_id=1,
                             frec_id=1,
                             is_frec=False)
    agency_2 = SubTierAgency(sub_tier_agency_code='0001',
                             cgac_id=1,
                             frec_id=1,
                             is_frec=True)

    # Same agency for cgac
    fabs_1 = FABSFactory(
        awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
        awarding_office_code=office_1.office_code,
        correction_delete_indicatr='')
    # Same agency for cgac (uppercased)
    fabs_2 = FABSFactory(
        awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code.upper(),
        awarding_office_code=office_1.office_code.upper(),
        correction_delete_indicatr=None)
    # Same agency for frec
    fabs_3 = FABSFactory(
        awarding_sub_tier_agency_c=agency_2.sub_tier_agency_code,
        awarding_office_code=office_2.office_code,
        correction_delete_indicatr='c')
    # Missing sub tier code
    fabs_4 = FABSFactory(awarding_sub_tier_agency_c='',
                         awarding_office_code=office_2.office_code,
                         correction_delete_indicatr='C')
    # Missing office code
    fabs_5 = FABSFactory(
        awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
        awarding_office_code=None,
        correction_delete_indicatr='')
    # Ignore correction delete indicator of D
    fabs_6 = FABSFactory(
        awarding_sub_tier_agency_c=agency_1.sub_tier_agency_code,
        awarding_office_code=office_2.office_code,
        correction_delete_indicatr='d')

    errors = number_of_errors(_FILE,
                              database,
                              models=[
                                  cgac, frec, office_1, office_2, agency_1,
                                  agency_2, fabs_1, fabs_2, fabs_3, fabs_4,
                                  fabs_5, fabs_6
                              ])
    assert errors == 0
Exemplo n.º 8
0
    def setUpClass(cls):
        """Set up class-wide resources (test data)"""
        super(ListLatestPublishedFileTests, cls).setUpClass()
        # TODO: refactor into a pytest fixture

        with create_app().app_context():
            # get the submission test user
            sess = GlobalDB.db().session
            cls.session = sess

            other_user = sess.query(User).filter(
                User.email == cls.test_users['agency_user']).one()
            cls.other_user_email = other_user.email
            cls.other_user_id = other_user.user_id
            cls.submission_user_id = other_user.user_id

            # ======= Reference ======
            cgac = CGAC(cgac_id=11, cgac_code='111', agency_name='CGAC 1')
            frec = FREC(frec_id=12,
                        cgac_id=11,
                        frec_code='2222',
                        agency_name='FREC 2')
            cgac2 = CGAC(cgac_id=13, cgac_code='333', agency_name='CGAC 3')
            sess.add_all([cgac, frec, cgac2])
            sess.commit()

            year = 2020
            period = 6
            diff_year = 2021
            diff_period = 7

            # ======= DABS =======
            cls.dabs_sub_unpub = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac2.cgac_code,
                reporting_fiscal_year=1999,
                reporting_fisacal_period=2,
                publish_status_id=PUBLISH_STATUS_DICT['unpublished'],
                is_fabs=False)
            cls.dabs_sub_pub_twice = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=year,
                reporting_fisacal_period=period,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=False)
            cls.setup_published_submission(sess,
                                           cls.dabs_sub_pub_twice,
                                           date='01/01/2020',
                                           is_fabs=False)
            cls.setup_published_submission(sess,
                                           cls.dabs_sub_pub_twice,
                                           date='01/02/2020',
                                           is_fabs=False)

            cls.dabs_sub_pub_diff_agency = insert_submission(
                sess,
                cls.submission_user_id,
                frec_code=frec.frec_code,
                reporting_fiscal_year=year,
                reporting_fisacal_period=period,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=False)
            cls.setup_published_submission(sess,
                                           cls.dabs_sub_pub_diff_agency,
                                           is_fabs=False)

            cls.dabs_sub_pub_diff_year = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=diff_year,
                reporting_fisacal_period=period,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=False)
            cls.setup_published_submission(sess,
                                           cls.dabs_sub_pub_diff_year,
                                           is_fabs=False)

            cls.dabs_sub_pub_diff_period = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=year,
                reporting_fisacal_period=diff_period,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=False)
            cls.setup_published_submission(sess,
                                           cls.dabs_sub_pub_diff_period,
                                           is_fabs=False)

            # ======= FABS =======
            cls.fabs_sub_unpub = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code='333',
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=1,
                is_fabs=True)

            cls.fabs_sub_pub = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=True)
            cls.setup_published_submission(sess,
                                           cls.fabs_sub_pub,
                                           date='10/01/2000',
                                           is_fabs=True)
            cls.fabs_sub_pub_2 = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=True)
            cls.setup_published_submission(sess,
                                           cls.fabs_sub_pub_2,
                                           date='10/02/2000',
                                           is_fabs=True)

            cls.fabs_sub_pub_diff_agency = insert_submission(
                sess,
                cls.submission_user_id,
                frec_code=frec.frec_code,
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=True)
            cls.setup_published_submission(sess,
                                           cls.fabs_sub_pub_diff_agency,
                                           date='10/01/2000',
                                           is_fabs=True)

            cls.fabs_sub_pub_diff_year = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=True)
            cls.setup_published_submission(sess,
                                           cls.fabs_sub_pub_diff_year,
                                           date='10/01/2001',
                                           is_fabs=True)

            cls.fabs_sub_pub_diff_period = insert_submission(
                sess,
                cls.submission_user_id,
                cgac_code=cgac.cgac_code,
                reporting_fiscal_year=None,
                reporting_fisacal_period=None,
                publish_status_id=PUBLISH_STATUS_DICT['published'],
                is_fabs=True)
            cls.setup_published_submission(sess,
                                           cls.fabs_sub_pub_diff_period,
                                           date='01/01/2001',
                                           is_fabs=True)
Exemplo n.º 9
0
    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']