def initDb(self, name, encoding): """Initializing SQLite database""" self.dbName = name self.db = SQLite(self.dbName, encoding) self.priority = Priority(self.db) self.task = Task(self.db) # for testing purposes if self.task.count() == 0: self.db.execSql( "insert into {} (name, priority, deadline) values(?, ?, ?)". format(self.task._tableName), ("Low Test", 1, date.today() + timedelta(2))) self.db.commit()
def initDb(self, name, encoding): """Initializing SQLite database""" self.dbName = name self.db = SQLite(self.dbName, encoding) self.priority = Priority(self.db) self.task = Task(self.db) # for testing purposes if self.task.count() == 0: self.db.execSql( "insert into {} (name, priority, deadline) values(?, ?, ?)".format(self.task._tableName), ("Low Test", 1, date.today() + timedelta(2)), ) self.db.commit()
class MainWindow(QtGui.QMainWindow): """The main window of the TODO application""" def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowTitle(self.tr("Todo")) self.createActions() self.createMenus() self.createToolBars() self.createStatusBar() # read settings settings = QtCore.QSettings("todo.conf", QtCore.QSettings.IniFormat) size = settings.value("MainWindow/Size", QtCore.QSize(800, 600)) self.resize(size) position = settings.value("MainWindow/Position", QtCore.QPoint(10, 10)) self.move(position) # initializing database dbName = settings.value("Default/DB_NAME") if not dbName: dbName = "db/todo.sqlite3" settings.setValue("Default/DB_NAME", dbName) dbName = os.path.normpath(os.path.join(APP_DIR, dbName)) dbEncoding = settings.value("Default/DB_ENCODING") if not dbEncoding: dbEncoding = "utf8" settings.setValue("Default/DB_ENCODING", dbEncoding) debug = settings.value("Default/DEBUG", "False") self.debug = False if debug in ("0", "False") else True self.createDockWindows() self.logger = QCCLog(self.logWidget) # sys.stdout = sys.stderr = self.logger self.initDb(dbName, dbEncoding) if self.debug: self.logger.write("{} database initialized".format(now())) self.createTableWidget() self.setCentralWidget(self.tableWidget) def closeEvent(self, event): settings = QtCore.QSettings("todo.conf", QtCore.QSettings.IniFormat) settings.setValue("MainWindow/Size", self.size()) settings.setValue("MainWindow/Position", self.pos()) def initDb(self, name, encoding): """Initializing SQLite database""" self.dbName = name self.db = SQLite(self.dbName, encoding) self.priority = Priority(self.db) self.task = Task(self.db) # for testing purposes if self.task.count() == 0: self.db.execSql( "insert into {} (name, priority, deadline) values(?, ?, ?)".format(self.task._tableName), ("Low Test", 1, date.today() + timedelta(2)), ) self.db.commit() def createActions(self): """Create actions (for menu etc).""" self.newTaskAction = QtGui.QAction( QtGui.QIcon("images/editadd.png"), self.tr("Add TODO item"), self, shortcut=QtGui.QKeySequence.New, statusTip=self.tr("Adding new TODO item"), triggered=self.newTask, ) self.completeAction = QtGui.QAction( QtGui.QIcon("images/editedit.png"), self.tr("Complete TODO item"), self, statusTip=self.tr("Completing TODO item"), triggered=self.completeTask, ) self.deleteAction = QtGui.QAction( QtGui.QIcon("images/editdelete.png"), self.tr("Delete TODO item"), self, statusTip=self.tr("Deleting TODO item"), triggered=self.deleteTask, ) self.editAction = QtGui.QAction( QtGui.QIcon("images/filenew.png"), self.tr("Edit TODO item"), self, shortcut=QtCore.Qt.CTRL | QtCore.Qt.Key_E, statusTip=self.tr("Editing TODO item"), triggered=self.editTask, ) self.exitAction = QtGui.QAction(QtGui.QIcon("images/exit.png"), self.tr("Exit"), self) self.exitAction.setShortcut("Ctrl+Q") self.exitAction.setStatusTip(self.tr("Exit application")) self.aboutAction = QtGui.QAction( QtGui.QIcon("images/about.png"), self.tr("&About"), self, statusTip=self.tr("Show the application's About box"), triggered=self.about, ) self.aboutQtAction = QtGui.QAction( QtGui.QIcon("images/qt-logo.png"), self.tr("About &Qt"), self, statusTip=self.tr("Show the Qt library's About box"), triggered=QtGui.qApp.aboutQt, ) self.connect(self.exitAction, QtCore.SIGNAL("triggered()"), QtCore.SLOT("close()")) def createMenus(self): menubar = self.menuBar() fileMenu = menubar.addMenu(self.tr("&File")) fileMenu.addAction(self.newTaskAction) fileMenu.addAction(self.editAction) fileMenu.addAction(self.completeAction) fileMenu.addSeparator() fileMenu.addAction(self.exitAction) self.viewMenu = menubar.addMenu(self.tr("&View")) menubar.addSeparator() helpMenu = menubar.addMenu(self.tr("&Help")) helpMenu.addAction(self.aboutAction) helpMenu.addAction(self.aboutQtAction) def createToolBars(self): taskToolBar = self.addToolBar("Task") taskToolBar.setObjectName("TaskToolbar") taskToolBar.addAction(self.newTaskAction) taskToolBar.addAction(self.editAction) taskToolBar.addAction(self.completeAction) exitToolBar = self.addToolBar("Exit") exitToolBar.setObjectName("ExitToolbar") exitToolBar.addAction(self.exitAction) def createStatusBar(self): self.sizeLabel = QtGui.QLabel(" ") self.sizeLabel.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken) self.sizeLabel.setFrameStyle(QtGui.QFrame.Sunken) status = self.statusBar() status.setSizeGripEnabled(True) status.addPermanentWidget(self.sizeLabel) status.showMessage(self.tr("Ready"), 5000) def openContextMenu(self, position): menu = QtGui.QMenu(self) menu.addAction(self.newTaskAction) menu.addAction(self.editAction) menu.addAction(self.completeAction) menu.addSeparator() menu.addAction(self.deleteAction) # menu.exec_(self.tableWidget.mapToGlobal(position)) menu.popup(QtGui.QCursor.pos()) def createTableWidget(self): """Table widget creation to display TODO lists""" self.tableWidget = QtGui.QTableWidget(0, 6) self.tableWidget.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) # select one row at a time self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) # no editing values self.tableWidget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.tableWidget.setHorizontalHeaderLabels( ( self.tr("ID"), self.tr("Name"), self.tr("Priority"), self.tr("Deadline"), self.tr("Completed"), self.tr("Created"), ) ) # self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.Stretch) self.tableWidget.verticalHeader().hide() self.tableWidget.setShowGrid(True) # self.tableWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) # self.addActions(self.tableWidget, (self.newAction, self.aboutAction)) self.tableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.tableWidget.customContextMenuRequested.connect(self.openContextMenu) self.tableWidget.cellDoubleClicked.connect(self.rowDblClick) self.refreshTable() def refreshTable(self): self.tableWidget.setRowCount(0) rows = self.db.execSql("select * from TodoTask where status=0") for row in rows: cnt = self.tableWidget.rowCount() self.tableWidget.insertRow(cnt) self.tableWidget.setItem(cnt, 0, QtGui.QTableWidgetItem(str(row["id"]))) self.tableWidget.setItem(cnt, 1, QtGui.QTableWidgetItem(row["name"])) self.tableWidget.setItem(cnt, 2, QtGui.QTableWidgetItem(self.priority.getName(row["priority"]))) self.tableWidget.setItem(cnt, 3, QtGui.QTableWidgetItem(str(row["deadline"]))) self.tableWidget.setItem(cnt, 4, QtGui.QTableWidgetItem(str(row["completed"]) if row["completed"] else "")) self.tableWidget.setItem(cnt, 5, QtGui.QTableWidgetItem(str(row["created"]))) QtGui.qApp.processEvents() self.tableWidget.resizeColumnsToContents() def createDockWindows(self): dockWidget = QtGui.QDockWidget(self.tr("Log"), self) dockWidget.setObjectName("LogDockWidget") dockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.logWidget = QtGui.QListWidget() dockWidget.setWidget(self.logWidget) self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dockWidget) self.viewMenu.addAction(dockWidget.toggleViewAction()) if not self.debug: dockWidget.close() def newTask(self): dialog = NewTaskDialog(self) dialog.priority.addItems(self.priority.listNames()) if dialog.exec_(): args = {} args["name"] = dialog.name.text() args["priority"] = self.priority.getCode(dialog.priority.currentText()) args["deadline"] = dialog.deadline.date().toPyDate() args = self.task.save("", **args) self.refreshTable() def rowDblClick(self, row, col): self._updateTask(row) def editTask(self): # index of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr("Edit")) msgBox.setText(self.tr("Select a task to edit!")) msgBox.exec_() else: self._updateTask(row) def _updateTask(self, row): # id of currently selected row _id = int(self.tableWidget.item(row, 0).text()) row = self.task.read(_id) # open dialog for editing record dialog = NewTaskDialog(self) dialog.name.setText(row["name"]) dialog.priority.addItems(self.priority.listNames()) dialog.priority.setCurrentIndex(row["priority"] - 1) dialog.deadline.setDate(row["deadline"]) if dialog.exec_(): row["name"] = dialog.name.text() row["priority"] = self.priority.getCode(dialog.priority.currentText()) row["deadline"] = dialog.deadline.date().toPyDate() args = self.task.save(_id, **row) self.refreshTable() def completeTask(self): # index of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr("Complete")) msgBox.setText(self.tr("Select a task to complete!")) msgBox.exec_() return # id of currently selected row _id = self.tableWidget.item(row, 0).text() if ( QtGui.QMessageBox.question( self, self.tr("Complete"), self.tr("Are you sure to complete this task (id={})?").format(_id), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, ) == QtGui.QMessageBox.Yes ): self.db.execSql("update TodoTask set status=1, completed=? where id=?", (datetime.now(), int(_id))) self.db.commit() self.refreshTable() def deleteTask(self): # index and id of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr("Delete")) msgBox.setText(self.tr("Select a task to delete!")) msgBox.exec_() return _id = self.tableWidget.item(row, 0).text() if ( QtGui.QMessageBox.question( self, self.tr("Delete"), self.tr("Are you sure to delete this record (id={})?").format(_id), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, ) == QtGui.QMessageBox.Yes ): # remove row from table widget self.tableWidget.removeRow(row) # remove record from database self.logger.write("{} delete from TodoTask where id={}".format(now(), _id)) self.task.deleteId(_id) self.statusBar().showMessage("Deleted record id=" + _id, 5000) def about(self): QtGui.QMessageBox.about( self, self.tr("About Application"), self.tr( "The purpose of the <b>Application</b> is:<br>" " - the management of TODO lists..." "<br><br>author: <a href='mailto:[email protected]'>Igor A.Vetrov</a> © 2012" "<hr>Version: {}" ).format(getVersion()), )
class MainWindow(QtGui.QMainWindow): """The main window of the TODO application""" def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowTitle(self.tr('Todo')) self.createActions() self.createMenus() self.createToolBars() self.createStatusBar() # read settings settings = QtCore.QSettings("todo.conf", QtCore.QSettings.IniFormat) size = settings.value("MainWindow/Size", QtCore.QSize(800, 600)) self.resize(size) position = settings.value("MainWindow/Position", QtCore.QPoint(10, 10)) self.move(position) # initializing database dbName = settings.value("Default/DB_NAME") if not dbName: dbName = "db/todo.sqlite3" settings.setValue("Default/DB_NAME", dbName) dbName = os.path.normpath(os.path.join(APP_DIR, dbName)) dbEncoding = settings.value("Default/DB_ENCODING") if not dbEncoding: dbEncoding = "utf8" settings.setValue("Default/DB_ENCODING", dbEncoding) debug = settings.value("Default/DEBUG", "False") self.debug = False if debug in ("0", "False") else True self.createDockWindows() self.logger = QCCLog(self.logWidget) #sys.stdout = sys.stderr = self.logger self.initDb(dbName, dbEncoding) if self.debug: self.logger.write("{} database initialized".format(now())) self.createTableWidget() self.setCentralWidget(self.tableWidget) def closeEvent(self, event): settings = QtCore.QSettings("todo.conf", QtCore.QSettings.IniFormat) settings.setValue("MainWindow/Size", self.size()) settings.setValue("MainWindow/Position", self.pos()) def initDb(self, name, encoding): """Initializing SQLite database""" self.dbName = name self.db = SQLite(self.dbName, encoding) self.priority = Priority(self.db) self.task = Task(self.db) # for testing purposes if self.task.count() == 0: self.db.execSql( "insert into {} (name, priority, deadline) values(?, ?, ?)". format(self.task._tableName), ("Low Test", 1, date.today() + timedelta(2))) self.db.commit() def createActions(self): """Create actions (for menu etc).""" self.newTaskAction = QtGui.QAction( QtGui.QIcon('images/editadd.png'), self.tr("Add TODO item"), self, shortcut=QtGui.QKeySequence.New, statusTip=self.tr("Adding new TODO item"), triggered=self.newTask) self.completeAction = QtGui.QAction( QtGui.QIcon('images/editedit.png'), self.tr("Complete TODO item"), self, statusTip=self.tr("Completing TODO item"), triggered=self.completeTask) self.deleteAction = QtGui.QAction( QtGui.QIcon('images/editdelete.png'), self.tr("Delete TODO item"), self, statusTip=self.tr("Deleting TODO item"), triggered=self.deleteTask) self.editAction = QtGui.QAction(QtGui.QIcon('images/filenew.png'), self.tr("Edit TODO item"), self, shortcut=QtCore.Qt.CTRL | QtCore.Qt.Key_E, statusTip=self.tr("Editing TODO item"), triggered=self.editTask) self.exitAction = QtGui.QAction(QtGui.QIcon('images/exit.png'), self.tr('Exit'), self) self.exitAction.setShortcut('Ctrl+Q') self.exitAction.setStatusTip(self.tr('Exit application')) self.aboutAction = QtGui.QAction( QtGui.QIcon('images/about.png'), self.tr("&About"), self, statusTip=self.tr("Show the application's About box"), triggered=self.about) self.aboutQtAction = QtGui.QAction( QtGui.QIcon('images/qt-logo.png'), self.tr("About &Qt"), self, statusTip=self.tr("Show the Qt library's About box"), triggered=QtGui.qApp.aboutQt) self.connect(self.exitAction, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()')) def createMenus(self): menubar = self.menuBar() fileMenu = menubar.addMenu(self.tr('&File')) fileMenu.addAction(self.newTaskAction) fileMenu.addAction(self.editAction) fileMenu.addAction(self.completeAction) fileMenu.addSeparator() fileMenu.addAction(self.exitAction) self.viewMenu = menubar.addMenu(self.tr("&View")) menubar.addSeparator() helpMenu = menubar.addMenu(self.tr("&Help")) helpMenu.addAction(self.aboutAction) helpMenu.addAction(self.aboutQtAction) def createToolBars(self): taskToolBar = self.addToolBar("Task") taskToolBar.setObjectName("TaskToolbar") taskToolBar.addAction(self.newTaskAction) taskToolBar.addAction(self.editAction) taskToolBar.addAction(self.completeAction) exitToolBar = self.addToolBar("Exit") exitToolBar.setObjectName("ExitToolbar") exitToolBar.addAction(self.exitAction) def createStatusBar(self): self.sizeLabel = QtGui.QLabel(" ") self.sizeLabel.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken) self.sizeLabel.setFrameStyle(QtGui.QFrame.Sunken) status = self.statusBar() status.setSizeGripEnabled(True) status.addPermanentWidget(self.sizeLabel) status.showMessage(self.tr("Ready"), 5000) def openContextMenu(self, position): menu = QtGui.QMenu(self) menu.addAction(self.newTaskAction) menu.addAction(self.editAction) menu.addAction(self.completeAction) menu.addSeparator() menu.addAction(self.deleteAction) #menu.exec_(self.tableWidget.mapToGlobal(position)) menu.popup(QtGui.QCursor.pos()) def createTableWidget(self): """Table widget creation to display TODO lists""" self.tableWidget = QtGui.QTableWidget(0, 6) self.tableWidget.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) # select one row at a time self.tableWidget.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) # no editing values self.tableWidget.setEditTriggers( QtGui.QAbstractItemView.NoEditTriggers) self.tableWidget.setHorizontalHeaderLabels( (self.tr("ID"), self.tr("Name"), self.tr("Priority"), self.tr("Deadline"), self.tr("Completed"), self.tr("Created"))) #self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.Stretch) self.tableWidget.verticalHeader().hide() self.tableWidget.setShowGrid(True) #self.tableWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) #self.addActions(self.tableWidget, (self.newAction, self.aboutAction)) self.tableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.tableWidget.customContextMenuRequested.connect( self.openContextMenu) self.tableWidget.cellDoubleClicked.connect(self.rowDblClick) self.refreshTable() def refreshTable(self): self.tableWidget.setRowCount(0) rows = self.db.execSql("select * from TodoTask where status=0") for row in rows: cnt = self.tableWidget.rowCount() self.tableWidget.insertRow(cnt) self.tableWidget.setItem(cnt, 0, QtGui.QTableWidgetItem(str(row["id"]))) self.tableWidget.setItem(cnt, 1, QtGui.QTableWidgetItem(row["name"])) self.tableWidget.setItem( cnt, 2, QtGui.QTableWidgetItem(self.priority.getName(row["priority"]))) self.tableWidget.setItem( cnt, 3, QtGui.QTableWidgetItem(str(row["deadline"]))) self.tableWidget.setItem( cnt, 4, QtGui.QTableWidgetItem( str(row["completed"]) if row["completed"] else "")) self.tableWidget.setItem( cnt, 5, QtGui.QTableWidgetItem(str(row["created"]))) QtGui.qApp.processEvents() self.tableWidget.resizeColumnsToContents() def createDockWindows(self): dockWidget = QtGui.QDockWidget(self.tr("Log"), self) dockWidget.setObjectName("LogDockWidget") dockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.logWidget = QtGui.QListWidget() dockWidget.setWidget(self.logWidget) self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dockWidget) self.viewMenu.addAction(dockWidget.toggleViewAction()) if not self.debug: dockWidget.close() def newTask(self): dialog = NewTaskDialog(self) dialog.priority.addItems(self.priority.listNames()) if dialog.exec_(): args = {} args["name"] = dialog.name.text() args["priority"] = self.priority.getCode( dialog.priority.currentText()) args["deadline"] = dialog.deadline.date().toPyDate() args = self.task.save("", **args) self.refreshTable() def rowDblClick(self, row, col): self._updateTask(row) def editTask(self): # index of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr('Edit')) msgBox.setText(self.tr('Select a task to edit!')) msgBox.exec_() else: self._updateTask(row) def _updateTask(self, row): # id of currently selected row _id = int(self.tableWidget.item(row, 0).text()) row = self.task.read(_id) # open dialog for editing record dialog = NewTaskDialog(self) dialog.name.setText(row["name"]) dialog.priority.addItems(self.priority.listNames()) dialog.priority.setCurrentIndex(row['priority'] - 1) dialog.deadline.setDate(row['deadline']) if dialog.exec_(): row["name"] = dialog.name.text() row["priority"] = self.priority.getCode( dialog.priority.currentText()) row["deadline"] = dialog.deadline.date().toPyDate() args = self.task.save(_id, **row) self.refreshTable() def completeTask(self): # index of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr('Complete')) msgBox.setText(self.tr('Select a task to complete!')) msgBox.exec_() return # id of currently selected row _id = self.tableWidget.item(row, 0).text() if QtGui.QMessageBox.question( self, self.tr('Complete'), self.tr('Are you sure to complete this task (id={})?').format( _id), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes: self.db.execSql( 'update TodoTask set status=1, completed=? where id=?', (datetime.now(), int(_id))) self.db.commit() self.refreshTable() def deleteTask(self): # index and id of currently selected row row = self.tableWidget.currentRow() if row == -1: msgBox = QtGui.QMessageBox() msgBox.setWindowTitle(self.tr('Delete')) msgBox.setText(self.tr('Select a task to delete!')) msgBox.exec_() return _id = self.tableWidget.item(row, 0).text() if QtGui.QMessageBox.question( self, self.tr('Delete'), self.tr('Are you sure to delete this record (id={})?').format( _id), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes: # remove row from table widget self.tableWidget.removeRow(row) # remove record from database self.logger.write("{} delete from TodoTask where id={}".format( now(), _id)) self.task.deleteId(_id) self.statusBar().showMessage('Deleted record id=' + _id, 5000) def about(self): QtGui.QMessageBox.about( self, self.tr("About Application"), self. tr("The purpose of the <b>Application</b> is:<br>" " - the management of TODO lists..." "<br><br>author: <a href='mailto:[email protected]'>Igor A.Vetrov</a> © 2012" "<hr>Version: {}").format(getVersion()))
def setUp(self): with threading.Lock(): self.dbName = "test.sqlite3" self.db = SQLite(self.dbName) self.table = Priority(self.db)
class PriorityTable(unittest.TestCase): def setUp(self): with threading.Lock(): self.dbName = "test.sqlite3" self.db = SQLite(self.dbName) self.table = Priority(self.db) def tearDown(self): with threading.Lock(): if os.path.exists(self.dbName): self.db.__del__() os.unlink(self.dbName) def test_table_exists(self): self.assertTrue( self.db.tableExists(self.table._tableName) ) def test_create_sql(self): sql = "create table TodoPriority(\n" \ "\tcode integer primary key not null,\n" \ "\tname text not null,\n" \ "\tcreated timestamp default (datetime('now', 'localtime'))\n" \ ");" self.assertEqual( sql, self.table.createSql() ) def test_count(self): cnt = self.table.count() self.assertEqual( cnt, 3 ) def test_id_name(self): self.assertEqual( self.table._idName, "code" ) def test_low(self): row = self.table.select( "select name from {} where code=?;".format(self.table._tableName), (1,) )[0] self.assertEqual( row["name"], "Low" ) def test_medium(self): row = self.table.select( "select name from {} where code=?;".format(self.table._tableName), (2,) )[0] self.assertEqual( row["name"], "Medium" ) def test_high(self): row = self.table.select( "select name from {} where code=?;".format(self.table._tableName), (3,) )[0] self.assertEqual( row["name"], "High" ) def test_openId(self): self.table.openId(1) self.assertEqual( self.table.name, "Low" ) def test_read(self): args = self.table.read(2) self.assertEqual( args["code"], 2 ) self.assertEqual( args["name"], "Medium" ) self.assertEqual( args["id"], 2 ) def test_save(self): args = dict(code=9, name="Unused") args = self.table.save("", **args) self.assertEqual( self.table.count(), 4 ) self.assertEqual( args["id"], 9 ) del args args = self.table.read(9) self.assertEqual( args["id"], 9 ) self.assertEqual( args["code"], 9 ) self.assertEqual( args["name"], "Unused" ) def test_update(self): args = dict(code=9, name="Unused") args = self.table.save("", **args) del args args = self.table.read(9) args["name"] = "Used" args = self.table.save(9, **args) del args args = self.table.read(9) self.assertEqual( args["id"], 9 ) self.assertEqual( args["code"], 9 ) self.assertEqual( args["name"], "Used" ) def test_delete(self): args = self.table.deleteId(2) self.assertEqual( self.table.count(), 2 ) self.assertFalse( self.table.existsId(2) ) def test_getValue(self): value = self.table.getValue(2, "code", "name") self.assertEqual( value, (2, "Medium") ) def test_setValue(self): self.table.setValue(2, name="Changing Medium") value = self.table.getValue(2, "name") self.assertEqual( value, ("Changing Medium",) ) def test_getCode(self): code = self.table.getCode("High") self.assertEqual( code, 3 ) def test_getName(self): name = self.table.getName(3) self.assertEqual( name, "High" ) def test_listNames(self): values = self.table.listNames() self.assertEqual( values, ["Low", "Medium", "High"] ) def test_repr(self): self.table.open(2) dt = self.table['created'] value = str(self.table) self.assertEqual( value, "Priority([('created', {}, ('id', 2), ('code', 2), ('name', 'Medium')])".format(dt) ) def test_keys(self): self.table.open(2) self.assertEqual( set(list(self.table.keys())), set(["id", "code", "name", "created"]) ) def test_open(self): obj = self.table obj.open(3) self.assertEqual( obj["name"], "High" )