def test_get_status_invalid_type(database):
    """ Test get status function for all versions of an "invalid" file type """
    sub_1 = SubmissionFactory(submission_id=1, d2_submission=False)
    sub_2 = SubmissionFactory(submission_id=2, d2_submission=True)

    database.session.add_all([sub_1, sub_2])
    database.session.commit()

    # Getting fabs for non-fabs submissions
    json_response = fileHandler.get_status(sub_1, 'fabs')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content[
        'message'] == 'fabs is not a valid file type for this submission'

    # Getting award for non-dabs submissions
    json_response = fileHandler.get_status(sub_2, 'award')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content[
        'message'] == 'award is not a valid file type for this submission'

    # Getting completely not allowed type
    json_response = fileHandler.get_status(sub_1, 'approp')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['message'] == 'approp is not a valid file type'
def test_get_status_invalid_type(database):
    """ Test get status function for all versions of an "invalid" file type """
    sub_1 = SubmissionFactory(submission_id=1, d2_submission=False)
    sub_2 = SubmissionFactory(submission_id=2, d2_submission=True)

    database.session.add_all([sub_1, sub_2])
    database.session.commit()

    # Getting fabs for non-fabs submissions
    json_response = fileHandler.get_status(sub_1, 'fabs')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['message'] == 'fabs is not a valid file type for this submission'

    # Getting award for non-dabs submissions
    json_response = fileHandler.get_status(sub_2, 'award')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['message'] == 'award is not a valid file type for this submission'

    # Getting completely not allowed type
    json_response = fileHandler.get_status(sub_1, 'approp')
    assert json_response.status_code == 400
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['message'] == 'approp is not a valid file type'
def test_get_status_fabs(database):
    """ Test get status function for a fabs submission """
    sess = database.session

    sub = SubmissionFactory(submission_id=1, d2_submission=True)
    job_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=sess.query(JobType).filter_by(name='file_upload').one(),
        file_type=sess.query(FileType).filter_by(name='fabs').one(),
        job_status=sess.query(JobStatus).filter_by(name='finished').one(),
        number_of_errors=0,
        number_of_warnings=0)
    job_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=sess.query(JobType).filter_by(
            name='csv_record_validation').one(),
        file_type=sess.query(FileType).filter_by(name='fabs').one(),
        job_status=sess.query(JobStatus).filter_by(name='finished').one(),
        number_of_errors=0,
        number_of_warnings=4)

    sess.add_all([sub, job_up, job_val])
    sess.commit()

    json_response = fileHandler.get_status(sub)
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['fabs'] == {
        'status': 'finished',
        'has_errors': False,
        'has_warnings': True,
        'message': ''
    }
Exemplo n.º 4
0
def test_get_status_fabs(database):
    """ Test get status function for a fabs submission """
    sess = database.session

    sub = SubmissionFactory(submission_id=1, d2_submission=True)
    job_up = JobFactory(submission_id=sub.submission_id,
                        job_type_id=JOB_TYPE_DICT['file_upload'],
                        file_type_id=FILE_TYPE_DICT['fabs'],
                        job_status_id=JOB_STATUS_DICT['finished'],
                        number_of_errors=0,
                        number_of_warnings=0)
    job_val = JobFactory(submission_id=sub.submission_id,
                         job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                         file_type_id=FILE_TYPE_DICT['fabs'],
                         job_status_id=JOB_STATUS_DICT['finished'],
                         number_of_errors=0,
                         number_of_warnings=4)

    sess.add_all([sub, job_up, job_val])
    sess.commit()

    json_response = fileHandler.get_status(sub)
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['fabs'] == {
        'status': 'finished',
        'has_errors': False,
        'has_warnings': True,
        'message': ''
    }
def test_get_status_fabs(database):
    """ Test get status function for a fabs submission """
    sess = database.session

    sub = SubmissionFactory(submission_id=1, d2_submission=True)
    job_up = JobFactory(submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['file_upload'],
                        file_type_id=FILE_TYPE_DICT['fabs'], job_status_id=JOB_STATUS_DICT['finished'],
                        number_of_errors=0, number_of_warnings=0)
    job_val = JobFactory(submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                         file_type_id=FILE_TYPE_DICT['fabs'], job_status_id=JOB_STATUS_DICT['finished'],
                         number_of_errors=0, number_of_warnings=4)

    sess.add_all([sub, job_up, job_val])
    sess.commit()

    json_response = fileHandler.get_status(sub)
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert json_content['fabs'] == {'status': 'finished', 'has_errors': False, 'has_warnings': True, 'message': ''}
 def check_status(submission):
     return get_status(submission)
Exemplo n.º 7
0
 def check_status(submission, type):
     return get_status(submission, type)
