Пример #1
0
 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)
Пример #2
0
 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")
Пример #3
0
 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")