def test_update_tas_ids_has_match_closed(database, factory): """If there are models which match the TAS (with an defined end date), they should be modified""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 10), reporting_end_date=date(2010, 10, 31)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2010, 9, 1), internal_end_date=date(2010, 10, 15)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id == tas.account_num
def test_update_tas_ids_bad_dates(database, factory): """If the relevant TAS does not overlap the date of the submission, it should not be used""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2011, 1, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id is None
def test_update_account_nums_has_match_open_ended(database, factory): """ If there are models which match the TAS (with an undefined end date), they should be modified """ sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2010, 9, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.account_num is None sess.add_all([tas, model]) sess.commit() validationManager.update_account_nums(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.account_num == tas.account_num
def test_update_tas_ids_bad_dates(database, factory): """If the relevant TAS does not overlap the date of the submission, it should not be used""" sess = database.session submission = SubmissionFactory(reporting_start_date=date(2010, 10, 1), reporting_end_date=date(2010, 10, 1)) sess.add(submission) sess.flush() tas = TASFactory(internal_start_date=date(2011, 1, 1)) model = factory(submission_id=submission.submission_id, **tas.component_dict()) assert model.tas_id is None sess.add_all([tas, model]) sess.commit() validationManager.update_tas_ids(model.__class__, submission.submission_id) model = sess.query(model.__class__).one() # we'll only have one entry assert model.tas_id is None
def test_update_tas_ids_fiscal_year(database): """Fiscal year math should be accurate when checking TAS entries""" sess = database.session tas = TASFactory(internal_start_date=date(2010, 1, 1), internal_end_date=date(2010, 8, 31)) sf_133 = SF133Factory(fiscal_year=2011, period=1, **tas.component_dict()) sess.add_all([tas, sf_133]) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 9, 30) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id is None tas.internal_end_date = date(2010, 10, 31) sess.commit() load_sf133.update_tas_id(2011, 1) sess.refresh(sf_133) assert sf_133.tas_id == tas.account_num
def test_update_account_nums_fiscal_year(database): """ Fiscal year math should be accurate when checking TAS entries """ sess = database.session tas = TASFactory(internal_start_date=date(2010, 1, 1), internal_end_date=date(2010, 8, 31)) sf_133 = SF133Factory(fiscal_year=2011, period=1, **tas.component_dict()) sess.add_all([tas, sf_133]) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num is None tas.internal_end_date = date(2010, 9, 30) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num is None tas.internal_end_date = date(2010, 10, 31) sess.commit() load_sf133.update_account_num(2011, 1) sess.refresh(sf_133) assert sf_133.account_num == tas.account_num
def setUpClass(cls): """ Set up class-wide resources (test data) """ super(ErrorWarningTests, cls).setUpClass() logging.getLogger('dataactcore').setLevel(logging.ERROR) logging.getLogger('dataactvalidator').setLevel(logging.ERROR) with create_app().app_context(): # get the submission test users sess = GlobalDB.db().session cls.session = sess # set up default e-mails for tests admin_user = sess.query(User).filter( User.email == cls.test_users['admin_user']).one() cls.validator = ValidationManager( directory=CONFIG_SERVICES['error_report_path']) # Just have one valid submission and then keep on reloading files cls.submission_id = insert_submission(sess, admin_user.user_id, cgac_code='SYS', start_date='01/2001', end_date='03/2001', is_quarter=True) cls.submission = sess.query(Submission).filter_by( submission_id=cls.submission_id).one() cls.val_job = insert_job( cls.session, FILE_TYPE_DICT['appropriations'], JOB_STATUS_DICT['ready'], JOB_TYPE_DICT['csv_record_validation'], cls.submission_id, filename=JOB_TYPE_DICT['csv_record_validation']) cls.original_reports = set( os.listdir(CONFIG_SERVICES['error_report_path'])) # adding TAS to ensure valid file is valid tas1 = TASFactory(account_num=1, allocation_transfer_agency='019', agency_identifier='072', beginning_period_of_availa=None, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0306', sub_account_code='000', internal_start_date='01-01-2000') tas2 = TASFactory(account_num=2, allocation_transfer_agency=None, agency_identifier='019', beginning_period_of_availa='2016', ending_period_of_availabil='2016', availability_type_code=None, main_account_code='0113', sub_account_code='000', internal_start_date='01-01-2000') tas3 = TASFactory(account_num=3, allocation_transfer_agency=None, agency_identifier='028', beginning_period_of_availa=None, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0406', sub_account_code='000', internal_start_date='01-01-2000') tas4 = TASFactory(account_num=4, allocation_transfer_agency=None, agency_identifier='028', beginning_period_of_availa='2010', ending_period_of_availabil='2011', availability_type_code=None, main_account_code='0406', sub_account_code='000', internal_start_date='01-01-2000') tas5 = TASFactory(account_num=5, allocation_transfer_agency='069', agency_identifier='013', beginning_period_of_availa=None, ending_period_of_availabil=None, availability_type_code='X', main_account_code='2050', sub_account_code='005', internal_start_date='01-01-2000') tas6 = TASFactory(account_num=6, allocation_transfer_agency='028', agency_identifier='028', beginning_period_of_availa=None, ending_period_of_availabil=None, availability_type_code='X', main_account_code='8007', sub_account_code='000', internal_start_date='01-01-2000') tas7 = TASFactory(account_num=7, allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa=None, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0100', sub_account_code='000', internal_start_date='01-01-2000') tas8 = TASFactory(account_num=8, allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2010', ending_period_of_availabil='2011', availability_type_code=None, main_account_code='0100', sub_account_code='000', internal_start_date='01-01-2000') tas9 = TASFactory(account_num=9, allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2014', ending_period_of_availabil='2015', availability_type_code=None, main_account_code='0100', sub_account_code='000', internal_start_date='01-01-2000') tas10 = TASFactory(account_num=10, allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2015', ending_period_of_availabil='2016', availability_type_code=None, main_account_code='0100', sub_account_code='000', internal_start_date='01-01-2000') sess.add_all( [tas1, tas2, tas3, tas4, tas5, tas6, tas7, tas8, tas9, tas10]) # adding GTAS to ensure valid file is valid gtas1 = SF133Factory(tas=concat_tas_dict(tas1.component_dict()), allocation_transfer_agency='019', agency_identifier='072', beginning_period_of_availa=None, line=1009, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0306', sub_account_code='000', period=6, fiscal_year=2001) gtas2 = SF133Factory(tas=concat_tas_dict(tas2.component_dict()), allocation_transfer_agency=None, agency_identifier='019', beginning_period_of_availa='2016', line=1009, ending_period_of_availabil='2016', availability_type_code=None, main_account_code='0113', sub_account_code='000', period=6, fiscal_year=2001) gtas3 = SF133Factory(tas=concat_tas_dict(tas3.component_dict()), allocation_transfer_agency=None, agency_identifier='028', beginning_period_of_availa=None, line=1009, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0406', sub_account_code='000', period=6, fiscal_year=2001) gtas4 = SF133Factory(tas=concat_tas_dict(tas4.component_dict()), allocation_transfer_agency=None, agency_identifier='028', beginning_period_of_availa='2010', line=1009, ending_period_of_availabil='2011', availability_type_code=None, main_account_code='0406', sub_account_code='000', period=6, fiscal_year=2001) gtas5 = SF133Factory(tas=concat_tas_dict(tas5.component_dict()), allocation_transfer_agency='069', agency_identifier='013', beginning_period_of_availa=None, line=1009, ending_period_of_availabil=None, availability_type_code='X', main_account_code='2050', sub_account_code='005', period=6, fiscal_year=2001) gtas6 = SF133Factory(tas=concat_tas_dict(tas6.component_dict()), allocation_transfer_agency='028', agency_identifier='028', beginning_period_of_availa=None, line=1009, ending_period_of_availabil=None, availability_type_code='X', main_account_code='8007', sub_account_code='000', period=6, fiscal_year=2001) gtas7 = SF133Factory(tas=concat_tas_dict(tas7.component_dict()), allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa=None, line=1009, ending_period_of_availabil=None, availability_type_code='X', main_account_code='0100', sub_account_code='000', period=6, fiscal_year=2001) gtas8 = SF133Factory(tas=concat_tas_dict(tas8.component_dict()), allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2010', line=1009, ending_period_of_availabil='2011', availability_type_code=None, main_account_code='0100', sub_account_code='000', period=6, fiscal_year=2001) gtas9 = SF133Factory(tas=concat_tas_dict(tas9.component_dict()), allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2014', line=1009, ending_period_of_availabil='2015', availability_type_code=None, main_account_code='0100', sub_account_code='000', period=6, fiscal_year=2001) gtas10 = SF133Factory(tas=concat_tas_dict(tas10.component_dict()), allocation_transfer_agency=None, agency_identifier='049', beginning_period_of_availa='2015', line=1009, ending_period_of_availabil='2016', availability_type_code=None, main_account_code='0100', sub_account_code='000', period=6, fiscal_year=2001) sess.add_all([ gtas1, gtas2, gtas3, gtas4, gtas5, gtas6, gtas7, gtas8, gtas9, gtas10 ]) sess.commit()