def test_storeIDAccessor(self): """ Test that the __get__ of the IColumn implementation for storeID works the same as that for normal attributes. """ s = Store() dummy = FullImplementationDummyClass(store=s) self.assertIdentical(s.getItemByID(dummy.storeID), dummy)
def testReferenceDeletion(self): store = Store() referee = Referee(store=store, topSecret=0) dep = DependentReferent(store=store, ref=referee) sid = dep.storeID self.assertIdentical(store.getItemByID(sid), dep) # sanity referee.deleteFromStore() self.assertRaises(KeyError, store.getItemByID, sid)
def test_dummyItemGetItemByID(self): """ Instantiating a dummy item and then getting it by its storeID should upgrade it. """ store = Store() t = nonUpgradedItem(store=store) self.assertEquals(t.__legacy__, True) self.assertRaises(KeyError, store.objectCache.get, t.storeID) t2 = store.getItemByID(t.storeID) self.assertNotIdentical(t, t2) self.assertTrue(isinstance(t2, UpgradedItem))
def test_dummyItemGetItemByID(self): """ Instantiating a dummy item and then getting it by its storeID should upgrade it. """ store = Store() t = nonUpgradedItem(store=store) self.assertEquals(t.__legacy__, True) self.assertFalse(store.objectCache.has(t.storeID)) t2 = store.getItemByID(t.storeID) self.assertNotIdentical(t, t2) self.assertTrue(isinstance(t2, UpgradedItem))
def test_makeService(self): """ L{AxiomaticStart.makeService} returns the L{IService} powerup of the L{Store} at the directory in the options object it is passed. """ dbdir = FilePath(self.mktemp()) store = Store(dbdir) recorder = RecorderService(store=store) self.assertFalse(recorder.started) store.powerUp(recorder, IService) store.close() service = AxiomaticStart.makeService({"dbdir": dbdir, "debug": False}) service.startService() service.stopService() store = Store(dbdir) self.assertTrue(store.getItemByID(recorder.storeID).started)
def test_oneThingMemory(self): """ Ensure that items put into in-memory substores are retrievable. """ s = Store() ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() ssd = SubStored(store=s2, a=u'hello world', b='what, its text') oid = ss.storeID oid2 = ssd.storeID s2.close() self.assertIdentical(s.getItemByID(oid), ss) self.assertIdentical(ss.open(), s2) item = s2.getItemByID(oid2) self.assertEquals(item.a, u'hello world') self.assertEquals(item.b, 'what, its text')
def test_hereTodayGoneTomorrow(self): """ Ensure that substores exist after closing them. """ s = Store() ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() ssd = SubStored(store=s2, a=u'hello world', b='what, its text') oid = ss.storeID oid2 = ssd.storeID s2.close() #the following is done to mimic garbage collection of objects holding #on to substores del s2._openSubStore ss = s.getItemByID(oid) s2 = ss.open() item = s2.getItemByID(oid2) self.assertEquals(item.a, u'hello world') self.assertEquals(item.b, 'what, its text')
def testOneThing(self): topdb = self.mktemp() s = Store(topdb) ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() ssd = SubStored(store=s2, a=u'hello world', b='what, its text') oid = ss.storeID oid2 = ssd.storeID s2.close() s.close() reopens = Store(topdb) reopenss = reopens.getItemByID(oid) reopens2 = reopenss.open() reopenssd = reopens2.getItemByID(oid2) self.assertEquals(reopenssd.a, u'hello world') self.assertEquals(reopenssd.b, 'what, its text')
def testOneThing(self): """ Ensure that items can be inserted into substores and subsequently retrieved. """ topdb = filepath.FilePath(self.mktemp()) s = Store(topdb) ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() ssd = SubStored(store=s2, a=u'hello world', b='what, its text') oid = ss.storeID oid2 = ssd.storeID s2.close() s.close() reopens = Store(topdb) reopenss = reopens.getItemByID(oid) reopens2 = reopenss.open() reopenssd = reopens2.getItemByID(oid2) self.assertEquals(reopenssd.a, u'hello world') self.assertEquals(reopenssd.b, 'what, its text')
def testTimestampDefault(self): s = Store() sid = DatedThing(store=s).storeID self.assertEqual(s.getItemByID(sid).date, someRandomDate)
# -*- test-case-name: axiom.test.test_xatop.ProcessConcurrencyTestCase -*- # this file is in support of the named test case import sys from axiom.store import Store from twisted.python import filepath # Open the store so that we get the bad version of the schema s = Store(filepath.FilePath(sys.argv[1])) # Alert our parent that we did that sys.stdout.write("1") sys.stdout.flush() # Grab the storeID we are supposed to be reading sids = sys.stdin.readline() sid = int(sids) # load the item we were told to - this should force a schema reload s.getItemByID(sid) # let our parent process know that we loaded it successfully sys.stdout.write("2") sys.stdout.flush() # then terminate cleanly
class BackwardsCompatibilitySchedTests(object): """ L{Scheduler} and L{SubScheduler} are going to be removed. In the mean time, if someone gets their hands on one and tries to do something supported to it, it should be as if they were doing it to the suitable replacement, L{_SiteScheduler} or L{_UserScheduler}. This mixin provides tests for that behavior, as well as for the deprecations of L{Scheduler} and L{SubScheduler}. @ivar schedulerType: L{Scheduler} or L{SubScheduler}, whichever is to be tested. """ def setUp(self): """ Create a store with an instance of C{self.schedulerType} in it. """ self.store = Store() self.oldScheduler = self.schedulerType(store=self.store) warnings = self.flushWarnings([self.setUp]) self.assertEquals(len(warnings), 1) self.assertEquals(warnings[0]['category'], PendingDeprecationWarning) self.assertEquals( warnings[0]['message'], self.schedulerType.__name__ + " is deprecated since Axiom 0.5.32. " "Just adapt stores to IScheduler.") self.scheduler = IScheduler(self.store) def _checkSynonym(self, name): # Whatever the value of the attribute is on the _SiteScheduler or # _UserScheduler instance, that's what it should be on the Scheduler # or SubScheduler Item. foo = object() setattr(self.scheduler, name, foo) self.assertIdentical(getattr(self.oldScheduler, name), foo) # And rebinding the attribute on the (Sub)Scheduler Item should rebind it on # the _SiteScheduler instance. bar = object() setattr(self.oldScheduler, name, bar) self.assertIdentical(getattr(self.scheduler, name), bar) def test_now(self): """ L{Scheduler.now} is a synonym for L{_SiteScheduler.now}. """ self._checkSynonym("now") def test_tick(self): """ L{Scheduler.tick} is a synonym for L{_SiteScheduler.tick}. """ self._checkSynonym("tick") def test_schedule(self): """ L{Scheduler.schedule} is a synonym for L{_SiteScheduler.schedule}. """ self._checkSynonym("schedule") def test_scheduledTimes(self): """ L{Scheduler.scheduledTimes} is a synonym for L{_SiteScheduler.scheduledTimes}. """ self._checkSynonym("scheduledTimes") def test_unscheduleAll(self): """ L{Scheduler.unscheduleAll} is a synonym for L{_SiteScheduler.unscheduleAll}. """ self._checkSynonym("unscheduleAll") def test_reschedule(self): """ L{Scheduler.reschedule} is a synonym for L{_SiteScheduler.reschedule}. """ self._checkSynonym("reschedule") def test_deprecated(self): """ Loading an existing L{Scheduler} from a L{Store} emits a deprecation warning. """ storeID = self.oldScheduler.storeID del self.oldScheduler gc.collect() # Just load the scheduler, we don't need to use it for anything. self.store.getItemByID(storeID) warnings = self.flushWarnings([self.test_deprecated]) self.assertEquals(len(warnings), 1) self.assertEquals(warnings[0]['category'], PendingDeprecationWarning) self.assertEquals( warnings[0]['message'], self.schedulerType.__name__ + " is deprecated since Axiom 0.5.32. " "Just adapt stores to IScheduler.")
# -*- test-case-name: axiom.test.test_xatop.ProcessConcurrencyTestCase -*- # this file is in support of the named test case import sys from axiom.store import Store # Open the store so that we get the bad version of the schema s = Store(sys.argv[1]) # Alert our parent that we did that sys.stdout.write("1") sys.stdout.flush() # Grab the storeID we are supposed to be reading sids = sys.stdin.readline() sid = int(sids) # load the item we were told to - this should force a schema reload s.getItemByID(sid) # let our parent process know that we loaded it successfully sys.stdout.write("2") sys.stdout.flush() # then terminate cleanly
class SubStoreMigrationTestCase(unittest.TestCase): IMPORTANT_VALUE = 159 localpart = 'testuser' domain = 'example.com' def setUp(self): self.dbdir = FilePath(self.mktemp()) self.store = Store(self.dbdir) self.ls = userbase.LoginSystem(store=self.store) self.scheduler = IScheduler(self.store) self.account = self.ls.addAccount( self.localpart, self.domain, 'PASSWORD') self.accountStore = self.account.avatars.open() self.ss = IScheduler(self.accountStore) self.origdir = self.accountStore.dbdir self.destdir = FilePath(self.mktemp()) def test_extraction(self): """ Ensure that user store extraction works correctly, particularly in the presence of timed events. """ thing = ThingThatMovesAround(store=self.accountStore, superValue=self.IMPORTANT_VALUE) self.ss.schedule(thing, Time() + datetime.timedelta(days=1)) self.test_noTimedEventsExtraction() def test_noTimedEventsExtraction(self): """ Ensure that user store extraction works correctly if no timed events are present. """ userbase.extractUserStore(self.account, self.destdir) self.assertEqual( self.ls.accountByAddress(self.localpart, self.domain), None) self.assertFalse(list(self.store.query(SubStore, SubStore.storepath == self.origdir))) self.origdir.restat(False) self.assertFalse(self.origdir.exists()) self.assertFalse(list(self.store.query(_SubSchedulerParentHook))) def test_noTimedEventsInsertion(self): """ Test that inserting a user store succeeds if it contains no timed events. """ self.test_noTimedEventsExtraction() self._testInsertion() def test_insertion(self, _deleteDomainDirectory=False): """ Test that inserting a user store succeeds and that the right items are placed in the site store as a result. """ self.test_extraction() self._testInsertion(_deleteDomainDirectory) insertedStore = self.ls.accountByAddress(self.localpart, self.domain).avatars.open() self.assertEqual( insertedStore.findUnique(ThingThatMovesAround).superValue, self.IMPORTANT_VALUE) siteStoreSubRef = self.store.getItemByID(insertedStore.idInParent) ssph = self.store.findUnique(_SubSchedulerParentHook, _SubSchedulerParentHook.subStore == siteStoreSubRef, default=None) self.assertTrue(ssph) self.assertTrue(self.store.findUnique(TimedEvent, TimedEvent.runnable == ssph)) def _testInsertion(self, _deleteDomainDirectory=False): """ Helper method for inserting a user store. """ if _deleteDomainDirectory: self.store.filesdir.child('account').child(self.domain).remove() userbase.insertUserStore(self.store, self.destdir) def test_insertionWithNoDomainDirectory(self): """ Test that inserting a user store succeeds even if it is the first one in that domain to be inserted. """ self.test_insertion(True)
def testTimestampNow(self): s = Store() sid = CreationDatedThing(store=s).storeID self.assertTrue( (Time().asDatetime() - s.getItemByID(sid).creationDate.asDatetime()).seconds < 10)