def test_get_status_dabs(database):
    """ Test get status function for a dabs submission, including all possible statuses and case insensitivity """
    sess = database.session

    sub = SubmissionFactory(submission_id=1, d2_submission=False)
    upload_job = sess.query(JobType).filter_by(name='file_upload').one()
    validation_job = sess.query(JobType).filter_by(
        name='csv_record_validation').one()
    finished_status = sess.query(JobStatus).filter_by(name='finished').one()

    # Completed, warnings, errors
    job_1_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(name='appropriations').one(),
        job_status=finished_status,
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    job_1_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=validation_job,
        file_type=sess.query(FileType).filter_by(name='appropriations').one(),
        job_status=finished_status,
        number_of_errors=10,
        number_of_warnings=4,
        error_message=None)
    # Invalid upload
    job_2_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(
            name='program_activity').one(),
        job_status=sess.query(JobStatus).filter_by(name='invalid').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    job_2_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=validation_job,
        file_type=sess.query(FileType).filter_by(
            name='program_activity').one(),
        job_status=sess.query(JobStatus).filter_by(name='waiting').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    # Validating
    job_3_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(name='award_financial').one(),
        job_status=finished_status,
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    job_3_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=validation_job,
        file_type=sess.query(FileType).filter_by(name='award_financial').one(),
        job_status=sess.query(JobStatus).filter_by(name='running').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    # Uploading
    job_4_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(name='award').one(),
        job_status=sess.query(JobStatus).filter_by(name='running').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    job_4_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=validation_job,
        file_type=sess.query(FileType).filter_by(name='award').one(),
        job_status=sess.query(JobStatus).filter_by(name='ready').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    # Invalid on validation
    job_5_up = JobFactory(submission_id=sub.submission_id,
                          job_type=upload_job,
                          file_type=sess.query(FileType).filter_by(
                              name='award_procurement').one(),
                          job_status=finished_status,
                          number_of_errors=0,
                          number_of_warnings=0,
                          error_message=None)
    job_5_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=validation_job,
        file_type=sess.query(FileType).filter_by(
            name='award_procurement').one(),
        job_status=sess.query(JobStatus).filter_by(name='invalid').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    # Failed
    job_6_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(
            name='executive_compensation').one(),
        job_status=sess.query(JobStatus).filter_by(name='failed').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message='test message')
    # Ready
    job_7_up = JobFactory(
        submission_id=sub.submission_id,
        job_type=upload_job,
        file_type=sess.query(FileType).filter_by(name='sub_award').one(),
        job_status=sess.query(JobStatus).filter_by(name='ready').one(),
        number_of_errors=0,
        number_of_warnings=0,
        error_message=None)
    # Waiting
    job_8_val = JobFactory(
        submission_id=sub.submission_id,
        job_type=sess.query(JobType).filter_by(name='validation').one(),
        file_type=None,
        job_status=sess.query(JobStatus).filter_by(name='waiting').one(),
        number_of_errors=0,
        number_of_warnings=5,
        error_message=None)

    sess.add_all([
        sub, job_1_up, job_1_val, job_2_up, job_2_val, job_3_up, job_3_val,
        job_4_up, job_4_val, job_5_up, job_5_val, job_6_up, job_7_up, job_8_val
    ])
    sess.commit()

    # Get all statuses
    json_response = fileHandler.get_status(sub)
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert len(json_content) == 8
    assert json_content['appropriations'] == {
        'status': 'finished',
        'has_errors': True,
        'has_warnings': True,
        'message': ''
    }
    assert json_content['program_activity'] == {
        'status': 'failed',
        'has_errors': True,
        'has_warnings': False,
        'message': ''
    }
    assert json_content['award_financial'] == {
        'status': 'running',
        'has_errors': False,
        'has_warnings': False,
        'message': ''
    }
    assert json_content['award'] == {
        'status': 'uploading',
        'has_errors': False,
        'has_warnings': False,
        'message': ''
    }
    assert json_content['award_procurement'] == {
        'status': 'finished',
        'has_errors': True,
        'has_warnings': False,
        'message': ''
    }
    assert json_content['executive_compensation'] == {
        'status': 'failed',
        'has_errors': True,
        'has_warnings': False,
        'message': 'test message'
    }
    assert json_content['sub_award'] == {
        'status': 'ready',
        'has_errors': False,
        'has_warnings': False,
        'message': ''
    }
    assert json_content['cross'] == {
        'status': 'ready',
        'has_errors': False,
        'has_warnings': False,
        'message': ''
    }

    # Get just one status (ignore case)
    json_response = fileHandler.get_status(sub, 'awArd')
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert len(json_content) == 1
    assert json_content['award'] == {
        'status': 'uploading',
        'has_errors': False,
        'has_warnings': False,
        'message': ''
    }
 def check_status(submission):
     return get_status(submission)
 def check_status(submission, type):
     return get_status(submission, type)
