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_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_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_insert_by_file(self): # no encoding of input / output files # no encoding of database content self.filename = "unipyshell.txt" append_text_to_file(self.filename, "database_name:" + self.database_name + "\n") append_text_to_file(self.filename, "table_name:" + self.table_name + "\n") append_text_to_file(self.filename, "delete_flag:False" + "\n") append_text_to_file( self.filename, "columns:" + "$$".join([field for field in self.columns]) + "\n") put_2darray_in_file(self.filename, self.row, suffix="rows:") DatabaseInsertRows.insert_by_file(self.filename) database = Database(self.database_name, True) with database: _, result, _ = tbl_rows_get(database, self.table_name) self.assertEqual(result, self.row) os_file_delete(self.filename)
def setUp(self): self.database_name = 'foobar' self.table_name = 'foobar' self.columns = ['col1', 'col2', 'col3'] self.column_defn = [('col1', 'text'), ('col2', 'text'), ('col3', 'integer')] self.row = [['x', 'y', 6]] self.qrow = _quotestrs(self.row) self.filename = "b64pyshell.txt" self.b64row = DatabaseBase._encode_2darray(self.row) self.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, "columns:" + "$$".join([b64encode(field) for field in self.columns]) + "\n") append_text_to_file( self.filename, "column_defns:" + "$$".join([ b64encode(_name) + "^" + b64encode(_type) for _name, _type in self.column_defn ]) + "\n") append_text_to_file( self.filename, "qry_str:" + b64encode("select col1,col2,col3 from " + self.table_name) + "\n") put_2darray_in_file(self.filename, self.b64row, suffix="rows:") DatabaseCreateTable.create_by_file(self.filename, runtime_path=self.runtime_path) DatabaseInsertRows.insert_by_file(self.filename, runtime_path=self.runtime_path)