def test_list_submission_users_cgac_affil(database): """ Test listing users based on cgac affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User') database.session.add_all(cgacs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=first_user.user_id, d2_submission=False) sub_2 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=other_user.user_id, d2_submission=False) database.session.add_all([sub_1, sub_2]) database.session.commit() g.user = first_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List both users because each has a submission with the cgac assert len(user_response) == 2 assert {user_response[0]['user_id'], user_response[1]['user_id']} == {first_user.user_id, other_user.user_id} assert {user_response[0]['name'], user_response[1]['name']} == {first_user.name, other_user.name} g.user = other_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List only the submissions this user is part of because they have no cgac/frec affiliations with either submission assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name
def test_list_submission_users_frec_affil(database): """ Test listing users based on frec affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] frecs = [FRECFactory(frec_code='0000', cgac=cgacs[0]), FRECFactory(frec_code='1111', cgac=cgacs[1])] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1', email='*****@*****.**') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User', email='*****@*****.**') third_user = UserFactory(name='Frec User', email='*****@*****.**') third_user.affiliations = [UserAffiliation(frec=frecs[0], user_id=third_user.user_id, permission_type_id=PERMISSION_TYPE_DICT['reader'])] database.session.add_all(cgacs + frecs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(frec_code=frecs[0].frec_code, user_id=first_user.user_id, is_fabs=False) sub_2 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, is_fabs=False) sub_3 = SubmissionFactory(frec_code=frecs[1].frec_code, user_id=other_user.user_id, is_fabs=False) database.session.add_all([sub_1, sub_2, sub_3]) database.session.commit() g.user = third_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List the first user because they have a submission with that frec assert len(user_response) == 1 assert user_response[0]['user_id'] == first_user.user_id assert user_response[0]['name'] == first_user.name assert user_response[0]['email'] == first_user.email
def test_list_submission_users_cgac_affil(database): """ Test listing users based on cgac affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1', email='*****@*****.**') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User', email='*****@*****.**') database.session.add_all(cgacs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=first_user.user_id, is_fabs=False) sub_2 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=other_user.user_id, is_fabs=False) database.session.add_all([sub_1, sub_2]) database.session.commit() g.user = first_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List both users because each has a submission with the cgac assert len(user_response) == 2 assert {user_response[0]['user_id'], user_response[1]['user_id']} == {first_user.user_id, other_user.user_id} assert {user_response[0]['name'], user_response[1]['name']} == {first_user.name, other_user.name} assert {user_response[0]['email'], user_response[1]['email']} == {first_user.email, other_user.email} g.user = other_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List only the submissions this user is part of because they have no cgac/frec affiliations with either submission assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name assert user_response[0]['email'] == other_user.email
def test_list_submission_users_owned(database): """ Test listing users based on owned submissions """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1') other_user = UserFactory.with_cgacs(cgacs[0], name='Test User') database.session.add_all(cgacs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, d2_submission=False) database.session.add(sub_1) database.session.commit() g.user = first_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # Don't list any submissions because they don't own any and have no cgac/frec affiliations assert len(user_response) == 0 g.user = other_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List the user because they have a submission they own (even though it doesn't match the cgac) assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name
def test_list_submission_users_cgac_frec_affil(database): """ Test listing users based on both cgac and frec affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] frecs = [FRECFactory(frec_code='0000', cgac=cgacs[0]), FRECFactory(frec_code='1111', cgac=cgacs[1])] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1', email='*****@*****.**') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User', email='*****@*****.**') third_user = UserFactory.with_cgacs(cgacs[1], name='Frec User', email='*****@*****.**') third_user.affiliations =\ third_user.affiliations + [UserAffiliation(frec=frecs[0], user_id=third_user.user_id, permission_type_id=PERMISSION_TYPE_DICT['reader'])] database.session.add_all(cgacs + frecs + [first_user, other_user]) database.session.commit() # Third user now has cgac 111 and frec 0000 sub_1 = SubmissionFactory(frec_code=frecs[0].frec_code, user_id=first_user.user_id, is_fabs=False) sub_2 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, is_fabs=False) sub_3 = SubmissionFactory(frec_code=frecs[1].frec_code, user_id=other_user.user_id, is_fabs=False) database.session.add_all([sub_1, sub_2, sub_3]) database.session.commit() g.user = third_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List both other users because one has a frec agency and one has a cgac assert len(user_response) == 2 assert {user_response[0]['user_id'], user_response[1]['user_id']} == {first_user.user_id, other_user.user_id} assert {user_response[0]['name'], user_response[1]['name']} == {first_user.name, other_user.name} assert {user_response[0]['email'], user_response[1]['email']} == {first_user.email, other_user.email}
def test_list_submission_users_fabs_dabs(database): """ Test listing DABS vs FABS users """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User') database.session.add_all(cgacs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=first_user.user_id, d2_submission=False) sub_2 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=other_user.user_id, d2_submission=True) database.session.add_all([sub_1, sub_2]) database.session.commit() g.user = first_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List only the first user because they're the only ones with a DABS submission assert len(user_response) == 1 assert user_response[0]['user_id'] == first_user.user_id assert user_response[0]['name'] == first_user.name response = list_submission_users(True) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List only the other user because they're the only ones with a FABS submission assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name
def test_list_submission_users_cgac_frec_affil(database): """ Test listing users based on both cgac and frec affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] frecs = [FRECFactory(frec_code='0000', cgac=cgacs[0]), FRECFactory(frec_code='1111', cgac=cgacs[1])] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User') third_user = UserFactory.with_cgacs(cgacs[1], name='Frec User') third_user.affiliations =\ third_user.affiliations + [UserAffiliation(frec=frecs[0], user_id=third_user.user_id, permission_type_id=PERMISSION_TYPE_DICT['reader'])] database.session.add_all(cgacs + frecs + [first_user, other_user]) database.session.commit() # Third user now has cgac 111 and frec 0000 sub_1 = SubmissionFactory(frec_code=frecs[0].frec_code, user_id=first_user.user_id, d2_submission=False) sub_2 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, d2_submission=False) sub_3 = SubmissionFactory(frec_code=frecs[1].frec_code, user_id=other_user.user_id, d2_submission=False) database.session.add_all([sub_1, sub_2, sub_3]) database.session.commit() g.user = third_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List both other users because one has a frec agency and one has a cgac assert len(user_response) == 2 assert {user_response[0]['user_id'], user_response[1]['user_id']} == {first_user.user_id, other_user.user_id} assert {user_response[0]['name'], user_response[1]['name']} == {first_user.name, other_user.name}
def test_list_submission_users_frec_affil(database): """ Test listing users based on frec affiliations """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] frecs = [FRECFactory(frec_code='0000', cgac=cgacs[0]), FRECFactory(frec_code='1111', cgac=cgacs[1])] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1') other_user = UserFactory.with_cgacs(cgacs[1], name='Test User') third_user = UserFactory(name='Frec User') third_user.affiliations = [UserAffiliation(frec=frecs[0], user_id=third_user.user_id, permission_type_id=PERMISSION_TYPE_DICT['reader'])] database.session.add_all(cgacs + frecs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(frec_code=frecs[0].frec_code, user_id=first_user.user_id, d2_submission=False) sub_2 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, d2_submission=False) sub_3 = SubmissionFactory(frec_code=frecs[1].frec_code, user_id=other_user.user_id, d2_submission=False) database.session.add_all([sub_1, sub_2, sub_3]) database.session.commit() g.user = third_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List the first user because they have a submission with that frec assert len(user_response) == 1 assert user_response[0]['user_id'] == first_user.user_id assert user_response[0]['name'] == first_user.name
def test_list_submission_users_owned(database): """ Test listing users based on owned submissions """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] first_user = UserFactory.with_cgacs(cgacs[0], name='Test User 1', email='*****@*****.**') other_user = UserFactory.with_cgacs(cgacs[0], name='Test User', email='*****@*****.**') database.session.add_all(cgacs + [first_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[1].cgac_code, user_id=other_user.user_id, d2_submission=False) database.session.add(sub_1) database.session.commit() g.user = first_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # Don't list any submissions because they don't own any and have no cgac/frec affiliations assert len(user_response) == 0 g.user = other_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # List the user because they have a submission they own (even though it doesn't match the cgac) assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name assert user_response[0]['email'] == other_user.email
def test_list_submission_users_admin(database): """ Test listing all users with a submission (admin called the function) """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] admin_user = UserFactory(website_admin=True, name='Admin User', email='*****@*****.**') other_user = UserFactory.with_cgacs(cgacs[0], name='Test User', email='*****@*****.**') database.session.add_all(cgacs + [admin_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=other_user.user_id, d2_submission=False) database.session.add(sub_1) database.session.commit() g.user = admin_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # Only lists users with submissions and doesn't care about affiliations because admin assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name assert user_response[0]['email'] == other_user.email
def test_list_submissions_permissions(database, monkeypatch): """Verify that the user must be in the same CGAC group, the submission's owner, or website admin to see the submission""" cgac1, cgac2 = CGACFactory(), CGACFactory() user1, user2 = UserFactory.with_cgacs(cgac1), UserFactory() database.session.add_all([cgac1, cgac2, user1, user2]) database.session.commit() sub = SubmissionFactory(user_id=user2.user_id, cgac_code=cgac2.cgac_code, publish_status_id=1) database.session.add(sub) database.session.commit() monkeypatch.setattr(fileHandler, 'g', Mock(user=user1)) assert list_submissions_result()['total'] == 0 user1.affiliations[0].cgac = cgac2 database.session.commit() assert list_submissions_result()['total'] == 1 user1.affiliations = [] database.session.commit() assert list_submissions_result()['total'] == 0 sub.user_id = user1.user_id database.session.commit() assert list_submissions_result()['total'] == 1 sub.user_id = user2.user_id database.session.commit() assert list_submissions_result()['total'] == 0 user1.website_admin = True database.session.commit() assert list_submissions_result()['total'] == 1
def test_list_submissions(file_app, database, user_constants, job_constants): """Test listing user's submissions. The expected values here correspond to the number of submissions within the agency of the user that is logged in """ cgacs = [CGACFactory() for _ in range(5)] user1 = UserFactory.with_cgacs(cgacs[0], cgacs[1]) user2 = UserFactory.with_cgacs(cgacs[2]) user3 = UserFactory.with_cgacs(*cgacs) database.session.add_all(cgacs + [user1, user2, user3]) database.session.commit() submissions = [ # one submission per CGAC SubmissionFactory(cgac_code=cgac.cgac_code, publish_status_id=PUBLISH_STATUS_DICT['unpublished']) for cgac in cgacs ] database.session.add_all(submissions) g.user = user1 response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {sub.submission_id for sub in submissions[:2]} response = file_app.get("/v1/list_submissions/?certified=false") assert sub_ids(response) == {sub.submission_id for sub in submissions[:2]} response = file_app.get("/v1/list_submissions/?certified=true") assert sub_ids(response) == set() submissions[0].publish_status_id = PUBLISH_STATUS_DICT['published'] database.session.commit() response = file_app.get("/v1/list_submissions/?certified=true") assert sub_ids(response) == {submissions[0].submission_id} g.user = user2 response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {submissions[2].submission_id} g.user = user3 submissions[3].d2_submission = True submissions[4].d2_submission = True database.session.commit() response = file_app.get( "/v1/list_submissions/?certified=mixed&d2_submission=true") assert sub_ids(response) == {sub.submission_id for sub in submissions[3:]} response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {sub.submission_id for sub in submissions[:3]}
def test_list_submissions(file_app, database, user_constants, job_constants): """Test listing user's submissions. The expected values here correspond to the number of submissions within the agency of the user that is logged in """ cgacs = [CGACFactory() for _ in range(5)] user1 = UserFactory.with_cgacs(cgacs[0], cgacs[1]) user2 = UserFactory.with_cgacs(cgacs[2]) user3 = UserFactory.with_cgacs(*cgacs) database.session.add_all(cgacs + [user1, user2, user3]) database.session.commit() submissions = [ # one submission per CGAC SubmissionFactory(cgac_code=cgac.cgac_code, publish_status_id=PUBLISH_STATUS_DICT['unpublished']) for cgac in cgacs ] database.session.add_all(submissions) g.user = user1 response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {sub.submission_id for sub in submissions[:2]} response = file_app.get("/v1/list_submissions/?certified=false") assert sub_ids(response) == {sub.submission_id for sub in submissions[:2]} response = file_app.get("/v1/list_submissions/?certified=true") assert sub_ids(response) == set() submissions[0].publish_status_id = PUBLISH_STATUS_DICT['published'] database.session.commit() response = file_app.get("/v1/list_submissions/?certified=true") assert sub_ids(response) == {submissions[0].submission_id} g.user = user2 response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {submissions[2].submission_id} g.user = user3 submissions[3].d2_submission = True submissions[4].d2_submission = True database.session.commit() response = file_app.get("/v1/list_submissions/?certified=mixed&d2_submission=true") assert sub_ids(response) == {sub.submission_id for sub in submissions[3:]} response = file_app.get("/v1/list_submissions/?certified=mixed") assert sub_ids(response) == {sub.submission_id for sub in submissions[:3]}
def test_list_user_emails(database, user_constants, user_app): cgacs = [CGACFactory() for _ in range(3)] users = [UserFactory.with_cgacs(cgacs[0]), UserFactory.with_cgacs(cgacs[0], cgacs[1]), UserFactory.with_cgacs(cgacs[1]), UserFactory.with_cgacs(cgacs[2])] database.session.add_all(users) database.session.commit() def user_ids(): result = user_app.get('/v1/list_user_emails/').data.decode('UTF-8') return {user['id'] for user in json.loads(result)['users']} g.user = users[0] assert user_ids() == {users[0].user_id, users[1].user_id} g.user = users[3] assert user_ids() == {users[3].user_id} g.user.website_admin = True database.session.commit() assert user_ids() == {user.user_id for user in users}
def test_list_user_emails(database, user_app): """ Test listing user emails """ cgacs = [CGACFactory() for _ in range(3)] users = [UserFactory.with_cgacs(cgacs[0]), UserFactory.with_cgacs(cgacs[0], cgacs[1]), UserFactory.with_cgacs(cgacs[1]), UserFactory.with_cgacs(cgacs[2])] database.session.add_all(users) database.session.commit() def user_ids(): result = user_app.get('/v1/list_user_emails/').data.decode('UTF-8') return {user['id'] for user in json.loads(result)['users']} g.user = users[0] assert user_ids() == {users[0].user_id, users[1].user_id} g.user = users[3] assert user_ids() == {users[3].user_id} g.user.website_admin = True database.session.commit() assert user_ids() == {user.user_id for user in users}
def test_list_submission_users_admin(database): """ Test listing all users with a submission (admin called the function) """ cgacs = [CGACFactory(cgac_code='000'), CGACFactory(cgac_code='111')] admin_user = UserFactory(website_admin=True, name='Admin User') other_user = UserFactory.with_cgacs(cgacs[0], name='Test User') database.session.add_all(cgacs + [admin_user, other_user]) database.session.commit() sub_1 = SubmissionFactory(cgac_code=cgacs[0].cgac_code, user_id=other_user.user_id, d2_submission=False) database.session.add(sub_1) database.session.commit() g.user = admin_user response = list_submission_users(False) user_response = json.loads(response.data.decode('UTF-8'))['users'] # Only lists users with submissions and doesn't care about affiliations because admin assert len(user_response) == 1 assert user_response[0]['user_id'] == other_user.user_id assert user_response[0]['name'] == other_user.name
def test_current_page(file_app, database, user_constants, job_constants, monkeypatch): """Test the route to check what the current progress of the submission is at the correct page """ cgac = CGACFactory() user = UserFactory.with_cgacs(cgac) user.user_id = 1 user.name = 'Oliver Queen' user.website_admin = True database.session.add(user) database.session.commit() g.user = user sub = SubmissionFactory(user_id=1, cgac_code=cgac.cgac_code) database.session.add(sub) csv_validation = database.session.query(JobType).filter_by( name='csv_record_validation').one() upload = database.session.query(JobType).filter_by( name='file_upload').one() validation = database.session.query(JobType).filter_by( name='validation').one() finished_job = database.session.query(JobStatus).filter_by( name='finished').one() waiting = database.session.query(JobStatus).filter_by(name='waiting').one() job_a = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='appropriations').one(), job_type=csv_validation, number_of_errors=0, file_size=123, job_status=finished_job) job_b = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='program_activity').one(), job_type=csv_validation, number_of_errors=0, file_size=123, job_status=finished_job) job_c = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='award_financial').one(), job_type=csv_validation, number_of_errors=0, file_size=123, job_status=finished_job) job_d1 = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='award_procurement').one(), job_type=csv_validation, number_of_errors=0, file_size=123, job_status=finished_job) job_d2 = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='award').one(), job_type=csv_validation, number_of_errors=0, file_size=123, job_status=finished_job) job_e = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='executive_compensation').one(), job_type=upload, number_of_errors=0, file_size=123, job_status=finished_job) job_f = JobFactory(submission_id=sub.submission_id, file_type=database.session.query(FileType).filter_by( name='sub_award').one(), job_type=upload, number_of_errors=0, file_size=123, job_status=finished_job) job_cross_file = JobFactory(submission_id=sub.submission_id, file_type=None, job_type=validation, number_of_errors=0, file_size=123, job_status=finished_job) database.session.add_all( [job_a, job_b, job_c, job_d1, job_d2, job_e, job_f, job_cross_file]) database.session.commit() # Everything ok response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '5' job_e.job_status_id = 6 database.session.commit() # E or F failed response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '4' job_e.job_status_id = 4 job_cross_file.number_of_errors = 6 database.session.commit() # Restore job_e and create errors for cross_file response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '3' job_d1.number_of_errors = 6 database.session.commit() # D file has errors response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '2' job_c.number_of_errors = 6 database.session.commit() # Fail C file validation response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '1' job_cross_file.job_status = waiting job_d1.number_of_errors = 0 database.session.commit() # E and F generated with C file errors response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '1'
def test_current_page(file_app, database): """Test the route to check what the current progress of the submission is at the correct page """ cgac = CGACFactory() user = UserFactory.with_cgacs(cgac) user.user_id = 1 user.name = 'Oliver Queen' user.website_admin = True database.session.add(user) database.session.commit() g.user = user sub = SubmissionFactory(user_id=1, cgac_code=cgac.cgac_code) database.session.add(sub) database.session.commit() csv_validation = JOB_TYPE_DICT['csv_record_validation'] upload = JOB_TYPE_DICT['file_upload'] validation = JOB_TYPE_DICT['validation'] finished_job = JOB_STATUS_DICT['finished'] waiting = JOB_STATUS_DICT['waiting'] job_a = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['appropriations'], job_type_id=csv_validation, number_of_errors=0, file_size=123, job_status_id=finished_job) job_b = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['program_activity'], job_type_id=csv_validation, number_of_errors=0, file_size=123, job_status_id=finished_job) job_c = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['award_financial'], job_type_id=csv_validation, number_of_errors=0, file_size=123, job_status_id=finished_job) job_d1 = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['award_procurement'], job_type_id=csv_validation, number_of_errors=0, file_size=123, job_status_id=finished_job) job_d2 = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['award'], job_type_id=csv_validation, number_of_errors=0, file_size=123, job_status_id=finished_job) job_e = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['executive_compensation'], job_type_id=upload, number_of_errors=0, file_size=123, job_status_id=finished_job) job_f = JobFactory(submission_id=sub.submission_id, file_type_id=FILE_TYPE_DICT['sub_award'], job_type_id=upload, number_of_errors=0, file_size=123, job_status_id=finished_job) job_cross_file = JobFactory(submission_id=sub.submission_id, file_type_id=None, job_type_id=validation, number_of_errors=0, file_size=123, job_status_id=finished_job) database.session.add_all([job_a, job_b, job_c, job_d1, job_d2, job_e, job_f, job_cross_file]) database.session.commit() # Everything ok response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '5' job_e.job_status_id = 6 database.session.commit() # E or F failed response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '4' job_e.job_status_id = 4 job_cross_file.number_of_errors = 6 database.session.commit() # Restore job_e and create errors for cross_file response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '3' job_d1.number_of_errors = 6 database.session.commit() # D file has errors response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '2' job_c.number_of_errors = 6 database.session.commit() # Fail C file validation response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '1' job_cross_file.job_status_id = waiting job_d1.number_of_errors = 0 database.session.commit() # E and F generated with C file errors response = file_app.get("/v1/check_current_page/?submission_id=" + str(sub.submission_id)) response_json = json.loads(response.data.decode('UTF-8')) assert response_json['step'] == '1'