コード例 #1
0
ファイル: test_web.py プロジェクト: rcarmo/divmod.org
    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
コード例 #2
0
class InstallationTest(TestCase):
    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_install(self):
        """
        Ensure that Installation installs instances of the types it is created with.
        """
        self.assertNotEqual(IFoo(self.s, None), None)
        self.assertNotEqual(IBaz(self.s, None), None)
        self.assertEqual(list(self.i.items),
                         [self.s.findUnique(t) for t in [Foo, Baz]])

    def test_uninstall(self):
        """
        Ensure that Installation properly uninstalls all of the items it controls.
        """
        self.product.removeProductFrom(self.s)
        self.assertEqual(IFoo(self.s, None), None)
        self.assertEqual(IBaz(self.s, None), None)
        self.assertEqual(list(self.s.query(Installation)), [])
コード例 #3
0
class ProductTest(TestCase):
    def setUp(self):
        """
        Create a pseudo site store and a pseudo user store in it.
        """
        self.siteStore = Store()
        self.userStore = Store()
        self.userStore.parent = self.siteStore

    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 test_createProduct(self):
        """
        Verify that L{ProductConfiguration.createProduct} creates a
        correctly configured L{Product} and returns it.
        """
        conf = ProductConfiguration(store=self.userStore)
        product = conf.createProduct([Foo, Baz])
        self.assertEqual(product.types, [qual(Foo), qual(Baz)])
コード例 #4
0
ファイル: test_admin.py プロジェクト: fusionapp/mantissa
    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
コード例 #5
0
    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
コード例 #6
0
ファイル: util.py プロジェクト: pombredanne/hyperbola
    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')
コード例 #7
0
ファイル: test_product.py プロジェクト: twisted/mantissa
class ProductTest(TestCase):
    def setUp(self):
        """
        Create a pseudo site store and a pseudo user store in it.
        """
        self.siteStore = Store()
        self.userStore = Store()
        self.userStore.parent = self.siteStore


    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 test_createProduct(self):
        """
        Verify that L{ProductConfiguration.createProduct} creates a
        correctly configured L{Product} and returns it.
        """
        conf = ProductConfiguration(store=self.userStore)
        product = conf.createProduct([Foo, Baz])
        self.assertEqual(product.types, [qual(Foo), qual(Baz)])
コード例 #8
0
ファイル: test_product.py プロジェクト: twisted/mantissa
class InstallationTest(TestCase):

    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_install(self):
        """
        Ensure that Installation installs instances of the types it is created with.
        """
        self.assertNotEqual(IFoo(self.s, None), None)
        self.assertNotEqual(IBaz(self.s, None), None)
        self.assertEqual(list(self.i.items), [self.s.findUnique(t) for t in [Foo, Baz]])


    def test_uninstall(self):
        """
        Ensure that Installation properly uninstalls all of the items it controls.
        """
        self.product.removeProductFrom(self.s)
        self.assertEqual(IFoo(self.s, None), None)
        self.assertEqual(IBaz(self.s, None), None)
        self.assertEqual(list(self.s.query(Installation)), [])
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
    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
コード例 #12
0
ファイル: test_web.py プロジェクト: rcarmo/divmod.org
    def test_authenticatedUserVirtualHost(self):
        """
        A request by an authenticated user for I{/shareid} on a subdomain 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)

        # 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 from the virtual host as the authenticated
            # user.
            return getResource(
                self.factory,
                "/" + self.share.shareID.encode("ascii"),
                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
コード例 #13
0
ファイル: test_product.py プロジェクト: twisted/mantissa
 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)
コード例 #14
0
    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])
コード例 #15
0
ファイル: util.py プロジェクト: Aeroglyphic/twisted-quotient
    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()
コード例 #16
0
ファイル: test_signup.py プロジェクト: jonathanj/mantissa
    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)
コード例 #17
0
ファイル: test_admin.py プロジェクト: jonathanj/mantissa
    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
コード例 #18
0
ファイル: util.py プロジェクト: DalavanCloud/hyperbola
    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')
コード例 #19
0
    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])
コード例 #20
0
    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()
コード例 #21
0
ファイル: test_product.py プロジェクト: twisted/mantissa
 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)