class StubbedTest(unittest.TestCase): def openLegacyStore(self): """ Extract the Store tarball associated with this test, open it, and return it. """ temp = self.mktemp() f = sys.modules[self.__module__].__file__ dfn = os.path.join( os.path.dirname(f), os.path.basename(f).split("test_")[1].split('.py')[0] + '.axiom') arcname = dfn + '.tbz2' tarball = tarfile.open(arcname, 'r:bz2') for member in tarball.getnames(): tarball.extract(member, temp) return Store(os.path.join(temp, os.path.basename(dfn))) def setUp(self): """ Prepare to test a stub by opening and then fully upgrading the legacy store. """ self.store = self.openLegacyStore() self.service = IService(self.store) self.service.startService() return self.store.whenFullyUpgraded() def tearDown(self): return self.service.stopService()
class StubbedTest(unittest.TestCase): def openLegacyStore(self): """ Extract the Store tarball associated with this test, open it, and return it. """ temp = self.mktemp() f = sys.modules[self.__module__].__file__ dfn = os.path.join( os.path.dirname(f), os.path.basename(f).split("test_")[1].split('.py')[0]+'.axiom') arcname = dfn + '.tbz2' tarball = tarfile.open(arcname, 'r:bz2') for member in tarball.getnames(): tarball.extract(member, temp) return Store(os.path.join(temp, os.path.basename(dfn))) def setUp(self): """ Prepare to test a stub by opening and then fully upgrading the legacy store. """ self.store = self.openLegacyStore() self.service = IService(self.store) self.service.startService() return self.store.whenFullyUpgraded() def tearDown(self): return self.service.stopService()
def closeStore(self): """ Close C{self.currentStore} and discard the reference. If there is a store service running, stop it first. """ service = IService(self.currentStore) if service.running: result = service.stopService() else: result = succeed(None) def close(ignored): self.currentStore.close() self.currentStore = None result.addCallback(close) return result
def closeStore(self): """ Close C{self.currentTopStore} and C{self.currentSubStore}. If there is a store service running in C{self.currentTopStore}, stop it first. """ service = IService(self.currentTopStore) if service.running: result = service.stopService() else: result = succeed(None) def stopped(ignored): self.currentSubStore.close() self.currentTopStore.close() self.currentSubStore = None self.currentTopStore = None result.addCallback(stopped) return result
def closeStore(self): """ Close C{self.currentStore} and discard the reference. If there is a store service running, stop it first. """ service = IService(self.currentStore) if service.running: result = service.stopService() else: result = succeed(None) def close(ignored): self.currentStore.close() self.currentStore = None result.addCallback(close) return result
class SubSchedTest(SchedTest): def setUp(self): self.storePath = self.mktemp() self.store = Store(self.storePath) Scheduler(store=self.store).installOn(self.store) self.svc = IService(self.store) self.svc.startService() def tearDown(self): return self.svc.stopService() def testSubScheduler(self): substoreItem = SubStore.createNew(self.store, ['scheduler_test']) substore = substoreItem.open() SubScheduler(store=substore).installOn(substore) return self._doTestScheduler(substore)
class StubbedTest(unittest.TestCase): def setUp(self): temp = self.mktemp() f = sys.modules[self.__module__].__file__ dfn = os.path.join( os.path.dirname(f), os.path.basename(f).split("test_")[1].split('.py')[0]+'.axiom') arcname = dfn + '.tbz2' tarball = tarfile.open(arcname, 'r:bz2') for member in tarball.getnames(): tarball.extract(member, temp) self.store = Store(os.path.join(temp, os.path.basename(dfn))) self.service = IService(self.store) self.service.startService() return self.store.whenFullyUpgraded() def tearDown(self): return self.service.stopService()
def closeStore(self): """ Close C{self.currentTopStore} and C{self.currentSubStore}. If there is a store service running in C{self.currentTopStore}, stop it first. """ service = IService(self.currentTopStore) if service.running: result = service.stopService() else: result = succeed(None) def stopped(ignored): self.currentSubStore.close() self.currentTopStore.close() self.currentSubStore = None self.currentTopStore = None result.addCallback(stopped) return result
def stopStoreService(self): service = IService(self.store) if service.running: return service.stopService()
class IndexerAPISearchTestsMixin(IndexerTestsMixin): """ Test ISearchProvider search API on indexer objects """ def setUp(self): """ Make a store, an account/substore, an indexer, and call startService() on the superstore's IService so the batch process interactions that happen in fulltext.py work """ self.dbdir = self.mktemp() self.path = u'index' superstore = store.Store(self.dbdir) loginSystem = LoginSystem(store=superstore) installOn(loginSystem, superstore) account = loginSystem.addAccount(u'testuser', u'example.com', None) substore = account.avatars.open() self.store = substore self.indexer = self.createIndexer() self.svc = IService(superstore) self.svc.startService() # Make sure the indexer is actually available writer = self.openWriteIndex() writer.close() def tearDown(self): """ Stop the service we started in C{setUp} """ return self.svc.stopService() def _indexSomeItems(self): writer = self.openWriteIndex() for i in xrange(5): writer.add(IndexableThing( _documentType=u'thing', _uniqueIdentifier=str(i), _textParts=[u'text'], _keywordParts={})) writer.close() def testIndexerSearching(self): """ Test calling search() on the indexer item directly """ def gotResult(res): self.assertEquals(identifiersFrom(res), range(5)) self._indexSomeItems() return self.indexer.search(u'text').addCallback(gotResult) def testIndexerSearchingCount(self): """ Test calling search() on the indexer item directly, with a count arg """ def gotResult(res): self.assertEquals(identifiersFrom(res), [0]) self._indexSomeItems() return self.indexer.search(u'text', count=1).addCallback(gotResult) def testIndexerSearchingOffset(self): """ Test calling search() on the indexer item directly, with an offset arg """ def gotResult(res): self.assertEquals(identifiersFrom(res), [1, 2, 3, 4]) self._indexSomeItems() return self.indexer.search(u'text', offset=1).addCallback(gotResult) def testIndexerSearchingCountOffset(self): """ Test calling search() on the indexer item directly, with count & offset args """ def gotResult(res): self.assertEquals(identifiersFrom(res), [1, 2, 3]) self._indexSomeItems() return self.indexer.search(u'text', count=3, offset=1) def test_DifficultTokens(self): """ Test searching for fragments of phone numbers, email addresses, and urls. """ writer = self.openWriteIndex() specimens = [u"trevor 718-555-1212", u"bob [email protected]", u"atop http://divmod.org/projects/atop"] for i, txt in enumerate(specimens): writer.add(IndexableThing( _documentType=u'thing', _uniqueIdentifier=str(i), _textParts=[txt], _keywordParts={})) writer.close() def gotResult(res): return identifiersFrom(res) def testResults(results): self.assertEqual(results, [[0], [1], [2], [0], [1], [2]]) return gatherResults( [self.indexer.search(u'718').addCallback(gotResult), self.indexer.search(u'moddiv').addCallback(gotResult), self.indexer.search(u'divmod').addCallback(gotResult), self.indexer.search(u'718-555').addCallback(gotResult), self.indexer.search(u'rjones@moddiv').addCallback(gotResult), self.indexer.search(u'divmod.org').addCallback(gotResult), ] ).addCallback(testResults) def test_unicodeSearch(self): return self.indexer.search(u'\N{WHITE SMILING FACE}')
class IndexerAPISearchTestsMixin(IndexerTestsMixin): """ Test ISearchProvider search API on indexer objects """ def setUp(self): """ Make a store, an account/substore, an indexer, and call startService() on the superstore's IService so the batch process interactions that happen in fulltext.py work """ self.dbdir = self.mktemp() self.path = u'index' superstore = store.Store(self.dbdir) loginSystem = LoginSystem(store=superstore) installOn(loginSystem, superstore) account = loginSystem.addAccount(u'testuser', u'example.com', None) substore = account.avatars.open() self.store = substore self.indexer = self.createIndexer() self.svc = IService(superstore) self.svc.startService() # Make sure the indexer is actually available writer = self.openWriteIndex() writer.close() def tearDown(self): """ Stop the service we started in C{setUp} """ return self.svc.stopService() def _indexSomeItems(self): writer = self.openWriteIndex() for i in xrange(5): writer.add(IndexableThing( _documentType=u'thing', _uniqueIdentifier=str(i), _textParts=[u'text'], _keywordParts={})) writer.close() def testIndexerSearching(self): """ Test calling search() on the indexer item directly """ def gotResult(res): self.assertEquals(identifiersFrom(res), range(5)) self._indexSomeItems() return self.indexer.search(u'text').addCallback(gotResult) def testIndexerSearchingCount(self): """ Test calling search() on the indexer item directly, with a count arg """ def gotResult(res): self.assertEquals(identifiersFrom(res), [0]) self._indexSomeItems() return self.indexer.search(u'text', count=1).addCallback(gotResult) def testIndexerSearchingOffset(self): """ Test calling search() on the indexer item directly, with an offset arg """ def gotResult(res): self.assertEquals(identifiersFrom(res), [1, 2, 3, 4]) self._indexSomeItems() return self.indexer.search(u'text', offset=1).addCallback(gotResult) def testIndexerSearchingCountOffset(self): """ Test calling search() on the indexer item directly, with count & offset args """ def gotResult(res): self.assertEquals(identifiersFrom(res), [1, 2, 3]) self._indexSomeItems() return self.indexer.search(u'text', count=3, offset=1) def test_DifficultTokens(self): """ Test searching for fragments of phone numbers, email addresses, and urls. """ writer = self.openWriteIndex() specimens = [u"trevor 718-555-1212", u"bob [email protected]", u"atop http://divmod.org/projects/atop"] for i, txt in enumerate(specimens): writer.add(IndexableThing( _documentType=u'thing', _uniqueIdentifier=str(i), _textParts=[txt], _keywordParts={})) writer.close() def gotResult(res): return identifiersFrom(res) def testResults(results): self.assertEqual(results, [[0], [1], [2], [0], [1], [2]]) return gatherResults( [self.indexer.search(u'718').addCallback(gotResult), self.indexer.search(u'moddiv').addCallback(gotResult), self.indexer.search(u'divmod').addCallback(gotResult), self.indexer.search(u'718-555').addCallback(gotResult), self.indexer.search(u'rjones@moddiv').addCallback(gotResult), self.indexer.search(u'divmod.org').addCallback(gotResult), ] ).addCallback(testResults) def test_unicodeSearch(self): return self.indexer.search(u'\N{WHITE SMILING FACE}')