def setUp(self): self.sm = sqm.SQLiteMgr("../fixtures/fruit.db") self.sm.new_table("nuts").add_table_column("Nmbr", "INT", "PRIMARY KEY").add_table_column("Called", "TEXT", "UNIQUE").add_table_column("Description", "TEXT").create_table() self.cursor = self.sm.get_cursor() self.cursor.execute("SELECT * FROM nuts") self.col_names = [description[0] for description in self.cursor.description] # gets the column names from nuts table because self.sm.get_cursor().execute() is selecting from nuts table self.comp_names = ['Nmbr', 'Called', 'Description']
def setUp(self): self.sm = sqm.SQLiteMgr("../fixtures/fruit.db") self.sm.set_table_statement("CREATE TABLE IF NOT EXISTS nuts(Nmbr INT PRIMARY KEY, Called TEXT UNIQUE, Description TEXT)").create_table() self.table_exists = self.check_sqlite_master() # should return True self.sm.table = "nuts" self.sm.delete_table() self.table_exists_after_delete = self.check_sqlite_master() # should return False
def setUp(self): table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) re = rdbrecord.ReadEntry(sg.make_conn(), table, db) self.first_head_comp = [(1, '2017-02-11'), (2, '2017-02-27'), (3, '2017-03-09'), (4, '2017-03-12'), (5, '2017-03-04'), \ (6, '2017-03-15'), (7, '2017-04-04'), (8, '2017-04-12')] self.second_head_comp = [(1, '2017-02-11'), (2, '2017-02-27'), (4, '2017-03-12'), (5, '2017-03-04'), (7, '2017-04-04')] re.head(8) self.first_head = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.first_head_result = re.result del re.entry_list[2] del re.entry_list[4] re.head() # just use the default value for the argument to this method self.second_head = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.second_head_result = re.result
def setUp(self): numbers_list = list() table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) conn = sg.make_conn() self.sm = sqliteminor.SQLiteMinor(conn, table) test_entry = entry.Entry(16, "<h2 class='title'>A test Title</h2><p>This is a test entry. No Godlore to speak of.</p>",\ "test godlore", datetime.date(2017, 6, 25) , table, db) self.number_added_comp = 1 self.entry_numbers_comp = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ] self.added_entry_matter_comp = [( 16, "<h2 class='title'>A test Title</h2><p>This is a test entry. No Godlore to speak of.</p>", '2017-06-25', 'test godlore')] self.ce = rdbrecord.CreateEntry(conn, table, db) self.number_added = self.ce.create(test_entry.entry_number, test_entry.entry_text, test_entry.entry_keywords, test_entry.entry_date) self.create_result = self.ce.result self.entry_numbers = [i[0] for i in self.sm.read_all("entry_number")] self.added_entry_matter = self.sm.read_search_rows("entry_number", 16) self.sm.delete("entry_number", 16)
def setUp(self): self.sm = sqm.SQLiteMgr() self.sm.new_table("nuts") self.final_statement = 'CREATE TABLE IF NOT EXISTS nuts(Nmbr INT PRIMARY KEY, Called TEXT UNIQUE, Description TEXT, ' self.sm.add_table_column("Nmbr", "INT", "PRIMARY KEY").add_table_column( "Called", "TEXT", "UNIQUE").add_table_column( "Description", "TEXT")
def setUp(self): self.path_to_db = "../fixtures/fruit.db" self.path_to_none = "../fixtures/flowers.db" self.db_not_present = False self.db_created = False if os.path.isfile(self.path_to_db): try: os.remove(self.path_to_db) self.db_not_present = True except: pass self.sm = sqm.SQLiteMgr(self.path_to_none) self.sm.create_db(self.path_to_db) self.db_created = os.path.isfile(self.path_to_db)
def setUp(self): table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) conn = sg.make_conn() self.entry_numbers_comp = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ] self.re = rdbrecord.ReadEntry(conn, table, db) self.re.all() self.entries = self.re.entry_list self.all_result = self.re.result
def setUp(self): self.path_to_db = "../fixtures/fruit.db" self.path_to_none = "../fixtures/flowers.db" self.db_is_present = False self.db_deleted = False if not os.path.isfile(self.path_to_db): try: open(self.path_to_db, "w").close() self.db_is_present = True except: pass else: self.db_is_present = True self.sm = sqm.SQLiteMgr(self.path_to_none) self.sm.delete_db(self.path_to_db) self.db_deleted = not os.path.isfile( self.path_to_db ) # evaluates to False if os.path.isfile returns True (and vice versa),
def setUp(self): self.db_name = "../fixtures/fruit.db" open(self.db_name, "w").close() # remove everything from the fruit.db file self.comp_assert = 4 self.sm = sqm.SQLiteMgr(self.db_name) self.sm.new_table("fruit").set_table_statement( 'CREATE TABLE IF NOT EXISTS fruit (Id INT, Name TEXT, Qualities TEXT)' ).create_table() self.sm.new_table("nuts").set_table_statement( 'CREATE TABLE IF NOT EXISTS nuts(Id INT PRIMARY KEY, Name TEXT UNIQUE, Qualities TEXT)' ).create_table() self.sm.new_table("flowers").set_table_statement( 'CREATE TABLE IF NOT EXISTS flowers(Id INT PRIMARY KEY, Name TEXT UNIQUE, Qualities TEXT)' ).create_table() self.sm.new_table("seeds").set_table_statement( 'CREATE TABLE IF NOT EXISTS seeds(Id INT PRIMARY KEY, Name TEXT UNIQUE, Qualities TEXT)' ).create_table() self.tables_count = self.sm.get_number_tables_db()
def setUp(self): self.table_name = "fruit" self.db_name = "../fixtures/fruit.db" open(self.db_name, "w").close() # remove everything from the fruit.db file self.sm = sqm.SQLiteMgr(self.db_name) self.sm.new_table(self.table_name).set_table_statement( 'CREATE TABLE IF NOT EXISTS fruit(Id INT PRIMARY KEY, Name TEXT UNIQUE, Qualities TEXT)' ).create_table() self.cursor = self.sm.get_cursor() self.cursor.execute( "INSERT INTO fruit VALUES(1,'cherry','tart, sweet, red, harvest from branch')" ) self.cursor.execute( "INSERT INTO fruit VALUES(2,'strawberry','sweet, red, harvest from plant')" ) self.cursor.execute( "INSERT INTO fruit VALUES(3,'orange','sweet, orange, harvest from branch')" ) self.cursor.execute( "INSERT INTO fruit VALUES(4,'grape','sweet, red, harvest from vine')" ) self.table_count = self.sm.get_number_rows_in_table(self.table_name)
def setUp(self): table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) re = rdbrecord.ReadEntry(sg.make_conn(), table, db) self.first_tail_comp = [(8, '2017-04-12'), (9, '2017-04-20'), (10, '2017-04-22'), (11, '2017-04-30'), \ (12, '2017-05-04'), (13, '2017-05-12'), (14, '2017-06-15'), (15, '2017-06-22')] self.second_tail_comp = [(9, '2017-04-20'), (11, '2017-04-30'), (12, '2017-05-04'), (14, '2017-06-15'), (15, '2017-06-22')] re.tail(8) self.first_tail = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.first_tail_result = re.result del re.entry_list[2] del re.entry_list[4] re.tail() # just use the default value for the argument to this method self.second_tail = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.second_tail_result = re.result
def setUp(self): self.comp_statement = 'CREATE TABLE IF NOT EXISTS nuts(' self.sm = sqm.SQLiteMgr() self.sm.new_table("nuts")
to_output_html get_file_names delete msd.delete_all_from_db(sm) msd.populate_test_journal(sm) """ table = "entries" db = "test_journal" input_html_path = "../io_files/input.html" output_html_path = "../io_files/output.html" html_template_path = "../waxtablet/html-templates/default.html" path_to_db = "../temp/test_journal" entry_list = list() fio = wtfileio.WTFileIO(table, db, input_html_path, output_html_path, html_template_path) sg = sqlitemgr.SQLiteMgr(path_to_db) sm = sqliteminor.SQLiteMinor(sg.make_conn(), table) fio.entry_list = msd.populate_entry_object_list(sm) #fio.to_input_file(True) #fio.from_input_file() #fio.to_output_html() fio.delete("../target/rdbrecord.pyc") found = False for f in fio.get_file_names("../target/"): print "\t", f if f == "rdbrecord.pyc": found = True
def setUp(self): self.smgr = sqm.SQLiteMgr("test.db")
def setUp(self): table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) sg2 = sqlitemgr.SQLiteMgr(db) conn = sg.make_conn() conn2 = sg2.make_conn() sm = sqliteminor.SQLiteMinor(conn2, table) re = rdbrecord.ReadEntry(conn, table, db) self.text_keywords_liberal_comp = [(1, '2017-02-11'), (2, '2017-02-27'), (3, '2017-03-09'), (5, '2017-03-15'), (6, '2017-03-15'), \ (9, '2017-04-20'), (11, '2017-04-30'), (12, '2017-05-04'), (14, '2017-06-15'), (15, '2017-06-22')] self.text_keywords_strict_comp = [(12, '2017-05-04')] self.date_member_comp = [(3, '2017-03-09'), (4, '2017-03-12'), (5, '2017-03-15'), (6, '2017-03-15')] self.date_search_comp = [(5, '2017-03-15'), (6, '2017-03-15')] """ Database searches """ re.entry_list = [ ] # clear out the entry_list to force ReadEntry to read from the database re.search(["entry_text", "entry_keywords"], ["%Odhinn%", "%Aesir%"]) self.text_keywords_liberal_db_result = re.result self.text_keywords_liberal_db = get_results(re.entry_list) re.entry_list = [] re.search(["entry_text", "entry_keywords"], ["%Odhinn%", "%Aesir%"], None, "has-all") self.text_keywords_strict_db_result = re.result self.text_keywords_strict_db = get_results(re.entry_list) re.entry_list = [] re.search("entry_date", "03", "month") self.date_member_db_result = re.result self.date_member_db = get_results(re.entry_list) re.entry_list = [] re.search(["entry_date"], ["2017-03-15"]) self.date_search_db_result = re.result self.date_search_db = get_results(re.entry_list) """ entry_list searches """ re.entry_list = setup_db_objects.populate_entry_object_list( sm) #re-populate the entry_list of the ReadEntry object with all #the entries from the database re.search(["entry_text", "entry_keywords"], ["Odhinn", "Aesir"]) self.text_keywords_liberal_el_result = re.result self.text_keywords_liberal_el = get_results(re.entry_list) re.entry_list = setup_db_objects.populate_entry_object_list(sm) re.search(["entry_text", "entry_keywords"], ["Odhinn", "Aesir"], None, "has-all") self.text_keywords_strict_el_result = re.result self.text_keywords_strict_el = get_results(re.entry_list) re.entry_list = setup_db_objects.populate_entry_object_list(sm) re.search("entry_date", "03", "month") self.date_member_el_result = re.result self.date_member_el = get_results(re.entry_list) re.entry_list = setup_db_objects.populate_entry_object_list(sm) re.search(["entry_date"], ["2017-03-15"]) self.date_search_el_result = re.result self.date_search_el = get_results(re.entry_list)
for row in sm.read_all(): content = str(nmbr) + " " + str(row[0]) + "\t" + str(row[1]) t.display(content, 2, 0, 1) row_list.append([nmbr, row[0], row[1]]) nmbr = nmbr + 1 t.display(" ", 0, 0, 1) return row_list if __name__ == "__main__": path_to_db = ".waxtablet/wtab_usr_data/wtab_app" # modify this path as needed sg_read = sqlitemgr.SQLiteMgr(path_to_db) sm_read = sqliteminor.SQLiteMinor(sg_read.make_conn(), "settings") trm = wtterm.WTTermIO() try: while (1): try: if os.name == "nt": os.system('cls') else: os.system('clear') except Exception as e: pass rows = show_db_vals(sm_read, trm)
def setUp(self): table = "entries" db = "../fixtures/test_journal" sg = sqlitemgr.SQLiteMgr(db) conn = sg.make_conn() re = rdbrecord.ReadEntry(conn, table, db) """ range of entries by number tests """ self.first_range_call_comp = [(2, '2017-02-27'), (3, '2017-03-09'), (4, '2017-03-12'), (5, '2017-03-04'), (6, '2017-03-15'), \ (7, '2017-04-04'), (8, '2017-04-12'), (9, '2017-04-20')] self.second_range_call_comp = [(2, '2017-02-27'), (3, '2017-03-09'), (4, '2017-03-12'), (6, '2017-03-15'), (7, '2017-04-04'), (9, '2017-04-20')] re.range( "entry_number", 2, 9 ) # get a range of entries from the database of entry_numbers 2 thru 9 self.first_range_call = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.first_range_call_result = re.result del re.entry_list[ 3] # delete a couple of entries from the ReadEntry object's entry_list del re.entry_list[5] re.range( "entry_number", 2, 9 ) # get a range of entries from ReadEntry object's entry_list of entry_numbers 2 thru 9 self.second_range_call = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.second_range_call_result = re.result """ range of entries by date tests """ re.entry_list = [ ] # start over by clearing out the ReadEntry object's entry_list self.first_range_call_date_comp = [(3, '2017-03-09'), (4, '2017-03-12'), (6, '2017-03-15'), (7, '2017-04-04'), (8, '2017-04-12'), \ (9, '2017-04-20'), (10, '2017-04-22'), (11, '2017-04-30'), (12, '2017-05-04')] self.second_range_call_date_comp = [(3, '2017-03-09'), (4, '2017-03-12'), (6, '2017-03-15'), (8, '2017-04-12'), (9, '2017-04-20'), \ (10, '2017-04-22'), (12, '2017-05-04')] re.range("entry_date", "2017-03-09", "2017-05-05") self.first_range_call_date = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.first_range_call_date_result = re.result del re.entry_list[3] del re.entry_list[6] re.range("entry_date", "2017-03-09", "2017-05-05") self.second_range_call_date = [(i.entry_number, str(i.entry_date)) for i in re.entry_list] self.second_range_call_date_result = re.result