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 test_schedulerStartsWhenServiceStarts(self): """ Test that IScheduler(store).startService() gets called whenever IService(store).startService() is called. """ service = IService(self.store) service.startService() scheduler = service.getServiceNamed(SITE_SCHEDULER) self.assertTrue(scheduler.running)
def main(*config_file_paths): # Setup logging root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) root_logger.addHandler(logging.handlers.SysLogHandler('/dev/log')) application = make_application(*config_file_paths) service = IService(application) service.startService() reactor.addSystemEventTrigger('before', 'shutdown', service.stopService) reactor.run()
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)
def testNoResults(self): """ Test that the string 'no results' appears in the flattened HTML response to a search on an empty index """ service = IService(self.indexer.store.parent) service.startService() def gotSearchResult((fragment,)): deferred = renderLivePage(ThemedFragmentWrapper(fragment)) def rendered(res): self.assertIn('no results', res.lower()) return service.stopService() return deferred.addCallback(rendered) s = self.indexer.store deferred = ixmantissa.ISearchAggregator(s).search(u'hi', {}, None, None) return deferred.addCallback(gotSearchResult)
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 startStoreService(self): """ Start the Store Service. """ service = IService(self.store) service.startService()
def startStoreService(self): svc = IService(self.currentTopStore) svc.getServiceNamed("Batch Processing Controller").disownServiceParent() svc.startService()
def startStoreService(self): svc = IService(self.currentTopStore) svc.getServiceNamed( "Batch Processing Controller").disownServiceParent() svc.startService()
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}')
from tessw import VERSION_STRING from tessw.application import application from tessw.logger import sysLogInfo # ---------------- # Module constants # ---------------- # ----------------------- # Module global variables # ----------------------- log = Logger(namespace='global') # ------------------------ # Module Utility Functions # ------------------------ # ==== # Main # ==== serv = IService(application) log.info('{program} {version}', program=serv.name, version=VERSION_STRING) sysLogInfo("Starting {0} {1} Linux service".format(serv.name, VERSION_STRING)) serv.startService() reactor.run() sysLogInfo("{0} {1} Linux service stopped".format(serv.name, VERSION_STRING))
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}')