Beispiel #1
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
Beispiel #2
0
def test_generate_e_file_query(monkeypatch, mock_broker_config_paths,
                               database):
    """ Verify that generate_e_file makes an appropriate query (matching both D1 and D2 entries) """
    # Generate several file D1 entries, largely with the same submission_id, and with two overlapping DUNS. Generate
    # several D2 entries with the same submission_id as well
    sess = database.session
    sub = SubmissionFactory()
    sub_2 = SubmissionFactory()
    sess.add_all([sub, sub_2])
    sess.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()

    model = AwardProcurementFactory(submission_id=sub.submission_id)
    aps = [
        AwardProcurementFactory(submission_id=sub.submission_id)
        for _ in range(4)
    ]
    afas = [
        AwardFinancialAssistanceFactory(submission_id=sub.submission_id)
        for _ in range(5)
    ]
    same_duns = AwardProcurementFactory(
        submission_id=sub.submission_id,
        awardee_or_recipient_uniqu=model.awardee_or_recipient_uniqu)
    unrelated = AwardProcurementFactory(submission_id=sub_2.submission_id)
    sess.add_all(aps + afas + [model, same_duns, unrelated])
    sess.commit()

    monkeypatch.setattr(file_generation_manager, 'mark_job_status', Mock())
    monkeypatch.setattr(file_generation_manager.fileE, 'retrieve_rows',
                        Mock(return_value=[]))

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

    # [0][0] gives us the first, non-keyword args
    call_args = file_generation_manager.fileE.retrieve_rows.call_args[0][0]
    expected = [ap.awardee_or_recipient_uniqu for ap in aps]
    expected.append(model.awardee_or_recipient_uniqu)
    expected.extend(afa.awardee_or_recipient_uniqu for afa in afas)
    assert list(sorted(call_args)) == list(sorted(expected))