def testInsertAndRemoveDirEntries(self): homeDir = os.path.expanduser("~") dbFile = os.path.join(homeDir, "queue.db") if os.path.exists(dbFile): os.remove(dbFile) db = Database() files={"/watchDir/dir/": {}, "/watchDir/dir2/": {}, "/watchDir/dir/sub_dir/": {}} mockFileSystem = MockFileSystem( files=files, testHomePath="/watchDir") dirList, fileList = mockFileSystem.walkDirectory("/watchDir") #inserting record for dir in dirList: db.insertDir(dir) records = db.select() for record in records: filePath, timeStamp, event = record self.assertTrue(files.has_key(filePath)) self.assertTrue(filePath in dirList) self.assertEqual(event, "dir") #deleting record for dir in dirList: db.delete(dir, isDir=True) records = db.select() self.assertEqual(len(records), 0)
def testInsertDeleteWatchFolderEvent(self): #UNCOMMENT below code if need to use fresh table homeDir = os.path.expanduser("~") dbFile = os.path.join(homeDir, "queue.db") if os.path.exists(dbFile): os.remove(dbFile) db = Database() files={"/watchDir/file1": {}, "/watchDir/file2": {}, "/watchDir/file3": {}} mockFileSystem = MockFileSystem( files=files, testHomePath="/watchDir") dirList, fileList = mockFileSystem.walkDirectory("/watchDir") #deleting watchDir folder for dir in dirList: db.delete(dir) #delete event for each of the file eventName = "del" for file in fileList: db.insertFile(file, eventName, datetime.datetime.now()) records = db.select() self.assertEqual(len(records), 3) for record in records: filePath, timeStamp, event = record self.assertTrue(files.has_key(filePath)) self.assertTrue(filePath in fileList) self.assertEqual(event, eventName)
def testAddFileTogetherWithDirName(self): homeDir = os.path.expanduser("~") dbFile = os.path.join(homeDir, "queue.db") if os.path.exists(dbFile): os.remove(dbFile) db = Database() files={"/watchDir/dir/": {}, "/watchDir/dir/file1": {}, "/watchDir/file2": {}, "/watchDir/dir/sub_dir/file1": {}} mockFileSystem = MockFileSystem( files=files, testHomePath="/watchDir") dirList, fileList = mockFileSystem.walkDirectory("/watchDir") dirListExpected = ['/watchDir/', '/watchDir/dir/', '/watchDir/dir/sub_dir/'] fileListExpected = ['/watchDir/file2', '/watchDir/dir/file1', '/watchDir/dir/sub_dir/file1'] for dir in dirList: db.insertDir(dir) eventName = "mod" for file in fileList: db.insertFile(file, "mod", datetime.datetime.now()) records = db.select() self.assertEqual(len(records), 6) for record in records: filePath, timeStamp, event = record if event == "dir": self.assertTrue(filePath in dirListExpected) self.assertEqual(event, "dir") self.assertEqual(str(timeStamp), "0") else: print filePath print fileListExpected self.assertTrue(filePath in fileListExpected) self.assertEqual(event, "mod") homeDir = os.path.expanduser("~") dbFile = os.path.join(homeDir, "queue.db") if os.path.exists(dbFile): os.remove(dbFile) #try watching different directory db = Database() dirList, fileList = mockFileSystem.walkDirectory("/watchDir/dir") dirListExpected = ['/watchDir/dir/', '/watchDir/dir/sub_dir/'] fileListExpected = ['/watchDir/dir/file1', '/watchDir/dir/sub_dir/file1'] for dir in dirList: db.insertDir(dir) eventName = "mod" for file in fileList: db.insertFile(file, "mod", datetime.datetime.now()) records = db.select() self.assertEqual(len(records), 4) for record in records: filePath, timeStamp, event = record if event == "dir": self.assertTrue(filePath in dirListExpected) self.assertEqual(event, "dir") self.assertEqual(str(timeStamp), "0") else: self.assertTrue(filePath in fileListExpected) self.assertEqual(event, "mod")
def testDeleteDirectory(self): homeDir = os.path.expanduser("~") dbFile = os.path.join(homeDir, "queue.db") if os.path.exists(dbFile): os.remove(dbFile) db = Database() files={"/watchDir/dir/file1": {}, "/watchDir/file2": {}, "/watchDir/dir/sub_dir/file1": {}} mockFileSystem = MockFileSystem( files=files, testHomePath="/watchDir") dirList, fileList = mockFileSystem.walkDirectory("/watchDir") dirListExpected = ['/watchDir/', '/watchDir/dir/', '/watchDir/dir/sub_dir/'] fileListExpectedWatchDir = ['/watchDir/file2', '/watchDir/dir/file1', '/watchDir/dir/sub_dir/file1'] #insert all the record first.... for dir in dirList: db.insertDir(dir) eventName = "mod" for file in fileList: db.insertFile(file, eventName, datetime.datetime.now()) records = db.select() self.assertEqual(len(records), 6) for record in records: filePath, timeStamp, event = record if event == "dir": self.assertTrue(filePath in dirListExpected) self.assertEqual(event, "dir") self.assertEqual(str(timeStamp), "0") else: self.assertTrue(filePath in fileListExpectedWatchDir) self.assertEqual(event, "mod") #now delete /watchDir/dir dirList, fileList = mockFileSystem.walkDirectory("/watchDir/dir") dirListExpected = ['/watchDir/dir/', '/watchDir/dir/sub_dir/'] fileListExpected = ['/watchDir/dir/file1', '/watchDir/dir/sub_dir/file1'] for dir in dirList: db.delete(dir) eventName="del" for file in fileList: db.insertFile(file, eventName, datetime.datetime.now()) records = db.select() self.assertEqual(len(records), 4) for record in records: filePath, timeStamp, event = record if event == "dir": self.assertEqual(filePath, "/watchDir/") self.assertEqual(event, "dir") self.assertEqual(str(timeStamp), "0") else: self.assertTrue(filePath in fileListExpectedWatchDir) if filePath == "/watchDir/file2": self.assertEqual(event, "mod") else: self.assertEqual(event, "del")
from tkinter import * #import sqlitedb from sqlitedb import Database database = Database("Book-Database.db") def get_selected(event): try: global selected_tuple index = l1.curselection()[0] selected_tuple = l1.get(index) e1.delete(0, END) e1.insert(END, selected_tuple[1]) e2.delete(0, END) e2.insert(END, selected_tuple[2]) e3.delete(0, END) e3.insert(END, selected_tuple[3]) e4.delete(0, END) e4.insert(END, selected_tuple[4]) except IndexError: pass def update_command(): database.update(selected_tuple[0], e1_val.get(), e2_val.get(), e3_val.get(), e4_val.get()) def view_command(): l1.delete(0, END)