<commit_before>import os
import datetime
import pytest

from dataactcore.config import CONFIG_BROKER
from dataactcore.scripts import load_duns_exec_comp
from dataactcore.models.domainModels import SAMRecipient


def test_load_duns(database):
    """ Test a local run load duns with the test files """
    sess = database.session
    duns_dir = os.path.join(CONFIG_BROKER['path'], 'tests', 'unit', 'data', 'fake_sam_files', 'duns')

    load_duns_exec_comp.load_from_sam('DUNS', sess, True, duns_dir)

    # update if the fake DUNS file name/zip changes
    deactivation_date = '2021-02-07'

    expected_duns_results = {
        # Pulled active daily V1 record, not updated in V2 files
        '000000005': {
            'uei': None,
            'awardee_or_recipient_uniqu': '000000005',
            'registration_date': '2000-02-01',
            'activation_date': '2000-02-02',
            'expiration_date': '2000-02-25',
            'last_sam_mod_date': '2000-02-15',
            'deactivation_date': None,
            'legal_business_name': 'LEGAL BUSINESS NAME 000000005 V1 DAILY',
            'address_line_1': 'ADDRESS LINE 1 000000005 V1 DAILY',
            'address_line_2': 'ADDRESS LINE 2 000000005 V1 DAILY',
            'city': 'CITY 000000005 V1 DAILY',
            'state': 'ST 000000005 V1 DAILY',
            'zip': 'ZIP 000000005 V1 DAILY',
            'zip4': 'ZIP4 000000005 V1 DAILY',
            'country_code': 'COUNTRY 000000005 V1 DAILY',
            'congressional_district': 'CONGRESSIONAL DISTRICT 000000005 V1 DAILY',
            'business_types_codes': ['2X', 'MF'],
            'business_types': ['For Profit Organization', 'Manufacturer of Goods'],
            'dba_name': 'DBA NAME 000000005 V1 DAILY',
            'ultimate_parent_uei': None,
            'ultimate_parent_unique_ide': '000000007',
            # ultimate_parent_legal_enti derived via missing parent names
            'ultimate_parent_legal_enti': 'ULTIMATE PARENT LEGAL BUSINESS NAME G7 V2 BLANK DUNS DAILY',
            'historic': False
        }
    }
    expected_uei_results = {
        # Pulled active monthly record, slightly updated with deactivation date as sam_extract = 1
        # Also present in V2 but only as a delete, so update just the UEI and deactivation date
        'A1': {
            'uei': 'A1',
            'awardee_or_recipient_uniqu': '000000001',
            'registration_date': '1999-01-01',
            'activation_date': '1999-01-02',
            'expiration_date': '1999-01-25',
            'last_sam_mod_date': '1999-01-15',
            'deactivation_date': deactivation_date,
            'legal_business_name': 'LEGAL BUSINESS NAME 000000001 V1 MONTHLY',
            'address_line_1': 'ADDRESS LINE 1 000000001 V1 MONTHLY',
            'address_line_2': 'ADDRESS LINE 2 000000001 V1 MONTHLY',
            'city': 'CITY 000000001 V1 MONTHLY',
            'state': 'ST 000000001 V1 MONTHLY',
            'zip': 'ZIP 000000001 V1 MONTHLY',
            'zip4': 'ZIP4 000000001 V1 MONTHLY',<commit_msg>Fixing the test after the changes to how we backfill the legal entity parent name<commit_after>import os
import datetime
import pytest

from dataactcore.config import CONFIG_BROKER
from dataactcore.scripts import load_duns_exec_comp
from dataactcore.models.domainModels import SAMRecipient


def test_load_duns(database):
    """ Test a local run load duns with the test files """
    sess = database.session
    duns_dir = os.path.join(CONFIG_BROKER['path'], 'tests', 'unit', 'data', 'fake_sam_files', 'duns')

    load_duns_exec_comp.load_from_sam('DUNS', sess, True, duns_dir)

    # update if the fake DUNS file name/zip changes
    deactivation_date = '2021-02-07'

    expected_duns_results = {
        # Pulled active daily V1 record, not updated in V2 files
        '000000005': {
            'uei': None,
            'awardee_or_recipient_uniqu': '000000005',
            'registration_date': '2000-02-01',
            'activation_date': '2000-02-02',
            'expiration_date': '2000-02-25',
            'last_sam_mod_date': '2000-02-15',
            'deactivation_date': None,
            'legal_business_name': 'LEGAL BUSINESS NAME 000000005 V1 DAILY',
            'address_line_1': 'ADDRESS LINE 1 000000005 V1 DAILY',
            'address_line_2': 'ADDRESS LINE 2 000000005 V1 DAILY',
            'city': 'CITY 000000005 V1 DAILY',
            'state': 'ST 000000005 V1 DAILY',
            'zip': 'ZIP 000000005 V1 DAILY',
            'zip4': 'ZIP4 000000005 V1 DAILY',
            'country_code': 'COUNTRY 000000005 V1 DAILY',
            'congressional_district': 'CONGRESSIONAL DISTRICT 000000005 V1 DAILY',
            'business_types_codes': ['2X', 'MF'],
            'business_types': ['For Profit Organization', 'Manufacturer of Goods'],
            'dba_name': 'DBA NAME 000000005 V1 DAILY',
            'ultimate_parent_uei': None,
            'ultimate_parent_unique_ide': '000000007',
            # ultimate_parent_legal_enti derived via missing parent names
            'ultimate_parent_legal_enti': None,
            'historic': False
        }
    }
    expected_uei_results = {
        # Pulled active monthly record, slightly updated with deactivation date as sam_extract = 1
        # Also present in V2 but only as a delete, so update just the UEI and deactivation date
        'A1': {
            'uei': 'A1',
            'awardee_or_recipient_uniqu': '000000001',
            'registration_date': '1999-01-01',
            'activation_date': '1999-01-02',
            'expiration_date': '1999-01-25',
            'last_sam_mod_date': '1999-01-15',
            'deactivation_date': deactivation_date,
            'legal_business_name': 'LEGAL BUSINESS NAME 000000001 V1 MONTHLY',
            'address_line_1': 'ADDRESS LINE 1 000000001 V1 MONTHLY',
            'address_line_2': 'ADDRESS LINE 2 000000001 V1 MONTHLY',
            'city': 'CITY 000000001 V1 MONTHLY',
            'state': 'ST 000000001 V1 MONTHLY',
            'zip': 'ZIP 000000001 V1 MONTHLY',
            'zip4': 'ZIP4 000000001 V1 MONTHLY',
{'fraction_non_alphanumeric': 0.1035843472541927, 'fraction_numerical': 0.09799408089444261, 'mean_word_length': 2.578235294117647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 42, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3816284', 'n_tokens_mistral': 2395, 'n_tokens_neox': 1864, 'n_words': 516}