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

[((16, 18, 16, 88), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((17, 18, 17, 88), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((18, 18, 18, 88), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((19, 18, 19, 82), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((20, 18, 20, 84), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((21, 13, 21, 120), 'tests.unit.dataactvalidator.utils.number_of_errors', 'number_of_errors', (), '', False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n'), ((28, 18, 28, 87), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((29, 18, 29, 89), 'tests.unit.dataactcore.factories.staging.DetachedAwardFinancialAssistanceFactory', 'DetachedAwardFinancialAssistanceFactory', (), '', False, 'from tests.unit.dataactcore.factories.staging import DetachedAwardFinancialAssistanceFactory\n'), ((30, 13, 30, 81), 'tests.unit.dataactvalidator.utils.number_of_errors', 'number_of_errors', (), '', False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n'), ((9, 17, 9, 47), 'tests.unit.dataactvalidator.utils.query_columns', 'query_columns', ({(9, 31, 9, 36): '_FILE', (9, 38, 9, 46): 'database'}, {}), '(_FILE, database)', False, 'from tests.unit.dataactvalidator.utils import number_of_errors, query_columns\n')]