def test_suds_to_row_no_compensation():
    suds_obj = make_suds('A Duns', 'Par Duns', 'Par Name')
    suds_obj.coreData.listOfExecutiveCompensationInformation = ''
    row = fileE.suds_to_row(suds_obj)
    assert row == fileE.Row('A Duns', 'Par Duns', 'Par Name', '', '', '', '', '', '', '', '', '', '')

    del suds_obj.coreData.listOfExecutiveCompensationInformation
    row = fileE.suds_to_row(suds_obj)
    assert row == fileE.Row('A Duns', 'Par Duns', 'Par Name', '', '', '', '', '', '', '', '', '', '')
示例#2
0
def test_generate_e_file_csv(monkeypatch, mock_broker_config_paths, database):
    """ Verify that an appropriate CSV is written, based on fileE.Row's structure """
    # Create an award so that we have _a_ duns
    sub = SubmissionFactory()
    database.session.add(sub)
    database.session.commit()

    ap = AwardProcurementFactory(submission_id=sub.submission_id)
    database.session.add(ap)
    database.session.commit()

    file_path = str(mock_broker_config_paths['broker_files'].join('e_test1'))
    job = JobFactory(job_status_id=JOB_STATUS_DICT['running'],
                     job_type_id=JOB_TYPE_DICT['file_upload'],
                     file_type_id=FILE_TYPE_DICT['executive_compensation'],
                     filename=file_path,
                     original_filename='e_test1',
                     submission_id=sub.submission_id)
    database.session.add(job)
    database.session.commit()

    monkeypatch.setattr(file_generation_manager.fileE, 'row_to_dict', Mock())
    file_generation_manager.fileE.row_to_dict.return_value = {}

    monkeypatch.setattr(file_generation_manager.fileE, 'retrieve_rows', Mock())
    file_generation_manager.fileE.retrieve_rows.return_value = [
        fileE.Row('a', 'b', 'c', 'd', '1a', '1b', '2a', '2b', '3a', '3b', '4a',
                  '4b', '5a', '5b'),
        fileE.Row('A', 'B', 'C', 'D', '1A', '1B', '2A', '2B', '3A', '3B', '4A',
                  '4B', '5A', '5B')
    ]

    monkeypatch.setattr(file_generation_manager, 'mark_job_status', Mock())

    file_gen_manager = FileGenerationManager(job, None, None,
                                             CONFIG_BROKER['local'])
    file_gen_manager.generate_e_file()

    expected = [[
        'AwardeeOrRecipientUniqueIdentifier',
        'AwardeeOrRecipientLegalEntityName', 'UltimateParentUniqueIdentifier',
        'UltimateParentLegalEntityName', 'HighCompOfficer1FullName',
        'HighCompOfficer1Amount', 'HighCompOfficer2FullName',
        'HighCompOfficer2Amount', 'HighCompOfficer3FullName',
        'HighCompOfficer3Amount', 'HighCompOfficer4FullName',
        'HighCompOfficer4Amount', 'HighCompOfficer5FullName',
        'HighCompOfficer5Amount'
    ],
                [
                    'a', 'b', 'c', 'd', '1a', '1b', '2a', '2b', '3a', '3b',
                    '4a', '4b', '5a', '5b'
                ],
                [
                    'A', 'B', 'C', 'D', '1A', '1B', '2A', '2B', '3A', '3B',
                    '4A', '4B', '5A', '5B'
                ]]
    assert read_file_rows(file_path) == expected
示例#3
0
def test_generate_e_file_csv(monkeypatch, mock_broker_config_paths, database):
    """ Verify that an appropriate CSV is written, based on fileE.Row's structure """
    # Create an award so that we have _a_ duns
    sub = SubmissionFactory()
    database.session.add(sub)
    database.session.commit()

    ap = AwardProcurementFactory(submission_id=sub.submission_id)
    database.session.add(ap)
    database.session.commit()

    file_path = str(mock_broker_config_paths['broker_files'].join('e_test1'))
    job = JobFactory(
        job_status=database.session.query(JobStatus).filter_by(name='running').one(),
        job_type=database.session.query(JobType).filter_by(name='file_upload').one(),
        file_type=database.session.query(FileType).filter_by(name='executive_compensation').one(),
        filename=file_path, original_filename='e_test1', submission_id=sub.submission_id,
    )
    database.session.add(job)
    database.session.commit()

    monkeypatch.setattr(file_generation_handler.fileE, 'row_to_dict', Mock())
    file_generation_handler.fileE.row_to_dict.return_value = {}

    monkeypatch.setattr(file_generation_handler.fileE, 'retrieve_rows', Mock())
    file_generation_handler.fileE.retrieve_rows.return_value = [
        fileE.Row('a', 'b', 'c', 'd', '1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b'),
        fileE.Row('A', 'B', 'C', 'D', '1A', '1B', '2A', '2B', '3A', '3B', '4A', '4B', '5A', '5B')
    ]

    monkeypatch.setattr(file_generation_handler, 'mark_job_status', Mock())

    with Flask(__name__).app_context():
        file_generation_handler.generate_e_file(database.session, job, is_local=True)

    expected = [
        ['AwardeeOrRecipientUniqueIdentifier',
         'AwardeeOrRecipientLegalEntityName',
         'UltimateParentUniqueIdentifier',
         'UltimateParentLegalEntityName',
         'HighCompOfficer1FullName', 'HighCompOfficer1Amount',
         'HighCompOfficer2FullName', 'HighCompOfficer2Amount',
         'HighCompOfficer3FullName', 'HighCompOfficer3Amount',
         'HighCompOfficer4FullName', 'HighCompOfficer4Amount',
         'HighCompOfficer5FullName', 'HighCompOfficer5Amount'],
        ['a', 'b', 'c', 'd', '1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b'],
        ['A', 'B', 'C', 'D', '1A', '1B', '2A', '2B', '3A', '3B', '4A', '4B', '5A', '5B']
    ]
    assert read_file_rows(file_path) == expected
