Beispiel #1
0
 def test_get_data_returns_dict(self):
     ''' ensure we get a dict of Station_Information back '''
     session = get_session(env='TST', echo=True)
     metadata = create_metadata(Station_Information, session)
     data = get_data(Station_Information, metadata)
     self.assertIsInstance(data, dict)
     session.close()
 def test_load_on_empty(self):
     ''' all records pulled down should be loaded into db '''
     session = get_session(env='TST', echo=True)
     metadata = create_metadata(System_Region, session)
     data = get_data(System_Region, metadata)
     compare_data(data, System_Region, metadata, session)
     session.commit()
     # get data from db
     conn, cur = get_connection_and_cursor()
     cur.execute('''SELECT region_id,
                    region_name,
                    row_modified_tstmp,
                    load_id,
                    transtype,
                    modified_by
                    FROM system_regions''')
     db_data = cur.fetchall()
     correct = True
     # compare each val of each row from db to each row pulled from web
     i = 0
     while i < len(db_data) and correct:
         row = db_data[i]
         orig = data[row[0]].to_tuple()
         correct = (row == orig)
         if not correct:
             print(f'row {row} didnt match orig {orig}')
         i += 1
     self.assertTrue(correct)
     empty_db(session)
     session.close()
Beispiel #3
0
 def test_get_data_dict_key_is_id(self):
     ''' ensure dict key is row.id'''
     session = get_session(env='TST', echo=True)
     metadata = create_metadata(Station_Information, session)
     data = get_data(Station_Information, metadata)
     correct = True
     for row in data:
         if row != data[row].id:
             correct = False
     self.assertTrue(correct)
     session.close()
Beispiel #4
0
 def test_load_on_empty(self):
     ''' all records pulled down should be loaded into db '''
     session = get_session(env='TST', echo=True)
     metadata = create_metadata(Station_Information, session)
     data = get_data(Station_Information, metadata)
     compare_data(data, Station_Information, metadata, session)
     session.commit()
     # get data from db
     conn, cur = get_connection_and_cursor()
     cur.execute('''SELECT station_id,
                    short_name,
                    station_name,
                    lat,
                    lon,
                    capacity,
                    region_id,
                    eightd_has_key_dispenser,
                    rental_method_key,
                    rental_method_creditcard,
                    rental_method_paypass,
                    rental_method_applepay,
                    rental_method_androidpay,
                    rental_method_transitcard,
                    rental_method_accountnumber,
                    rental_method_phone,
                    row_modified_tstmp,
                    load_id,
                    transtype,
                    modified_by
                    FROM station_information;''')
     db_data = cur.fetchall()
     correct = True
     # compare each val of each row from db to each row pulled from web
     i = 0
     while i < len(db_data) and correct:
         row = db_data[i]
         orig = data[row[0]].to_tuple()
         correct = (row == orig)
         if not correct:
             print(f'row {row} didnt match orig {orig}')
         i += 1
     self.assertTrue(correct)
     empty_table_station_information(session)
     session.close()
Beispiel #5
0
 def test_update_only_updates_that_record(self):
     ''' load, then load an update. ensure only that record was updated'''
     # first get data and load
     session = get_session(env='TST', echo=True)
     metadata = create_metadata(Station_Information, session)
     data = get_data(Station_Information, metadata)
     compare_data(data, Station_Information, metadata, session)
     session.commit()
     # get tuple copies of each record that was loaded
     originals = {}
     for row in data:
         originals[row] = data[row].to_tuple()
     # now get data again
     m2 = create_metadata(Station_Information, session)
     d2 = get_data(Station_Information, m2)
     # get one record from data and make a change
     u_record = d2[list(d2.keys())[0]]
     u_record.station_name = 'phoney balogna'
     u_data = {u_record.id: u_record}
     # load new record (should be update)
     compare_data(u_data, Station_Information, metadata, session)
     session.commit()
     # get all current data from db
     conn, cur = get_connection_and_cursor()
     cur.execute('''SELECT station_id,
                    short_name,
                    station_name,
                    lat,
                    lon,
                    capacity,
                    region_id,
                    eightd_has_key_dispenser,
                    rental_method_key,
                    rental_method_creditcard,
                    rental_method_paypass,
                    rental_method_applepay,
                    rental_method_androidpay,
                    rental_method_transitcard,
                    rental_method_accountnumber,
                    rental_method_phone,
                    row_modified_tstmp,
                    load_id,
                    transtype,
                    modified_by
                    FROM station_information;''')
     db_data = cur.fetchall()
     row_updated = True
     rows_match = True
     correct_trans = True
     # iterate through db data. break if any test fails
     i = 0
     while i < len(db_data) and\
             row_updated and\
             rows_match and\
             correct_trans:
         row = db_data[i]
         orig = originals[row[0]]
         if row[0] == u_record.id:
             trans = 'U'
             # update orig should not match row and ensure name was updated
             row_updated = (orig != row) and (row[2] == 'phoney balogna')
         else:
             # all other records row should match orig
             trans = 'I'
             rows_match = (orig == row)
         correct_trans = (row[-2] == trans)
         if not row_updated:
             print(f'row {row} shouldnt match orig {orig}')
             print('also, region_name in row should be phoney balogna')
         if not rows_match:
             print(f'row {row} didnt match orig {orig}')
         if not correct_trans:
             print(f'incorrect trans on row {row} -- should be {trans}')
         i += 1
     self.assertTrue(row_updated and rows_match and correct_trans)
     empty_table_station_information(session)
     session.close()