Beispiel #1
0
    def runTest(self):
        folder = self.setUpFolder(mock=tests.MOCK_ALWAYS_MOCK)
        folder._fs.set_case_sensitive(False)

        db = sqlite3.connect(':memory:')
        db.row_factory = sqlite3.Row
        indexer = FilesIndexer(db, folder)

        def check_and_update_all():
            checker = FilesIndexChecker(indexer.db, indexer.folder)
            checker.queue_check()
            for out_of_date in checker.check_iter():
                if out_of_date:
                    for i in indexer.update_iter():
                        pass
            indexer.db.commit()

        for name in ('aaa.txt', 'bbb.txt', 'ccc.txt'):
            folder.file(name).write('Test 123\n')

        check_and_update_all()
        self.assertFilesDBConsistent(db)
        self.assertFilesDBEquals(db, ('aaa.txt', 'bbb.txt', 'ccc.txt'))

        mtime = folder.mtime()
        folder.file('aaa.txt').moveto(folder.file('AAA.txt'))
        self.assertEqual(list(folder.list_names()),
                         ['AAA.txt', 'bbb.txt', 'ccc.txt'])
        self.assertNotEqual(folder.mtime(), mtime)

        check_and_update_all()
        self.assertFilesDBConsistent(db)
        self.assertFilesDBEquals(db, ('AAA.txt', 'bbb.txt', 'ccc.txt'))
Beispiel #2
0
    def runTest(self):
        # Test in 3 parts:
        #   1. Index existing files structure
        #   2. Check and update after new files appear
        #   3. Check and update after files disappear

        self.root = self.setUpFolder(mock=tests.MOCK_DEFAULT_REAL)
        db = sqlite3.connect(':memory:')
        db.row_factory = sqlite3.Row

        indexer = FilesIndexer(db, self.root)

        def cb_filter_func(name, o, a):
            #~ print '>>', name
            if name in ('start-update', 'finish-update'):
                self.assertFalse(a)
                return ()
            else:
                row, = a
                self.assertIsInstance(row, sqlite3.Row)
                return row['path']

        signals = tests.SignalLogger(indexer, cb_filter_func)

        def check_and_update_all():
            checker = FilesIndexChecker(indexer.db, indexer.folder)
            checker.queue_check()
            for out_of_date in checker.check_iter():
                if out_of_date:
                    for i in indexer.update_iter():
                        pass
            indexer.db.commit()

        # 1. Index existing files structure
        self.create_files(self.FILES)
        check_and_update_all()

        files = set(f for f in self.FILES if not is_dir(f))

        self.assertEqual(set(signals['file-row-inserted']), files)
        self.assertEqual(set(signals['file-row-changed']), files)
        self.assertEqual(signals['file-row-deleted'], [])

        self.assertFilesDBConsistent(db)
        self.assertFilesDBEquals(db, self.FILES)

        # 2. Check and update after new files appear
        signals.clear()
        self.create_files(self.FILES_UPDATE + self.FILES_CHANGE)
        check_and_update_all()

        files = set(f for f in self.FILES_UPDATE if not is_dir(f))
        update = files | set(self.FILES_CHANGE)

        self.assertEqual(set(signals['file-row-inserted']), files)
        self.assertEqual(set(signals['file-row-changed']), update)
        self.assertEqual(signals['file-row-deleted'], [])

        self.assertFilesDBConsistent(db)
        self.assertFilesDBEquals(db, self.FILES + self.FILES_UPDATE)

        # 3. Check and update after files disappear
        signals.clear()
        self.remove_files(self.FILES_UPDATE)
        check_and_update_all()

        files = set(f for f in self.FILES_UPDATE if not is_dir(f))

        self.assertEqual(signals['file-row-inserted'], [])
        self.assertEqual(signals['file-row-changed'], [])
        self.assertEqual(set(signals['file-row-deleted']), files)

        self.assertFilesDBConsistent(db)
        self.assertFilesDBEquals(db, self.FILES)