def test_remove(self): """Remove args should remove the record.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'remove' in args] for args in args_set: args.func(args) # Check that the record has been deleted nose.tools.assert_false(database.lookup_record( TEST_NAME, 'name', TEST_PB, TEST_DB)) # Check that there's one less record nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record]) self.tearDown() self.setUp() def test_all_else(self): """Change and reverse-lookup should raise Exceptions. Script isn't ready for this though.""" pass
def write_data(): if request.method == 'POST': # message = request.form['userInput'] data = request.get_json() res = make_response(data['message']) cookie = request.cookies user_id = cookie.get('user_id') print(user_id) if user_id == None: user_id_list = database.read_table(database_name, message_table_name, "user_id") for ids in user_id_list: new_id = rand.randint(1000001, 9999999) if not user_id_list.count(new_id): user_id = new_id break res.set_cookie('user_id', f'{user_id}', expires='never') # Determine time of input here instead of taking from client-side js############################## epoch = round(time.time()) epoch = int(epoch) * 1000 database.add_to_database(database_name, database_columns, message_table_name, user_id, data['message'], epoch) print(data) print(epoch) return res
def test_add(self): """Add args should create a new record and leave other records alone.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'add' in args] for args in args_set: args.func(args) # Check that the record was added nose.tools.assert_true( database.lookup_record(TEST_NAME, 'name', TEST_PB, TEST_DB) == [TEST_RECORD]) # Check that only one record was added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS + 1) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record]) self.tearDown() self.setUp()
def test_change(self): """Change args should change the record.""" new_num = 'test_new_num' new_record = (TEST_NAME, new_num) args_set = [self.parser.parse_args(args) for args in read_args() if 'change' in args] for args in args_set: args.func(args) # Check that the test record has been modified nose.tools.assert_true(database.lookup_record( TEST_NAME, 'name', TEST_PB, TEST_DB) == [new_record]) # Check that no other records were added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS + 1) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record]) self.tearDown() self.setUp()
def get_consults(fname): # Read consultas.txt f = open(fname, 'r') # First line is the number of tables tb_num = int(f.readline().strip()) tbs = [db.read_table(f.readline().strip()) for i in range(tb_num)] tbs = {tname: tb for tname, tb in tbs} # Next line is the number of queries # Assumes that each line is one complete query query_num = int(f.readline().strip()) consults = [f.readline().strip() for i in range(query_num)] # close file f.close() return tbs, consults
def read_database(): if request.method == 'GET': data_json = {} message_count = 0 inputs = database.read_table(database_name, message_table_name) if inputs != None: for messages in inputs: data_json.update( {str(message_count): [messages[2], messages[3]]}) message_count += 1 # print(data_json) return jsonify(data_json) else: return "Error: Table does not exist"
def test_change_remove(self): """Change and remove args should raise Exceptions.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'change' in args or 'remove' in args] for args in args_set: nose.tools.assert_raises(Exception, args.func, args) # Check that no records were added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record])
def test_reverse_lookup(self): """Reverse-lookup args should return no results.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'reverse-lookup' in args] for args in args_set: # Check that lookup returns no results nose.tools.assert_false(args.func(args)) # Check that no records were added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record])
def test_add(self): """Add args should raise exceptions and not modify db.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'add' in args] for args in args_set: nose.tools.assert_raises(Exception, args.func, args) # Check that the test record hasn't been modified nose.tools.assert_true(database.lookup_record( TEST_NAME, 'name', TEST_PB, TEST_DB) == [TEST_RECORD]) # Check that no other records were added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS + 1) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record])
def test_reverse_lookup(self): """Reverse-lookup should return result.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'reverse-lookup' in args] for args in args_set: # Check that lookup returns the correct record nose.tools.assert_true(args.func(args) == [TEST_RECORD]) # Check that the test record hasn't been modified nose.tools.assert_true(database.lookup_record( TEST_NUM, 'number', TEST_PB, TEST_DB) == [TEST_RECORD]) # Check that no records were added nose.tools.assert_true( len(database.read_table( TEST_PB, TEST_DB)) == NUM_RECORDS + 1) # Check that all other records remain the same for record in read_records(): nose.tools.assert_true(database.lookup_record( record[0], 'name', TEST_PB, TEST_DB) == [record])
def test_create(self): """Tests the create argument, which should create a new table.""" args_set = [self.parser.parse_args(args) for args in read_args() if 'create' in args] for args in args_set: args.func(args) # Check that the table was created nose.tools.assert_true( database.table_exists(TEST_PB, TEST_DB)) # Check that only one table was created nose.tools.assert_true( len(database.list_tables(TEST_DB)) == 1) # Check that no records were added nose.tools.assert_true( len(database.read_table(TEST_PB, TEST_DB)) == 0) # Delete and recreate TEST_DB # There's probably a better way to do this self.tearDown() self.setUp()
# Get temperature temp = sense.get_temperature() tempF = temp * (9 / 5) + 32 intTempF = int(tempF) - 40 # Subtracting 40 accounts for the processor running hot on the Pi # print("Temperature in F = " +str(intTempF)) # Get pressure and print to console # pressure = sense.get_pressure() # print("Pressure = " +str(pressure)) # Get humidity humidity = sense.get_humidity() intHumidity = int(humidity) # print("Humidity = " +str(intHumidity)) # Connect to table database.init() # Add values to database database.add_new(intTempF, intHumidity) # Read table for debug purposes database.read_table() # Check temperature and alert the user if (intTempF > temp_threshold): webex.webex_alert("Temperature on Solar Panel 1 is %s degrees F" % (str(intTempF)))
# -*- coding: utf-8 -*- # Created on 2015 10 21 __author__ = 'SugN' __copyright__ = "Copyright 2015, SugN All Rights Reserved." __credits__ = [""] __license__ = "GPL" __version__ = "1.0.1" """ """ import database if __name__ == '__main__': print("test") database.read_table('2015.xls')
def setUp(self): # Simple expression self.e1 = 'EMPRESTA Persona, AnoNac DE personas;' # Long expression self.e2 = 'EMPRESTA AnoNac DE personas ' \ 'ONDE (AnoNac < 1995) ' \ 'ORDENATELOS X AnoNac PA RIBA;' # Expression with all keywords self.e3 = '(EMPRESTA AnoNac DE personas ' \ 'ONDE (AnoNac < 1995) ' \ 'ORDENATELOS X AnoNac PA RIBA) ' \ 'UNETELO CN ' \ '(EMPRESTA AnoNac DE personas ' \ 'ONDE (AnoNac > 1990));' # Testing conditional expressions # Comparators # '=' 'O' self.e4 = 'EMPRESTA Persona,AnoNac,Sexo DE personas ' \ 'ONDE (Persona = 10046101) O (Persona = 10002004);' # '<' '>=' self.e5 = 'EMPRESTA Persona,AnoNac,Sexo DE personas ' \ 'ONDE (Persona < 10004101) Y (Persona >= 10002004);' # '>' '!=' self.e6 = 'EMPRESTA Id, Comuna DE comunas ' \ 'ONDE (Id > 337) Y (Comuna != "PADRE HURTADO");' # 'Y' '<=''PARECIO A' self.e7 = 'EMPRESTA Id,Comuna DE comunas ' \ 'ONDE (Id <= 19) Y (Comuna PARECIO A "C");' # Set up files for test queries, test_tb is a dictionary tname1, tb1 = db.read_table('personas.csv') self.personas_tb = {tname1: tb1} tname2, tb2 = db.read_table('comunas.csv') self.comunas_tb = {tname2: tb2} tname3, tb3 = db.read_table("src/pokemon.csv") self.pokemon_tb = {tname3[4:]: tb3} tname4, tb4 = db.read_table('src/poke_estadisticas.csv') self.poke_estad_tb = {tname4[4:]: tb4} tname5, tb5 = db.read_table('src/estadisticas.csv') self.estad_tb = {tname5[4:]: tb5} tname6, tb6 = db.read_table('src/encuentros.csv') self.encuentros_tb = {tname6[4:]: tb6} self.tables = {} self.tables.update(self.personas_tb) self.tables.update(self.comunas_tb) self.tables.update(self.pokemon_tb) self.tables.update(self.poke_estad_tb) self.tables.update(self.estad_tb) self.tables.update(self.encuentros_tb) # set up testing column self.col1_name = 'col1' self.col1_vals = [i for i in range(100, 200)] self.col2_name = 'col2' self.col2_vals = [i for i in range(150, 250)] self.col3_name = 'col3' self.col3_vals = [str(i) + str(i + 1) for i in range(0, 10000)] # set up tables for testing ORDENATELOS and SOLO self.per_col = [10001001, 10001002, 10001003, 10002001, 10002002, 10002003, 10002004, 10002005, 10003001] self.nac_col = [1958, 1956, 1982, 1954, 1961, 1977, 1981, 1995, 1933] self.sex_col = [1, 2, 2, 1, 2, 1, 1, 1, 1] self.unordered_tb = {'Persona': self.per_col, 'AnoNac': self.nac_col, 'Sexo': self.sex_col} # Set up tables for testing join query results self.jcol1 = ['a', 'b', 'c'] self.jcol2 = ['b', 'c', 'd'] self.jcol3 = ['c', 'd', 'e'] self.jtb1 = {'col1': self.jcol1} self.jtb2 = {'col1': self.jcol2} self.jtb3 = {'col1': self.jcol3} # Set up tables for testing get grouping self.gcol1 = ['a', 'b', 'a', 'c', 'c', 'b'] self.gtb1 = {'col1': self.gcol1} # Set up tables for testing do_col_func self.dcol1 = ['a', 'a', 'b', 'b', 'c', 'c'] self.dcol2 = [1, 3, 2, 4, 5, 7] self.dtb1 = {'col1': self.dcol1, 'col2': self.dcol2}