def test_manipulation(input_dict, sqlfilename, sqltable): print("Testing table creation from a nested dictionary...") dbhandler.create_table(input_dict, sqlfilename, sqltable) print("") print("Testing data insertion in database...") dbhandler.add_dbrows(MY_DICT, MY_SQLFILENAME, MY_SQLTABLE) print("") print("Testing simple key comparison between a dictionary and a database created from that same dictionary...") dbhandler.compare_keysonly(MY_DICT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing simple key comparison between a dictionary and a database created from another dictionary...") dbhandler.compare_keysonly(MY_DICTALT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing full key comparison between a dictionary and a database created from that same dictionary...") dbhandler.compare_keysfull(MY_DICT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing full key comparison between a dictionary and a database created from another dictionary...") dbhandler.compare_keysfull(MY_DICTALT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing row comparison between a dictionary and a database created from that same dictionary...") dbhandler.compare_rowsfull(MY_DICT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing row comparison between a dictionary and a database created from another dictionary...") dbhandler.compare_rowsfull(MY_DICTALT, MY_SQLFILENAME, MY_SQLTABLE) print("Testing updating database from changes in dictionary...") dbhandler.update_dict_to_db(MY_DICTALT, MY_SQLFILENAME, MY_SQLTABLE) return None
def record_results(message): if not check_entry(message.text): bot.send_message(message.chat.id, values.FORMAT_REPLY) return # no need to add the message to db as it is incorrect subject_list = parse_entry(message.text) subject, grade = subject_list # unpack the list to insert into function dbhandler.create_table(message) dbhandler.write_table(subject, grade, message)
def test_insert_era(self): soup = make_soup() eras = parse_era_info(soup) conn = create_connection("test.db") create_table(conn) #Test multiple entries. record_id = 1 for era in eras: era.append(record_id) insert_era(conn, era) record_id += 1 #Test a double input attempt. insert_era(conn, eras[0]) #Test a bad input insert_era(conn, [1, '2', '3'])
def populate_db(mode=""): """ Input: blank, if set by user. For testing, a dictionary may be used to simulate user input. Objective: call other functions to populate a database from a .xls or .xlsx file. Output: .sqlite database. """ results = {} fieldvalues = [] fieldnames = [] if mode == "": mode = choose_mode_populate() # Usual state of affairs # Open the datasheet with the information and retrieve lists print("\nIn which workbook is the relevant table stored?") wb_filename = input_filename() if wb_filename.endswith(".xlsx"): fieldnames = xlsxtolist.get_firstrow(wb_filename) fieldvalues = xlsxtolist.get_otherrows(wb_filename) elif wb_filename.endswith(".xls"): fieldnames = xlstolist.get_firstrow(wb_filename) fieldvalues = xlstolist.get_otherrows(wb_filename) # Convert lists into a nested dictionary results = listlist_to_dictdict(fieldvalues, fieldnames) # Prepare the output file timestamp = filegenerator.generate_timestamp() if mode["outputtype"][0] == "current.sqlite": filename = mode["outputtype"][1] pprint.pprint(results) dbhandler.update_dict_to_db(results, filename, "rawdata", "id", True) elif mode["outputtype"][0] == "fresh.sqlite": filename = mode["outputtype"][1] + ".sqlite" pprint.pprint(results) dbhandler.create_table(results, filename, "rawdata", True) dbhandler.add_dbrows(results, filename, "rawdata", "id", True) return results
def test_create_table(self): conn = create_connection("test.db") create_table(conn)