def test_csv_new_assignment(csvfile): # Delete all current officers and assignments Assignment.query.delete() Officer.query.delete() assert Officer.query.count() == 0 df = pd.read_csv(csvfile) df.loc[0, "job_title"] = "Commander" df.to_csv(csvfile) n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created > 0 assert n_updated == 0 assert Officer.query.count() == n_created officer = get_officer(1, df.loc[0, "star_no"], df.loc[0, "first_name"], df.loc[0, "last_name"]) assert officer officer_id = officer.id assert len(list(officer.assignments)) == 1 # Update job_title df.loc[0, "job_title"] = "CAPTAIN" df.to_csv(csvfile) n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created == 0 assert n_updated == 1 officer = Officer.query.filter_by(id=officer_id).one() assert len(list(officer.assignments)) == 2 for assignment in officer.assignments: assert (assignment.job.job_title == "Commander" or assignment.job.job_title == "CAPTAIN")
def test_csv_new_assignment(csvfile): # Delete all current officers and assignments Assignment.query.delete() Officer.query.delete() assert Officer.query.count() == 0 df = pd.read_csv(csvfile) df.loc[0, 'rank'] = 'COMMANDER' df.to_csv(csvfile) n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created > 0 assert n_updated == 0 assert Officer.query.count() == n_created officer = get_officer(1, df.loc[0, 'star_no'], df.loc[0, 'first_name'], df.loc[0, 'last_name']) assert officer officer_id = officer.id assert len(list(officer.assignments)) == 1 # Update rank df.loc[0, 'rank'] = 'CAPTAIN' df.to_csv(csvfile) n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created == 0 assert n_updated > 0 assert Officer.query.count() == n_updated officer = Officer.query.filter_by(id=officer_id).one() assert len(list(officer.assignments)) == 2 for assignment in officer.assignments: assert assignment.rank == 'COMMANDER' or assignment.rank == 'CAPTAIN'
def test_csv_new_salary(csvfile): # Delete all current officers and salaries Salary.query.delete() Officer.query.delete() assert Officer.query.count() == 0 df = pd.read_csv(csvfile) df.loc[0, "salary"] = "123456.78" df.to_csv(csvfile) n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created > 0 assert n_updated == 0 officer_count = Officer.query.count() assert officer_count == n_created officer = get_officer(1, df.loc[0, "star_no"], df.loc[0, "first_name"], df.loc[0, "last_name"]) assert officer officer_id = officer.id assert len(list(officer.salaries)) == 1 # Update salary df.loc[0, "salary"] = "150000" df.to_csv(csvfile) assert Officer.query.count() > 0 n_created, n_updated = bulk_add_officers([csvfile], standalone_mode=False) assert n_created == 0 assert n_updated == 1 assert Officer.query.count() == officer_count officer = Officer.query.filter_by(id=officer_id).one() assert len(list(officer.salaries)) == 2 for salary in officer.salaries: assert float(salary.salary) == 123456.78 or float( salary.salary) == 150000.00