def test_generate_e_file_csv(monkeypatch, mock_broker_config_paths, database):
    """Verify that an appropriate CSV is written, based on fileE.Row's
    structure"""
    # Create an award so that we have _a_ duns
    sess = database.session
    ap = AwardProcurementFactory()
    sess.add(ap)
    sess.commit()

    monkeypatch.setattr(jobQueue.fileE, 'retrieveRows', Mock())
    jobQueue.fileE.retrieveRows.return_value = [
        fileE.Row('a', 'b', 'c', '1a', '1b', '2a', '2b', '3a', '3b', '4a',
                  '4b', '5a', '5b'),
        fileE.Row('A', 'B', 'C', '1A', '1B', '2A', '2B', '3A', '3B', '4A',
                  '4B', '5A', '5B')
    ]

    monkeypatch.setattr(jobQueue, 'mark_job_status', Mock())
    jobQueue.generate_e_file(ap.submission_id,
                             1,
                             'uniq',
                             'uniq',
                             is_local=True)

    file_path = str(mock_broker_config_paths['broker_files'].join('uniq'))
    expected = [[
        'AwardeeOrRecipientUniqueIdentifier', 'UltimateParentUniqueIdentifier',
        'UltimateParentLegalEntityName', 'HighCompOfficer1FullName',
        'HighCompOfficer1Amount', 'HighCompOfficer2FullName',
        'HighCompOfficer2Amount', 'HighCompOfficer3FullName',
        'HighCompOfficer3Amount', 'HighCompOfficer4FullName',
        'HighCompOfficer4Amount', 'HighCompOfficer5FullName',
        'HighCompOfficer5Amount'
    ],
                [
                    'a', 'b', 'c', '1a', '1b', '2a', '2b', '3a', '3b', '4a',
                    '4b', '5a', '5b'
                ],
                [
                    'A', 'B', 'C', '1A', '1B', '2A', '2B', '3A', '3B', '4A',
                    '4B', '5A', '5B'
                ]]
    assert read_file_rows(file_path) == expected
def test_suds_to_row_too_many_compensation():
    suds_obj = make_suds('B Duns', 'Par DunsB', 'Par NameB')
    info = suds_obj.coreData.listOfExecutiveCompensationInformation
    info.executiveCompensationDetail = [Mock(compensation=i * 11.11) for i in range(1, 10)]
    for idx, person in enumerate(info.executiveCompensationDetail):
        # Can't do this in the constructor as "name" is a reserved word
        person.name = "Person {}".format(idx + 1)

    row = fileE.suds_to_row(suds_obj)
    assert row == fileE.Row(
        'B Duns', 'Par DunsB', 'Par NameB',
        'Person 9', 99.99, 'Person 8', 88.88, 'Person 7', 77.77,
        'Person 6', 66.66, 'Person 5', 55.55)
def test_sudsToRow_too_few_compensation():
    sudsObj = make_suds('B Duns', 'Par DunsB', 'Par NameB')
    info = sudsObj.coreData.listOfExecutiveCompensationInformation

    middle = Mock(compensation=111.11)
    middle.name = 'Middle Person'  # "name" is a reserved word
    top = Mock(compensation=222.22)
    top.name = 'Top Person'
    bottom = Mock(compensation=0.0)
    bottom.name = 'Bottom Person'

    info.executiveCompensationDetail = [middle, top, bottom]
    row = fileE.sudsToRow(sudsObj)
    assert row == fileE.Row('B Duns', 'Par DunsB', 'Par NameB', 'Top Person',
                            222.22, 'Middle Person', 111.11, 'Bottom Person',
                            0.0, '', '', '', '')  # fills out to 5 pairs