def test_get_status_dabs(database):
    """ Test get status function for a dabs submission, including all possible statuses and case insensitivity """
    sess = database.session

    sub = SubmissionFactory(submission_id=1, d2_submission=False)
    upload_job = JOB_TYPE_DICT['file_upload']
    validation_job = JOB_TYPE_DICT['csv_record_validation']
    finished_status = JOB_STATUS_DICT['finished']

    # Completed, warnings, errors
    job_1_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['appropriations'], job_status_id=finished_status,
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    job_1_val = JobFactory(submission_id=sub.submission_id, job_type_id=validation_job,
                           file_type_id=FILE_TYPE_DICT['appropriations'], job_status_id=finished_status,
                           number_of_errors=10, number_of_warnings=4, error_message=None)
    # Invalid upload
    job_2_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['program_activity'], job_status_id=JOB_STATUS_DICT['invalid'],
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    job_2_val = JobFactory(submission_id=sub.submission_id, job_type_id=validation_job,
                           file_type_id=FILE_TYPE_DICT['program_activity'], job_status_id=JOB_STATUS_DICT['waiting'],
                           number_of_errors=0, number_of_warnings=0, error_message=None)
    # Validating
    job_3_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['award_financial'], job_status_id=finished_status,
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    job_3_val = JobFactory(submission_id=sub.submission_id, job_type_id=validation_job,
                           file_type_id=FILE_TYPE_DICT['award_financial'], job_status_id=JOB_STATUS_DICT['running'],
                           number_of_errors=0, number_of_warnings=0, error_message=None)
    # Uploading
    job_4_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['award'], job_status_id=JOB_STATUS_DICT['running'],
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    job_4_val = JobFactory(submission_id=sub.submission_id, job_type_id=validation_job,
                           file_type_id=FILE_TYPE_DICT['award'], job_status_id=JOB_STATUS_DICT['ready'],
                           number_of_errors=0, number_of_warnings=0, error_message=None)
    # Invalid on validation
    job_5_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['award_procurement'], job_status_id=finished_status,
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    job_5_val = JobFactory(submission_id=sub.submission_id, job_type_id=validation_job,
                           file_type_id=FILE_TYPE_DICT['award_procurement'], job_status_id=JOB_STATUS_DICT['invalid'],
                           number_of_errors=0, number_of_warnings=0, error_message=None)
    # Failed
    job_6_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['executive_compensation'],
                          job_status_id=JOB_STATUS_DICT['failed'], number_of_errors=0, number_of_warnings=0,
                          error_message='test message')
    # Ready
    job_7_up = JobFactory(submission_id=sub.submission_id, job_type_id=upload_job,
                          file_type_id=FILE_TYPE_DICT['sub_award'], job_status_id=JOB_STATUS_DICT['ready'],
                          number_of_errors=0, number_of_warnings=0, error_message=None)
    # Waiting
    job_8_val = JobFactory(submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['validation'], file_type_id=None,
                           job_status_id=JOB_STATUS_DICT['waiting'], number_of_errors=0, number_of_warnings=5,
                           error_message=None)

    sess.add_all([sub, job_1_up, job_1_val, job_2_up, job_2_val, job_3_up, job_3_val, job_4_up, job_4_val, job_5_up,
                  job_5_val, job_6_up, job_7_up, job_8_val])
    sess.commit()

    # Get all statuses
    json_response = fileHandler.get_status(sub)
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert len(json_content) == 8
    assert json_content['appropriations'] == {'status': 'finished', 'has_errors': True, 'has_warnings': True,
                                              'message': ''}
    assert json_content['program_activity'] == {'status': 'failed', 'has_errors': True, 'has_warnings': False,
                                                'message': ''}
    assert json_content['award_financial'] == {'status': 'running', 'has_errors': False, 'has_warnings': False,
                                               'message': ''}
    assert json_content['award'] == {'status': 'uploading', 'has_errors': False, 'has_warnings': False, 'message': ''}
    assert json_content['award_procurement'] == {'status': 'finished', 'has_errors': True, 'has_warnings': False,
                                                 'message': ''}
    assert json_content['executive_compensation'] == {'status': 'failed', 'has_errors': True, 'has_warnings': False,
                                                      'message': 'test message'}
    assert json_content['sub_award'] == {'status': 'ready', 'has_errors': False, 'has_warnings': False, 'message': ''}
    assert json_content['cross'] == {'status': 'ready', 'has_errors': False, 'has_warnings': False, 'message': ''}

    # Get just one status (ignore case)
    json_response = fileHandler.get_status(sub, 'awArd')
    assert json_response.status_code == 200
    json_content = json.loads(json_response.get_data().decode('UTF-8'))
    assert len(json_content) == 1
    assert json_content['award'] == {'status': 'uploading', 'has_errors': False, 'has_warnings': False, 'message': ''}
 def check_status(submission, **kwargs):
     type = kwargs.get('type')
     return get_status(submission, type)