Ejemplo n.º 1
0
 def submission_data(submission, type):
     return get_submission_data(submission, type)
 def submission_data(submission, type):
     return get_submission_data(submission, type)
 def submission_data(submission, **kwargs):
     type = kwargs.get('type')
     return get_submission_data(submission, type)
def test_get_submission_data_dabs(database):
    """ Tests the get_submission_data function for dabs records """
    sess = database.session

    cgac = CGACFactory(cgac_code='001', agency_name='CGAC Agency')

    sub = SubmissionFactory(submission_id=1, d2_submission=False)
    sub_2 = SubmissionFactory(submission_id=2, d2_submission=False)

    # Job for submission
    job = JobFactory(job_id=1, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                     job_status_id=JOB_STATUS_DICT['finished'], file_type_id=FILE_TYPE_DICT['appropriations'],
                     number_of_rows=3, file_size=7655, original_filename='file_1')
    job_2 = JobFactory(job_id=2, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['file_upload'],
                       job_status_id=JOB_STATUS_DICT['finished'], file_type_id=FILE_TYPE_DICT['program_activity'],
                       number_of_rows=None, file_size=None, original_filename='file_2')
    job_3 = JobFactory(job_id=3, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                       job_status_id=JOB_STATUS_DICT['running'], file_type_id=FILE_TYPE_DICT['program_activity'],
                       number_of_rows=7, file_size=12345, original_filename='file_2')
    job_4 = JobFactory(job_id=4, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['validation'],
                       job_status_id=JOB_STATUS_DICT['waiting'], file_type_id=None, number_of_rows=None,
                       file_size=None, original_filename=None)
    job_5 = JobFactory(job_id=5, submission_id=sub_2.submission_id, job_type_id=JOB_TYPE_DICT['validation'],
                       job_status_id=JOB_STATUS_DICT['waiting'], file_type_id=None, number_of_rows=None,
                       file_size=None, original_filename=None)

    sess.add_all([cgac, sub, sub_2, job, job_2, job_3, job_4, job_5])
    sess.commit()

    # a basic csv_validation job, should be in results
    correct_job = {
        'job_id': job.job_id,
        'job_status': job.job_status_name,
        'job_type': job.job_type_name,
        'filename': job.original_filename,
        'file_size': job.file_size,
        'number_of_rows': job.number_of_rows,
        'file_type': job.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # cross-file job, should be in results
    correct_cross_job = {
        'job_id': job_4.job_id,
        'job_status': job_4.job_status_name,
        'job_type': job_4.job_type_name,
        'filename': None,
        'file_size': None,
        'number_of_rows': None,
        'file_type': '',
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # upload job, shouldn't be in the results
    upload_job = {
        'job_id': job_2.job_id,
        'job_status': job_2.job_status_name,
        'job_type': job_2.job_type_name,
        'filename': job_2.original_filename,
        'file_size': job_2.file_size,
        'number_of_rows': job_2.number_of_rows,
        'file_type': job_2.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # cross-file job but from another submission, shouldn't be in the results
    different_sub_job = {
        'job_id': job_5.job_id,
        'job_status': job_5.job_status_name,
        'job_type': job_5.job_type_name,
        'filename': job_5.original_filename,
        'file_size': job_5.file_size,
        'number_of_rows': job_5.number_of_rows,
        'file_type': job_5.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    response = get_submission_data(sub)
    response = json.loads(response.data.decode('UTF-8'))
    results = response['jobs']
    assert len(results) == 3
    assert correct_job in results
    assert correct_cross_job in results
    assert upload_job not in results
    assert different_sub_job not in results

    response = get_submission_data(sub, 'appropriations')
    response = json.loads(response.data.decode('UTF-8'))
    results = response['jobs']
    assert len(results) == 1
    assert results[0] == correct_job
def test_get_submission_data_dabs(database):
    """ Tests the get_submission_data function for dabs records """
    sess = database.session

    cgac = CGACFactory(cgac_code='001', agency_name='CGAC Agency')

    sub = SubmissionFactory(submission_id=1, d2_submission=False)
    sub_2 = SubmissionFactory(submission_id=2, d2_submission=False)

    # Job for submission
    job = JobFactory(job_id=1, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                     job_status_id=JOB_STATUS_DICT['finished'], file_type_id=FILE_TYPE_DICT['appropriations'],
                     number_of_rows=3, file_size=7655, original_filename='file_1')
    job_2 = JobFactory(job_id=2, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['file_upload'],
                       job_status_id=JOB_STATUS_DICT['finished'], file_type_id=FILE_TYPE_DICT['program_activity'],
                       number_of_rows=None, file_size=None, original_filename='file_2')
    job_3 = JobFactory(job_id=3, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['csv_record_validation'],
                       job_status_id=JOB_STATUS_DICT['running'], file_type_id=FILE_TYPE_DICT['program_activity'],
                       number_of_rows=7, file_size=12345, original_filename='file_2')
    job_4 = JobFactory(job_id=4, submission_id=sub.submission_id, job_type_id=JOB_TYPE_DICT['validation'],
                       job_status_id=JOB_STATUS_DICT['waiting'], file_type_id=None, number_of_rows=None,
                       file_size=None, original_filename=None)
    job_5 = JobFactory(job_id=5, submission_id=sub_2.submission_id, job_type_id=JOB_TYPE_DICT['validation'],
                       job_status_id=JOB_STATUS_DICT['waiting'], file_type_id=None, number_of_rows=None,
                       file_size=None, original_filename=None)

    sess.add_all([cgac, sub, sub_2, job, job_2, job_3, job_4, job_5])
    sess.commit()

    # a basic csv_validation job, should be in results
    correct_job = {
        'job_id': job.job_id,
        'job_status': job.job_status_name,
        'job_type': job.job_type_name,
        'filename': job.original_filename,
        'file_size': job.file_size,
        'number_of_rows': job.number_of_rows,
        'file_type': job.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # cross-file job, should be in results
    correct_cross_job = {
        'job_id': job_4.job_id,
        'job_status': job_4.job_status_name,
        'job_type': job_4.job_type_name,
        'filename': None,
        'file_size': None,
        'number_of_rows': None,
        'file_type': '',
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # upload job, shouldn't be in the results
    upload_job = {
        'job_id': job_2.job_id,
        'job_status': job_2.job_status_name,
        'job_type': job_2.job_type_name,
        'filename': job_2.original_filename,
        'file_size': job_2.file_size,
        'number_of_rows': job_2.number_of_rows,
        'file_type': job_2.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    # cross-file job but from another submission, shouldn't be in the results
    different_sub_job = {
        'job_id': job_5.job_id,
        'job_status': job_5.job_status_name,
        'job_type': job_5.job_type_name,
        'filename': job_5.original_filename,
        'file_size': job_5.file_size,
        'number_of_rows': job_5.number_of_rows,
        'file_type': job_5.file_type_name,
        'file_status': "",
        'error_type': "",
        'error_data': [],
        'warning_data': [],
        'missing_headers': [],
        'duplicated_headers': []
    }

    response = get_submission_data(sub)
    response = json.loads(response.data.decode('UTF-8'))
    results = response['jobs']
    assert len(results) == 3
    assert correct_job in results
    assert correct_cross_job in results
    assert upload_job not in results
    assert different_sub_job not in results

    response = get_submission_data(sub, 'appropriations')
    response = json.loads(response.data.decode('UTF-8'))
    results = response['jobs']
    assert len(results) == 1
    assert results[0] == correct_job