def setUp(self): if sys.platform == "win32": self.schema_file1 = path.join(TESTDIR, "test_schema_vsimple.xml") assert (os_file_exists(self.schema_file1)) self.schema_file2 = path.join(TESTDIR, "test_schema_vsimple2.xml") assert (os_file_exists(self.schema_file2)) else: self.schema_file1 = os.path.join( os.environ["PYTHONPATH"], "test_misc/test_schema_vsimple.xml") self.schema_file2 = os.path.join( os.environ["PYTHONPATH"], "test_mis/test_schema_vsimple2.xml") schema_execute(self.schema_file1) datarows = {'tbl_col_name': [], 'tbl_rows': []} schema_data_get(self.schema_file1, 'workout', datarows) self.database1 = Database('fitness') with self.database1: tbl_rows_insert(self.database1, 'workout', datarows['tbl_col_name'], datarows['tbl_rows']) schema_execute(self.schema_file2) schema_data_get(self.schema_file2, 'food', datarows) self.database2 = Database('diet') with self.database2: tbl_rows_insert(self.database2, 'food', datarows['tbl_col_name'], datarows['tbl_rows'])
def test_count(self): database = Database('fitness', True) with database: self.assertEquals(tbl_count_get(database, 'workout'), 2) database = Database('diet', True) with database: pass
def test_db_create(self): database = Database(test_db.name) with database: tbl_create(database, test_db.tbl_name, test_db.col_defn) database = Database(test_db.name, True) with database: self.assertTrue(database.tbl_exists(test_db.tbl_name))
def test_tbl_rows_get_all(self): database = Database(test_db.name) with database: tbl_create(database, test_db.tbl_name, test_db.col_defn) tbl_rows_insert(database, test_db.tbl_name, test_db.col_name, test_db.tbl_rows) database = Database(test_db.name, remove_flag=True) with database: col_name, tbl_rows, _ = tbl_rows_get(database, test_db.tbl_name) self.assertListEqual(col_name, test_db.col_name) self.assertListEqual(tbl_rows, test_db.tbl_rows)
def test_tbl_rows_insert_str(self): database = Database(test_db_str.name) with database: tbl_create(database, test_db_str.tbl_name, test_db_str.col_defn) tbl_rows_insert(database, test_db_str.tbl_name, test_db_str.col_name, test_db_str.tbl_rows) database = Database(test_db_str.name, remove_flag=True) with database: self.assertEquals( [['foobar', 'barfoo']], database.execute( "select col_name1,col_name2 from tbl_name_test"))
def test_insert(self): DatabaseInsertRows.insert(self.database_name, self.table_name, self.columns, self.row) database = Database(self.database_name, True) with database: _, result, _ = tbl_rows_get(database, self.table_name) self.assertEqual(result, self.row)
def test_tbl_rows_insert_str_1col(self): database = Database(test_db_str_1col.name) with database: tbl_create(database, test_db_str_1col.tbl_name, test_db_str_1col.col_defn) tbl_rows_insert(database, test_db_str_1col.tbl_name, test_db_str_1col.col_name, test_db_str_1col.tbl_rows) database = Database(test_db_str_1col.name, remove_flag=True) with database: self.assertEquals( 'foobar', database.execute("select col_name1 from tbl_name_test", True))
def test_insert_by_file_encoded(self): # encoding of input / output files # encoding of database content append_text_to_file( self.filename, "database_name:" + b64encode(self.database_name) + "\n") append_text_to_file(self.filename, "table_name:" + b64encode(self.table_name) + "\n") append_text_to_file(self.filename, "delete_flag:" + b64encode("False") + "\n") #append_text_to_file(self.filename,"decode_flag:"+b64encode("False") + "\n") append_text_to_file( self.filename, "columns:" + "$$".join([b64encode(field) for field in self.columns]) + "\n") put_2darray_in_file(self.filename, self.row, suffix="rows:", encoding="base64") DatabaseInsertRows.insert_by_file(self.filename) database = Database(self.database_name, True) with database: _, result, _ = tbl_rows_get(database, self.table_name) self.assertEqual(DatabaseBase._decode_2darray(result), self.row) os_file_delete(self.filename)
def test_create_by_file_encoded_an_set_runtime_path(self): self.filename = "b64pyshell.txt" runtime_path = "C:\\Users\\burtnolej" append_text_to_file( self.filename, "database_name:" + b64encode(self.database_name) + "\n") append_text_to_file(self.filename, "table_name:" + b64encode(self.table_name) + "\n") append_text_to_file(self.filename, "delete_flag:" + b64encode("False") + "\n") append_text_to_file( self.filename, "column_defns:" + "$$".join([ b64encode(_name) + "^" + b64encode(_type) for _name, _type in self.column_defn ]) + "\n") DatabaseCreateTable.create_by_file(self.filename, runtime_path=runtime_path) database = Database( runtime_path + "\\" + self.database_name + ".sqlite", True) with database: self.assertTrue(tbl_exists(database, self.table_name)) os_file_delete(self.filename)
def test_tbl_create_pk(self): database = Database(test_db.name) with database: tbl_create(database, test_db.tbl_name, test_db.col_defn, test_db.tbl_pk_defn) database = Database(test_db.name, True) with database: self.assertEquals(1, tbl_index_count(database, test_db.tbl_name)) self.assertListEqual( test_db.tbl_pk_defn, tbl_index_defn_get(database, test_db.tbl_name))
def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') datamembers = dict(period='830-910',student='Booker',dow='MO', teacher='Amelia',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson0',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='910-950',student='Booker',dow='MO', teacher='Stan',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson1',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='950-1020',student='Booker',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson2',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='830-910',student='Clayton',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson3',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
def test_insert_encoded_by_file(self): append_text_to_file( self.filename, "database_name:" + b64encode(self.database_name) + "\n") append_text_to_file(self.filename, "table_name:" + b64encode(self.table_name) + "\n") append_text_to_file(self.filename, "delete_flag:" + b64encode("False") + "\n") append_text_to_file(self.filename, "decode_flag:" + b64encode("True") + "\n") append_text_to_file( self.filename, "columns:" + "$$".join([b64encode(field) for field in self.columns]) + "\n") put_2darray_in_file(self.filename, self.row, suffix="rows:", encoding="base64") DatabaseInsertRows.insert_by_file(self.filename, runtime_path=self.runtime_path) database = Database( self.runtime_path + "\\" + self.database_name + ".sqlite", True) with database: _, result, _ = tbl_rows_get(database, self.table_name) self.assertEqual(DatabaseBase._decode_2darray(result), self.row)
def test_tbl_rows_get_spoecific_field(self): database = Database(test_db.name) with database: tbl_create(database, test_db.tbl_name, test_db.col_defn) tbl_rows_insert(database, test_db.tbl_name, test_db.col_name, test_db.tbl_rows) database = Database(test_db.name, remove_flag=True) with database: col_name, tbl_rows, _ = tbl_rows_get( database, test_db.tbl_name, ['col_name1', 'col_name2', 'col_name3', 'col_name4']) self.assertListEqual(col_name, test_db.col_name) self.assertListEqual(tbl_rows, test_db.tbl_rows)
def test_(self): append_text_to_file( self.filename, "columns:" + "$$".join([b64encode(field) for field in self.columns]) + "\n") rows = get_2darray_from_file(path.join(TESTDIR, "testdata.csv")) put_2darray_in_file(self.filename, rows, suffix="rows:", encoding="base64") DatabaseInsertRows.insert_by_file(self.filename) database = Database(self.database_name, True) with database: columns, rows, _ = tbl_query( database, "select Description from foobar where LastName = \"" + b64encode("Osborn") + "\"") expected_results = [ b64encode( "dictum mi, ac mattis velit justo nec ante. Maecenas mi felis, adipiscing fringilla, porttitor vulputate, posuere vulputate, lacus. Cras interdum. Nunc sollicitudin commodo ipsum. Suspendisse non leo. Vivamus nibh dolor, nonummy ac, feugiat non, lobortis quis, pede. Suspendisse dui. Fusce diam nunc, ullamcorper eu, euismod ac, fermentum vel, mauris. Integer sem elit, pharetra ut, pharetra sed, hendrerit a, arcu. Sed et" ) ] self.assertListEqual(rows[0], expected_results)
def test_tbl_cols_get(self): schema_execute(self.schema_file) database = Database('fitness', remove_flag=True) with database: self.assertListEqual([('date', 'datetime'), ('type', 'text')], tbl_cols_get(database, 'workout')) database = Database('diet', remove_flag=True) with database: self.assertListEqual([('name', 'text'), ('calories', 'integer')], tbl_cols_get(database, 'food')) self.assertListEqual([('type', 'text'), ('time', 'datetime')], tbl_cols_get(database, 'meals'))
def test_db_create_from_schema(self): schema_execute(self.schema_file) database = Database('fitness', True) with database: self.assertTrue(database.tbl_exists('workout')) database = Database('diet') with database: self.assertTrue(database.tbl_exists('food')) database = Database('diet', True) with database: self.assertTrue(database.tbl_exists('meals'))
def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') self.datamembers = dict(period='830', student='Booker', teacher='Amelia', saveversion=0, session='AM.AC.SC')
def test_persist(self): with self.database: self.foobar.persist() self.database = Database('foobar',True) with self.database: col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['student','teacher']) self.assertEquals([['Booker','Amelia']],tbl_rows)
def test_persist(self): with self.database: self.dbg.persist() self.database = Database(test_db.name, True) with self.database: col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest', ['col1', 'col2', 'col3']) self.assertEquals([[123, 456, 789]], tbl_rows)
def test_persist(self): with self.database: self.dbg.persist() self.database = Database(test_db.name, remove_flag=True) with self.database: col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest', ['col1']) self.assertEquals([["abc"]], tbl_rows)
def test_persist_customtimestamp(self): self.foobar.customtimestamp = "%y%m%d_%H%M%S" with self.database: self.foobar.persist() self.database = Database('foobar',True) with self.database: col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['__timestamp']) self.assertTrue(13,len(tbl_rows[0][0]))
def __init__(self, dbname, tblname, fldname, **kwargs): database = Database(dbname) with database: rows = tbl_rows_get(database, tblname, [fldname]) # rows is a tuple; list is element 2 kwargs['set'] = [row[0] for row in rows[1]] super(DBSetMember, self).__init__(**kwargs) self.validations.append(_SetMemberVdt(**kwargs))
def test_tbl_rows_insert_dupe_key(self): database = Database(test_db.name, remove_flag=True) with database: tbl_create(database, test_db.tbl_name, test_db.col_defn, test_db.tbl_pk_defn) with self.assertRaises(S3IntegrityError): tbl_rows_insert(database, test_db.tbl_name, test_db.col_name, test_db.tbl_rows_dupe_key)
def test_insert_encoded(self): DatabaseInsertRows.insert(self.database_name, self.table_name, self.columns, self.row, encoding="base64") database = Database(self.database_name, True) with database: _, result, _ = tbl_rows_get(database, self.table_name) self.assertEqual(DatabaseBase._decode_2darray(result), self.row)
def test_tbl_rows_insert_from_schema(self): schema_execute(self.schema_file) database = Database('fitness') with database: tbl_rows_insert_from_schema(database, self.schema_file, 'workout') database = Database('fitness', remove_flag=True) with database: tbl_col_name, tbl_rows, _ = tbl_rows_get(database, 'workout') self.assertListEqual(tbl_rows, [[250772, 'cycling'], [260772, 'rowing']]) # this is there to force the delete of the 2nd db created but does database = Database('diet', True) with database: pass
def test_tbl_col_add(self): schema_execute(self.schema_file) database = Database('fitness') with database: tbl_col_add(database, 'workout', 'foobar', 'text') database = Database('fitness', remove_flag=True) with database: self.assertListEqual([('date', 'datetime'), ('type', 'text'), ('foobar', 'text')], tbl_cols_get(database, 'workout')) # this is there to force the delete of the 2nd db created but does database = Database('diet', remove_flag=True) with database: pass
def setUp(self): self.database = Database(test_db.name, remove_flag=True) class dbtbltest(dbtblgeneric): pass self.dbg = dbtbltest.datamembers(database=self.database, dm={'col1': 123}) self.dbg2 = dbtbltest.datamembers(database=self.database, dm={'col1': 456})
def setUp(self): self.database = Database(test_db.name, remove_flag=True) class dbtbltest(dbtblgeneric): pass self.dbg = dbtbltest.datamembers(database=self.database, dm={'col1': 123}) self.dbg.customtimestamp = "%y%m%d_%H%M%S" self.dbg.keepversion = True
def setUp(self): self.database = Database(test_db.name, remove_flag=True) class dbtbltest(dbtblgeneric): pass self.dbg = dbtbltest.datamembers(database=self.database, dm={'col1': 123}) self.dbg.tbl_name_get() self.dbg.tbl_col_defn_get(False) self.dbg.tbl_row_value_get(False)
def test_dbobject_db_str_insert(self): # tests that string values are wrapped in quotes with self.database: #with self.assertRaises(S3OperationalError): self.dbg.persist() self.database = Database(test_db.name, remove_flag=True) with self.database: col_name, tbl_rows, _ = tbl_rows_get(self.database, 'dbtbltest', ['col1']) self.assertEquals([["foobar"]], tbl_rows)