from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory
from tests.unit.dataactvalidator.utils import number_of_errors, query_columns

_FILE = 'fabs38_detached_award_financial_assistance_2'


def test_column_headers(database):
    expected_subset = {"row_number", "awarding_office_code"}
    actual = set(query_columns(_FILE, database))
    assert expected_subset == actual


def test_success(database):
    """ AwardingOfficeCode must be six characters long. """

    det_award_1 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='AAAAAA')
    det_award_2 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='111111')
    det_award_3 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='AAA111')
    det_award_4 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='')
    det_award_5 = DetachedAwardFinancialAssistanceFactory(awarding_office_code=None)
    errors = number_of_errors(_FILE, database, models=[det_award_1, det_award_2, det_award_3, det_award_4, det_award_5])
    assert errors == 0


def test_failure(database):
    """ AwardingOfficeCode must be six characters long. """

    det_award_1 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='AAAA1')
    det_award_2 = DetachedAwardFinancialAssistanceFactory(awarding_office_code='AAAAAAA')
    errors = number_of_errors(_FILE, database, models=[det_award_1, det_award_2])
    assert errors == 2

[((520, 590), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '"""AAAAAA"""'}), "(awarding_office_code='AAAAAA')\n", (559, 590), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((609, 679), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '"""111111"""'}), "(awarding_office_code='111111')\n", (648, 679), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((698, 768), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '"""AAA111"""'}), "(awarding_office_code='AAA111')\n", (737, 768), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((787, 851), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '""""""'}), "(awarding_office_code='')\n", (826, 851), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((870, 936), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': 'None'}), '(awarding_office_code=None)\n', (909, 936), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((950, 1061), 'tests.unit.dataactvalidator.utils.number_of_errors', 'number_of_errors', (['_FILE', 'database'], {'models': '[det_award_1, det_award_2, det_award_3, det_award_4, det_award_5]'}), '(_FILE, database, models=[det_award_1, det_award_2,\n    det_award_3, det_award_4, det_award_5])\n', (966, 1061), False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n'), ((1190, 1259), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '"""AAAA1"""'}), "(awarding_office_code='AAAA1')\n", (1229, 1259), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((1278, 1349), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', ([], {'awarding_office_code': '"""AAAAAAA"""'}), "(awarding_office_code='AAAAAAA')\n", (1317, 1349), False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((1363, 1431), 'tests.unit.dataactvalidator.utils.number_of_errors', 'number_of_errors', (['_FILE', 'database'], {'models': '[det_award_1, det_award_2]'}), '(_FILE, database, models=[det_award_1, det_award_2])\n', (1379, 1431), False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n'), ((342, 372), 'tests.unit.dataactvalidator.utils.query_columns', 'query_columns', (['_FILE', 'database'], {}), '(_FILE, database)\n', (355, 372), False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n')]