class DashboardModel(object): """ The class controlling the database """ def __init__(self, verbose=0, dbpath=None): """ Class constructor """ self.db = SQLiteAPI(verbose=verbose, dbpath=dbpath) def set_verbose(self, verbose=0): """ Verbose mode setter """ self.db.set_verbose(verbose=verbose) def set_dbpath(self, dbpath="./sqlite.db"): """ Database path setter """ self.db.set_dbpath(dbpath=dbpath) def exit(self): """ Close sqlite3 database Initialize the db3 object """ self.db.exit() def dump(self): """ Dump the database to store it """ return self.db.dump()
class TestDump(unittest.TestCase): """ Testsuite 1 to test map function """ def setUp(self): """ Setup function launched before a testcase """ self.dbpath = 'test/db.db3' self.unit = SQLiteAPI(verbose=1, dbpath=self.dbpath) self.unit.open() def tearDown(self): """ tearDown function launched after a testcase """ os.system("rm -fr " + self.dbpath) def test_dump(self): """ Simple test to be sure write function alive """ # Build a table to store into the database table = {} table["name"] = "Pagees" table["column"] = [] table["column"].append({"name" : 'name', "type" : "String"}) table["column"].append({"name" : 'comment', "type" : "str"}) table["column"].append({"name" : 'status', "type" : "int"}) self.unit.create_table(table) item = {} item["status"] = "OK" self.unit.write(table=table["name"], item=item) self.unit.write(table=table["name"], item=item) self.unit.write(table=table["name"], item=item) self.unit.write(table=table["name"], item=item) self.assertEqual(str, type(self.unit.dump()))