def setUp(self): """ Create an account and log in using it. """ IntegrationTestsMixin.setUp(self) # Make an account to be already logged in. self.userAccount = self.login.addAccount(self.username, self.domain, u'password', internal=True) self.userStore = self.userAccount.avatars.open() # Make a product that includes PrivateApplication. This is probably # the minimum requirement for web access. web = Product(store=self.store, types=[qual(PrivateApplication)]) # Give it to Alice. web.installProductOn(self.userStore) # Log in to the web as Alice. login = getWithSession( self.factory, 3, '/__login__?username=%s@%s&password=%s' % (self.username.encode('ascii'), self.domain.encode('ascii'), 'password'), {'host': self.domain.encode('ascii')}) def loggedIn(request): self.cookies = request.cookies login.addCallback(loggedIn) return login
def doRendering(self, fragmentClass): """ Verify that the given fragment class will render without raising an exception. """ siteStore = Store() loginSystem = LoginSystem(store=siteStore) installOn(loginSystem, siteStore) p = Product(store=siteStore, types=["xmantissa.webadmin.LocalUserBrowser", "xmantissa.signup.SignupConfiguration"]) account = loginSystem.addAccount(u'testuser', u'localhost', None) p.installProductOn(account.avatars.open()) f = fragmentClass(None, u'testuser', account) p = LivePage( docFactory=stan( html[ head(render=directive('liveglue')), body(render=lambda ctx, data: f)])) f.setFragmentParent(p) ctx = WovenContext() req = FakeRequest() ctx.remember(req, IRequest) d = p.renderHTTP(ctx) def rendered(ign): p.action_close(None) d.addCallback(rendered) return d
def setUp(self): self.s = Store() self.product = Product() self.product.types = [ n.decode('ascii') for n in [qual(Foo), qual(Baz)] ] self.product.installProductOn(self.s) self.i = self.s.findUnique(Installation)
def test_product(self): self.product = Product(store=self.siteStore) self.product.types = [ n.decode('ascii') for n in [qual(Foo), qual(Baz)] ] self.product.installProductOn(self.userStore) i = self.userStore.findUnique(Installation) self.assertEqual(i.types, self.product.types)
def createFreeSignup(self, itemClass, url=u'signup', prompt=u'Sign Up!'): """ A utility method to ensure that the same arguments are always used to create signup mechanisms, since these are the arguments that are going to be coming from the admin form. """ product = Product(store=self.store, types=[]) return self.sc.createSignup(u'testuser@localhost', itemClass, {'prefixURL': url}, product, u'Blank Email Template', prompt)
def test_authenticatedUserVirtualHostDefaultShare(self): """ A request by an authenticated user for I{/} on a subdomain of of the website's is responded to in the same way as the same request made by an anonymous user. """ # Make an account as which to authenticate. username = u'bob' bobAccount = self.login.addAccount(username, self.domain, u'password', internal=True) bobStore = bobAccount.avatars.open() # Make a product that includes PrivateApplication. This supposes that # viewing user-subdomain virtual hosting is the responsibility of # PrivateApplication. web = Product(store=self.store, types=[qual(PrivateApplication)]) # Give it to Bob. web.installProductOn(bobStore) # Make something the default share. addDefaultShareID(self.userStore, self.share.shareID, 0) # Log in through the web as Bob. cookies = {} login = getWithSession( self.factory, 3, '/__login__?username=%s@%s&password=%s' % (username.encode('ascii'), self.domain.encode('ascii'), 'password'), {'host': self.domain.encode('ascii')}) def loggedIn(request): # Get the share page as the authenticated user. return getResource( self.factory, '/', headers={'host': self.virtualHost.encode('ascii')}, cookies=request.cookies) login.addCallback(loggedIn) def rendered(request): # Make sure we're really authenticated. self.assertIn(username.encode('ascii'), request.accumulator) # Make sure the shared thing is there. self.assertIn(self.sharedContent.encode('ascii'), request.accumulator) login.addCallback(rendered) return login
def setUp(self): self.siteStore = Store(filesdir=self.mktemp()) Mantissa().installSite(self.siteStore, u'example.com', u"", False) self.loginSystem = self.siteStore.findUnique(LoginSystem) userAccount = self.loginSystem.addAccount(u'alice', u'example.com', u'password') self.userStore = userAccount.avatars.open() product = Product( store=self.siteStore, types=[qual(hyperbola_model.HyperbolaPublicPresence)]) product.installProductOn(self.userStore) self.publicPresence = self.userStore.findUnique( hyperbola_model.HyperbolaPublicPresence) self.me = Role(store=self.userStore, externalID=u'*****@*****.**', description=u'foobar') self.you = Role(store=self.userStore, externalID=u'*****@*****.**', description=u'rad yo') blog = self.blog = hyperblurb.Blurb(store=self.userStore, title=u"Hello World", body=u"Hello World!~!!", author=self.me, hits=0, dateCreated=Time(), dateLastEdited=Time(), flavor=hyperblurb.FLAVOR.BLOG) blog.permitChildren(self.me, hyperblurb.FLAVOR.BLOG_POST, ihyperbola.ICommentable) blog.permitChildren(self.me, hyperblurb.FLAVOR.BLOG_COMMENT, ihyperbola.ICommentable) blog.permitChildren(self.you, hyperblurb.FLAVOR.BLOG_POST, ihyperbola.ICommentable) blog.permitChildren(self.you, hyperblurb.FLAVOR.BLOG_COMMENT, ihyperbola.ICommentable) shareItem(blog, getEveryoneRole(self.userStore), shareID=u'blog', interfaces=[ihyperbola.IViewable])
def setUpMailStuff(self, extraPowerups=(), dbdir=None, generateCert=False): filesdir = None if dbdir is None: filesdir = self.mktemp() self.siteStore = store.Store(dbdir=dbdir, filesdir=filesdir) Mantissa().installSite(self.siteStore, u"example.com", u"", generateCert) IOfferingTechnician(self.siteStore).installOffering(quotientOffering) loginSystem = self.siteStore.findUnique(LoginSystem) account = loginSystem.addAccount(u'testuser', u'example.com', None) self.substore = account.avatars.open() product = Product( store=self.siteStore, types=[qual(Inbox)] + map(qual, extraPowerups)) product.installProductOn(self.substore) self.deliveryAgent = self.substore.findUnique(DeliveryAgent) return self.createMIMEReceiver()
def createSignupAndSignup(self, powerups): """ Signup via a newly-created signup, using a unique email address. @return: substore, which will be endowed with C{product} """ product = Product(store=self.store, types=[qual(p) for (name, desc, p) in powerups]) qsignup = self.signupConfig.createSignup(u'admin@localhost', freeTicket.itemClass, {'prefixURL': u'signup'}, product, u'', u'') booth = qsignup.booth localpart = unicode(str(time()), 'ascii') ticket = booth.createTicket(booth, localpart + '@localhost', product) ticket.claim() return self.loginSystem.accountByAddress(localpart, u'localhost').avatars.open()
def _setUpStore(self): """ Set up a store, install a L{HyperbolaPublicPresence} and its dependencies, and create a role """ self.siteStore = Store(filesdir=self.mktemp()) Mantissa().installSite(self.siteStore, u"localhost", u"", generateCert=False) # Make it standard so there's no port number in the generated URL. # This kind of sucks. I don't want people assuming SSLPorts are # created by Mantissa().installSite(). Oh right, I should add a better # API for initializing a Mantissa server. -exarkun site = self.siteStore.findUnique(SiteConfiguration) ssls = list(site.store.query(SSLPort)) ssls[0].portNumber = 443 self.loginSystem = self.siteStore.findUnique(LoginSystem) product = Product(store=self.siteStore, types=[qual(HyperbolaPublicPresence)]) acct = self.loginSystem.addAccount(u'user', u'localhost', u'asdf', internal=True) self.userStore = acct.avatars.open() product.installProductOn(self.userStore) self.publicPresence = self.userStore.findUnique( HyperbolaPublicPresence) self.role = sharing.Role(store=self.userStore, externalID=u'foo@host', description=u'foo')