def main(): filename = 'Test_Files/DatabaseManagerTest_15.csv' ingestor = Ingestor(filename) ingestor.readCSV() print("Header of csv file") print(ingestor.getCSVHeaders()) tempHeaders = ingestor.getCSVHeaders() searchCritera = [tempHeaders[2], tempHeaders[3], tempHeaders[5]] searchCritera = ingestor.getHeaderIndex(searchCritera, tempHeaders) print("\nDictionary of search critera and their indexes in the csv") print(searchCritera) print("\nPrint raw list from csv") print(ingestor.getRowAt(1)) ingestor.searchRows(searchCritera, ingestor.getRows()) print("\nPrint filtered list from unfiltered row") print(ingestor.getRowAt(1)) print(ingestor.getRowAt(2)) print(ingestor.getRowAt(3)) print(ingestor.getRowAt(4)) print("\nNumber of columns") print(ingestor.getNumberOfHeaders()) print("\nNumber of rows") print(ingestor.getNumberOfRows()) print( "\nUpdating file to a csv in project folder names newList.csv. Expected:False" ) print( ingestor.updateFileLoc( "/home/anthonym/Documents/SchoolWork/SoftwareEngineering/newList.csv" )) print("\nUpdating file to a csv with no name. Expected:false") print(ingestor.updateFileLoc("")) print( "\nUpdating file to a csv with location Test_Files/DatabaseManagerTest_1000.csv. Expected:true" ) print(ingestor.updateFileLoc("Test_Files/DatabaseManagerTest_1000.csv"))
class IngestorTest(unittest.TestCase): def setUp(self): filename = 'Test_Files/DatabaseManagerTest_15.csv' self.ingestor = Ingestor(filename) self.ingestor.readCSV() def test_headers(self): headerList = ["Street Address","owner's first name","last_name","Long","email","phone Number","Loan Amount","Lat"] #self.assertEqual(self.ingestor.getCSVHeaders(),headerList) def test_search_headers(self): searchCritera = ["last_name","Long","phone Number"] expectedRetun = [["last_name",2],["Long",3],["phone_Number",5]] self.assertEqual(self.ingestor.getHeaderIndex(searchCritera,self.ingestor.getCSVHeaders()),expectedRetun) def test_get_row(self): expectedRetun = ["8 Hoard Court","Samuele","Gulliver","-64.1305924","*****@*****.**","+54 (656) 804-6029","$14,895.21 ","-31.4325479"] self.assertEqual(self.ingestor.getRowAt(0),expectedRetun) def test_get_row_filtered(self): searchCritera = [["last_name",2],["Long",3],["phone_Number",5]] expectedRetun = ["Gulliver","-64.1305924","+54 (656) 804-6029"] self.ingestor.searchRows(searchCritera,self.ingestor.getRows()) self.assertEqual(self.ingestor.getRowAt(0),expectedRetun) expectedRetun = ["Scoullar","121.5570313","+63 (634) 506-0432"] self.assertEqual(self.ingestor.getRowAt(4),expectedRetun) def test_number_of_headers(self): self.assertEqual(self.ingestor.getNumberOfHeaders(),8) def test_number_of_row(self): self.assertEqual(self.ingestor.getNumberOfRows(),15) def test_switch_files(self): self.assertFalse(self.ingestor.updateFileLoc("")) self.assertTrue(self.ingestor.updateFileLoc("Test_Files/DatabaseManagerTest_1000.csv"))
ingestor = Ingestor(filename) ingestor.readCSV() tempHeaders = ingestor.getCSVHeaders() searchCritera = [ tempHeaders[0], tempHeaders[1], tempHeaders[2], tempHeaders[4], tempHeaders[5], tempHeaders[6] ] searchCriteraTwoD = ingestor.getHeaderIndex(searchCritera, tempHeaders) print("\nDictionary of search critera and their indexes in the csv") print(searchCriteraTwoD) ingestor.searchRows(searchCriteraTwoD, ingestor.getRows()) print("\nPrint filtered list from unfiltered row") print(ingestor.getRowAt(0)) searchCritera = db.remove_spaces(searchCritera) new_table = 'Test_15' print('\nCreating a new table using the search critera as headers') print('If the row already exists it will throw an error and continue') db.create_table_list(new_table, searchCritera, 'string') print('\nAdding all the rows from the CSV file into new table') for person in ingestor.getRows(): db.add_row_list(new_table, searchCritera, person) print(db.get_header_index(new_table, "email")) db.add_list_of_rows(new_table, searchCritera, ingestor.getRows())