def setUp(self): """ Set up stores and an offering. """ store = Store(dbdir=self.mktemp()) appStore1 = SubStore.createNew(store, ("app", "test1.axiom")) appStore2 = SubStore.createNew(store, ("app", "test2.axiom")) self.firstOffering = Offering(u'first offering', None, None, None, None, None, []) firstInstalledOffering = InstalledOffering( store=store, application=appStore1, offeringName=self.firstOffering.name) ss1 = appStore1.open() self.installApp(ss1) # (bypass Item.__setattr__) object.__setattr__( firstInstalledOffering, 'getOffering', lambda: self.firstOffering) secondOffering = Offering(u'second offering', None, None, None, None, None, []) secondInstalledOffering = InstalledOffering( store=store, application=appStore2, offeringName=secondOffering.name) # (bypass Item.__setattr__) object.__setattr__(secondInstalledOffering, 'getOffering', lambda: secondOffering) self.fragment = _OfferingsFragment(FrontPage(store=store))
def setUp(self): """ Set up stores and an offering. """ store = Store(dbdir=self.mktemp()) appStore1 = SubStore.createNew(store, ("app", "test1.axiom")) appStore2 = SubStore.createNew(store, ("app", "test2.axiom")) self.firstOffering = Offering(u'first offering', None, None, None, None, None, []) firstInstalledOffering = InstalledOffering( store=store, application=appStore1, offeringName=self.firstOffering.name) ss1 = appStore1.open() self.installApp(ss1) # (bypass Item.__setattr__) object.__setattr__(firstInstalledOffering, 'getOffering', lambda: self.firstOffering) secondOffering = Offering(u'second offering', None, None, None, None, None, []) secondInstalledOffering = InstalledOffering( store=store, application=appStore2, offeringName=secondOffering.name) # (bypass Item.__setattr__) object.__setattr__(secondInstalledOffering, 'getOffering', lambda: secondOffering) self.fragment = _OfferingsFragment(FrontPage(store=store))
def test_upgradeStoreRecursing(self): """ L{Upgrade} upgrades L{Item}s in substores. """ choose(oldapp) ss1 = SubStore.createNew(self.store, ['a']) ss2 = SubStore.createNew(self.store, ['b']) swordIDs = [ (ss1.storeID, oldapp.Sword(store=ss1.open(), name='foo').storeID), (ss2.storeID, oldapp.Sword(store=ss2.open(), name='bar').storeID)] del ss1, ss2 self.store.close() choose(deleteswordapp) self.store = store.Store(self.dbdir) cmd = Upgrade() cmd.parent = CommandStub(self.store, 'upgrade') callWithStdoutRedirect(cmd.parseOptions, []) for (ssid, swordID) in swordIDs: self.assertRaises( KeyError, self.store.getItemByID(ssid).open().getItemByID, swordID)
def test_upgradeStoreRecursing(self): """ L{Upgrade} upgrades L{Item}s in substores. """ choose(oldapp) ss1 = SubStore.createNew(self.store, ['a']) ss2 = SubStore.createNew(self.store, ['b']) swordIDs = [(ss1.storeID, oldapp.Sword(store=ss1.open(), name='foo').storeID), (ss2.storeID, oldapp.Sword(store=ss2.open(), name='bar').storeID)] del ss1, ss2 self.store.close() choose(deleteswordapp) self.store = store.Store(self.dbdir) cmd = Upgrade() cmd.parent = CommandStub(self.store, 'upgrade') callWithStdoutRedirect(cmd.parseOptions, []) for (ssid, swordID) in swordIDs: self.assertRaises(KeyError, self.store.getItemByID(ssid).open().getItemByID, swordID)
def testAvatarStoreState(self): """ You can only pass an 'avatars' argument if it doesn't already have an account in it. Some accounts want to have their stores in slightly odd places (like offering.py) but you can't have two accounts added which both point to the same store. """ dbdir = FilePath(self.mktemp()) s = Store(dbdir) ls = userbase.LoginSystem(store=s) dependency.installOn(ls, s) acc = ls.addAccount('alice', 'dom.ain', 'password') # this is allowed, if weird unrelatedAccount = ls.addAccount( 'elseice', 'dom.ain', 'password', avatars=SubStore.createNew(s, ('crazy', 'what'))) # this is not allowed. self.assertRaises(errors.DuplicateUniqueItem, ls.addAccount, 'bob', 'ain.dom', 'xpassword', avatars=acc.avatars) # Make sure that our stupid call to addAccount did not corrupt # anything, because we are stupid self.assertEqual(acc.avatars.open().query(userbase.LoginAccount).count(), 1)
def test_requiresFromSite(self): """ The value of a L{axiom.dependency.requiresFromSite} descriptor ought to be the powerup on the site for the instance it describes. """ dependency.installOn(RealGrid(store=self.store), self.store) substore = SubStore.createNew(self.store, ['sub']).open() self.assertEquals(PowerStrip(store=substore).draw(1), REAL_POWER)
def setUp(self): self.spath = filepath.FilePath(self.mktemp() + ".axiom") self.store = Store(self.spath) self.substoreitem = SubStore.createNew(self.store, ["sub.axiom"]) self.substore = self.substoreitem.open() # Not available yet. self.substore.attachToParent()
def test_subSchedule(self): """ The same as test_schedule, except using a subscheduler. """ subst = SubStore.createNew(self.store, ['scheduler_test']) substore = subst.open() subscheduler = IScheduler(substore) return self._testSchedule(subscheduler)
def setUp(self): """ Set up the tests by creating a store and a substore and opening them both. """ self.topdb = topdb = Store(filepath.FilePath(self.mktemp())) self.ssitem = ssitem = SubStore.createNew( topdb, ["dontstartme", "really"]) self.ss = ssitem.open() self.serviceStarted = False
def test_requiresFromSiteNoDefault(self): """ The default function shouldn't be needed or invoked if its value isn't going to be used. """ dependency.installOn(RealGrid(store=self.store), self.store) substore = SubStore.createNew(self.store, ['sub']).open() self.assertEquals( SpecifiedBadDefaults(store=substore).pump(), REAL_POWER)
def test_requiresFromSiteNoDefault(self): """ The default function shouldn't be needed or invoked if its value isn't going to be used. """ dependency.installOn(RealGrid(store=self.store), self.store) substore = SubStore.createNew(self.store, ['sub']).open() self.assertEquals(SpecifiedBadDefaults(store=substore).pump(), REAL_POWER)
def setUp(self): """ Set up the tests by creating a store and a substore and opening them both. """ self.topdb = topdb = Store(filepath.FilePath(self.mktemp())) self.ssitem = ssitem = SubStore.createNew(topdb, ["dontstartme", "really"]) self.ss = ssitem.open() self.serviceStarted = False
def openStore(self): self.currentTopStore = store.Store(self.topdbdir) if self.subStoreID is not None: self.currentSubStore = self.currentTopStore.getItemByID(self.subStoreID).open() else: ss = SubStore.createNew(self.currentTopStore, ['sub']) self.subStoreID = ss.storeID self.currentSubStore = ss.open() return self.currentSubStore
def test_requiresFromSiteDefault(self): """ The value of a L{axiom.dependency.requiresFromSite} descriptor on an item in a user store ought to be the result of invoking its default factory parameter. """ substore = SubStore.createNew(self.store, ['sub']).open() ps = PowerStrip(store=substore) self.assertEquals(ps.draw(1), FAKE_POWER) self.assertEquals(ps.grid.siteStore, self.store)
def test_inheritParentConfiguration(self): """ Substores use the debug and journal configuration of the parent store. """ filesdir = filepath.FilePath(self.mktemp()) s = Store(filesdir=filesdir, debug=True, journalMode=u'MEMORY') ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() self.assertEqual(s2.debug, True) self.assertEqual(s2.journalMode, u'MEMORY')
def openStore(self): self.currentTopStore = store.Store(self.topdbdir) if self.subStoreID is not None: self.currentSubStore = self.currentTopStore.getItemByID( self.subStoreID).open() else: ss = SubStore.createNew(self.currentTopStore, ['sub']) self.subStoreID = ss.storeID self.currentSubStore = ss.open() return self.currentSubStore
def createDatabase(s): """ Create a store which contains a substore-service-starter item powered up for IService, and a substore, which contains a service that should not be started after the upgrader runs. """ ssi = SubStore.createNew(s, ["sub", "test"]) ss = ssi.open() ds = DummyService(store=ss) ss.powerUp(ds, IService) ssss = SubStoreStartupService(store=s).installOn(s)
def test_listOffering(self): """ Mantissa offerings are added as users with a 'username' but no domain. Check that the 'list' command prints these correctly. """ name = 'offering-name' self.userbase('install') realm = IRealm(self.store) substoreItem = SubStore.createNew(self.store, ('app', name)) realm.addAccount(name, None, None, internal=True, avatars=substoreItem) output = self.userbase('list') self.assertEquals(output, [name])
def test_memorySubstoreFile(self): """ In-memory substores whose stores have file directories should be able to create files. """ filesdir = filepath.FilePath(self.mktemp()) s = Store(filesdir=filesdir) ss = SubStore.createNew(s, ['account', '*****@*****.**']) s2 = ss.open() f = s2.newFile("test.txt") f.write("yay") f.close() self.assertEqual(open(f.finalpath.path).read(), "yay")
def test_requiresFromSiteUnspecifiedException(self): """ If a default factory function isn't supplied, an L{UnsatisfiedRequirement}, which should be a subtype of L{AttributeError}, should be raised when the descriptor is retrieved. """ lung = IronLung(store=self.store) siteLung = IronLung( store=SubStore.createNew(self.store, ['sub']).open()) self.assertRaises(UnsatisfiedRequirement, lambda : lung.grid) self.assertRaises(UnsatisfiedRequirement, lambda : siteLung.grid) default = object() self.assertIdentical(getattr(lung, 'grid', default), default)
def test_requiresFromSiteUnspecifiedException(self): """ If a default factory function isn't supplied, an L{UnsatisfiedRequirement}, which should be a subtype of L{AttributeError}, should be raised when the descriptor is retrieved. """ lung = IronLung(store=self.store) siteLung = IronLung( store=SubStore.createNew(self.store, ['sub']).open()) self.assertRaises(UnsatisfiedRequirement, lambda: lung.grid) self.assertRaises(UnsatisfiedRequirement, lambda: siteLung.grid) default = object() self.assertIdentical(getattr(lung, 'grid', default), default)
def test_listOffering(self): """ Mantissa offerings are added as users with a 'username' but no domain. Check that the 'list' command prints these correctly. """ name = 'offering-name' self.userbase('install') realm = IRealm(self.store) substoreItem = SubStore.createNew(self.store, ('app', name)) realm.addAccount(name, None, None, internal=True, avatars=substoreItem) output = self.userbase('list') self.assertEqual(output, [name])
def insertUserStore(siteStore, userStorePath): """ Move the SubStore at the indicated location into the given site store's directory and then hook it up to the site store's authentication database. @type siteStore: C{Store} @type userStorePath: C{FilePath} """ # The following may, but does not need to be in a transaction, because it # is merely an attempt to guess a reasonable filesystem name to use for # this avatar. The user store being operated on is expected to be used # exclusively by this process. ls = siteStore.findUnique(LoginSystem) unattachedSubStore = Store(userStorePath) for lm in unattachedSubStore.query( LoginMethod, LoginMethod.account == unattachedSubStore.findUnique(LoginAccount), sort=LoginMethod.internal.descending): if ls.accountByAddress(lm.localpart, lm.domain) is None: localpart, domain = lm.localpart, lm.domain break else: raise AllNamesConflict() unattachedSubStore.close() insertLocation = siteStore.newFilePath('account', domain, localpart + '.axiom') insertParentLoc = insertLocation.parent() if not insertParentLoc.exists(): insertParentLoc.makedirs() if insertLocation.exists(): raise DatabaseDirectoryConflict() userStorePath.moveTo(insertLocation) ss = SubStore(store=siteStore, storepath=insertLocation) attachedStore = ss.open() # migrateUp() manages its own transactions because it interacts with two # different stores. attachedStore.findUnique(LoginAccount).migrateUp()
def test_navPage(self): """ Test that L{webapp.GenericNavigationLivePage} supports theming of Athena's unsupported-browser page based on an L{ITemplateNameResolver} installed on the viewing user's store. """ subStore = SubStore.createNew(self.siteStore, ['athena', 'unsupported']).open() stp = StubThemeProvider(store=subStore) installOn(stp, subStore) p = GenericNavigationAthenaPage( stp, LiveFragment(), _PageComponents([], None, None, None, None), None) self.assertEqual(p.renderUnsupported(None), flatten(CUSTOM_MSG))
def insertUserStore(siteStore, userStorePath): """ Move the SubStore at the indicated location into the given site store's directory and then hook it up to the site store's authentication database. @type siteStore: C{Store} @type userStorePath: C{FilePath} """ # The following may, but does not need to be in a transaction, because it # is merely an attempt to guess a reasonable filesystem name to use for # this avatar. The user store being operated on is expected to be used # exclusively by this process. ls = siteStore.findUnique(LoginSystem) unattachedSubStore = Store(userStorePath) for lm in unattachedSubStore.query(LoginMethod, LoginMethod.account == unattachedSubStore.findUnique(LoginAccount), sort=LoginMethod.internal.descending): if ls.accountByAddress(lm.localpart, lm.domain) is None: localpart, domain = lm.localpart, lm.domain break else: raise AllNamesConflict() unattachedSubStore.close() insertLocation = siteStore.newFilePath('account', domain, localpart + '.axiom') insertParentLoc = insertLocation.parent() if not insertParentLoc.exists(): insertParentLoc.makedirs() if insertLocation.exists(): raise DatabaseDirectoryConflict() userStorePath.moveTo(insertLocation) ss = SubStore(store=siteStore, storepath=insertLocation) attachedStore = ss.open() # migrateUp() manages its own transactions because it interacts with two # different stores. attachedStore.findUnique(LoginAccount).migrateUp()
def setUp(self): """ Create a site store for the substore which will contain the IScheduler being tested. Start its IService so any scheduled events will run. """ self.storePath = filepath.FilePath(self.mktemp()) self.siteStore = Store(self.storePath) super(SubSchedulerTests, self).setUp() substoreItem = SubStore.createNew(self.siteStore, ['scheduler_test']) self.substore = substoreItem.open() self.scheduler = scheduler = IScheduler(self.substore) self.stubTime(scheduler) self.store = self.substore
def setUp(self): self.clock = Clock() self.dbdir = filepath.FilePath(self.mktemp()) self.store = Store(self.dbdir) self.substoreItem = SubStore.createNew(self.store, ['sub']) self.substore = self.substoreItem.open() self.scheduler = IScheduler(self.store) self.subscheduler = IScheduler(self.substore) self.scheduler.callLater = self.clock.callLater self.scheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds()) self.subscheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds()) IService(self.store).startService()
def test_navPage(self): """ Test that L{webapp.GenericNavigationAthenaPage} supports theming of Athena's unsupported-browser page based on an L{ITemplateNameResolver} installed on the viewing user's store. """ subStore = SubStore.createNew( self.siteStore, ['athena', 'unsupported']).open() stp = StubThemeProvider(store=subStore) installOn(stp, subStore) p = GenericNavigationAthenaPage(stp, LiveFragment(), _PageComponents([], None, None, None, None), None) self.assertEqual(p.renderUnsupported(None), flatten(CUSTOM_MSG))
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 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 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): """ 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 createDatabase(store): sub = SubStore.createNew(store, ["substore"]).open() installOn(SubScheduler(store=sub), sub)
def makeAvatars(self, domain, username): return SubStore.createNew(self.store, ('account', domain, username + '.axiom'))
def setUp(self): store = Store() ss = SubStore.createNew(store, ['test']).open() self.pa = PrivateApplication(store=ss) installOn(self.pa, ss) self.webViewer = IWebViewer(ss)
def siteStoreTxn(): Mantissa().installSite(self.siteStore, u"localhost", u"", False) self.userStore = SubStore.createNew( self.siteStore, ['child', 'lookup']).open()
def createDatabase(store): scheduler = Scheduler(store=store) installOn(scheduler, store) installOn( _SubSchedulerParentHook(store=store, loginAccount=SubStore(store=store)), store)
def testSubScheduler(self): substoreItem = SubStore.createNew(self.store, ['scheduler_test']) substore = substoreItem.open() SubScheduler(store=substore).installOn(substore) return self._doTestScheduler(substore)