def test_delete_tracklets(tracklet_dict_list): '''Test deleting multiple tracklets.''' # set up db & table if os.path.isfile(sql.fetch_db_filepath()): os.remove(sql.fetch_db_filepath()) conn = sql.create_connection(sql.fetch_db_filepath()) cur = conn.cursor() sql.create_specific_table(conn) # upload data ... JD = [tracklet_dic['JD'] for tracklet_dic in tracklet_dict_list] HP = [tracklet_dic['HP'] for tracklet_dic in tracklet_dict_list] tracklet_name = [tracklet_dic['tracklet_name'] for tracklet_dic in tracklet_dict_list] sql.upsert_tracklets(conn, JD, HP, tracklet_name, tracklet_dict_list) # query the data & check that required # of dictionaries are returned list_of_tuples = sql.query_tracklets_jdhp(conn, JD[0], HP[0]) assert isinstance(list_of_tuples, list) and len(list_of_tuples) == 1 list_of_tuples = sql.query_tracklets_jdhp(conn, JD[1], HP[1]) assert isinstance(list_of_tuples, list) and len(list_of_tuples) == 1 # now delete two tracklets & check that two fewer dictionaries remain sql.delete_tracklets(conn, [tracklet_dict_list[0]['tracklet_name'], tracklet_dict_list[1]['tracklet_name']]) list_of_tuples = sql.query_tracklets_jdhp(conn, JD[0], HP[0]) assert isinstance(list_of_tuples, list) and len(list_of_tuples) == 0 list_of_tuples = sql.query_tracklets_jdhp(conn, JD[1], HP[1]) assert isinstance(list_of_tuples, list) and len(list_of_tuples) == 0 # Delete the db to facilitate future testing os.remove(sql.fetch_db_filepath())
def test_tracklets_upsert(tracklet_dict_list): """ Here we are updating/inserting **lists** of tracklet data """ # set up db & table if os.path.isfile(sql.fetch_db_filepath()): os.remove(sql.fetch_db_filepath()) conn = sql.create_connection(sql.fetch_db_filepath()) cur = conn.cursor() sql.create_specific_table(conn) # upload data ... JD = [tracklet_dic['JD'] for tracklet_dic in tracklet_dict_list] HP = [tracklet_dic['HP'] for tracklet_dic in tracklet_dict_list] tracklet_name = [tracklet_dic['tracklet_name'] for tracklet_dic in tracklet_dict_list] sql.upsert_tracklets(conn, JD, HP, tracklet_name, tracklet_dict_list) # test that the data was actually uploaded cur.execute('SELECT * from tracklets') f = cur.fetchall() assert(len(f) == len(tracklet_dict_list)), 'data not uploaded' for ii, fi in enumerate(f): assert fi[3] == tracklet_name[ii], 'data not uploaded' # Delete the db to facilitate future testing os.remove(sql.fetch_db_filepath())
def test_tracklet_query_mutiple_HP(tracklet_dict_list): '''Test querying multiple Heal Pix.''' # set up db & table if os.path.isfile(sql.fetch_db_filepath()): os.remove(sql.fetch_db_filepath()) conn = sql.create_connection(sql.fetch_db_filepath()) cur = conn.cursor() sql.create_specific_table(conn) # upload data ... JD = [tracklet_dic['JD'] for tracklet_dic in tracklet_dict_list] HP = [tracklet_dic['HP'] for tracklet_dic in tracklet_dict_list] tracklet_name = [tracklet_dic['tracklet_name'] for tracklet_dic in tracklet_dict_list] sql.upsert_tracklets(conn, JD, HP, tracklet_name, tracklet_dict_list) # query the data & check that requisite dictionaries are returned list_of_tuples = sql.query_tracklets_jd_hplist(conn, JD[0], HP) assert isinstance(list_of_tuples, list) and len(list_of_tuples) == 1 # Delete the db to facilitate future testing os.remove(sql.fetch_db_filepath())