def row_comparison(db1, db2, query, table_name): # created a separate function that compares rows to avoid repetition/reuse for 2 tables conn1, cur1 = main.create_connection(db1) conn2, cur2 = main.create_connection(db2) res1 = cur1.execute(query) res2 = cur2.execute(query) print("...Comparing Table: " + table_name) for row1 in res1: row2 = res2.fetchone() print(row1) print(row2) if row1 is not None and row2 is not None and (row1[0] == row2[0]): print("........Tables Match:" + str(row1[0])) assert True else: if row1 is not None and row1[0] is not None: print("!!!!!!!!PROBLEM " + db1 + " is missing Table:" + str(row1[0])) assert False else: print("!!!!!!!!PROBLEM " + db2 + " is missing Table:" + str(row2[0])) assert False print("...Completed table comparison for " + table_name + ": all tables match") main.close_db(conn1) main.close_db(conn2)
def test_num_states(): # test to see if we get entries from all 50 states at least (in my case i also got data from territories) conn, cursor = main.create_connection('test.sqlite') cursor.execute("SELECT COUNT(DISTINCT area_title) FROM jobs_data;") query = cursor.fetchone()[0] conn.close() assert query >= 50
def exec_sql(filename, table_name): # this function will return the number of entries from a table conn, cursor = main.create_connection(filename) cursor.execute("SELECT COUNT(*) FROM " + table_name) query = cursor.fetchone()[0] main.close_db(conn) return query
def test_states(): # same as function above but getting entry count from state_lookup table conn, cursor = main.create_connection('test.sqlite') main.create_state_lookup(cursor) cursor.execute("SELECT COUNT(*) FROM state_lookup") query = cursor.fetchone()[0] conn.close() assert query >= 50
def mainScript(): date = datetime.date.today() date = date.strftime("%B %d, %Y") conn = main.create_connection(main.DB_FILE) main.create_table(conn) players = main.select_player_by_points(conn) fileBase = open("base.html", encoding="utf8") fileIndex = open("../index.html", "w", encoding="utf8") updateIndex_html(players, fileBase, fileIndex) main.print_table(conn) print("Website Updated as of {}".format(date))
def test_createconnectionexception(self, mockconnection, mock_print): db = '/home/nineleaps/PycharmProjects/cabBooking/booking' create_connection(db) mock_print.assert_called_once()
def test_createconnection(self, mockconnection): db = '/home/nineleaps/PycharmProjects/cabBooking/booking' m = create_connection(db) assert m == '1'
def test_creating_connection(self): self.assertIsNotNone(main.create_connection())