Example #1
0
    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 createDatabase(s):
    ls = LoginSystem(store=s)
    ls.installOn(s)
    acc = ls.addAccount(*CREDENTIALS)
    ss = acc.avatars.open()
    gph = GarbageProtocolHandler(store=ss, garbage=GARBAGE_LEVEL)
    gph.installOn(ss)
Example #3
0
def createDatabase(s):
    ls = LoginSystem(store=s)
    ls.installOn(s)
    acc = ls.addAccount(u"test", u"example.com", "asdf")
    ss = acc.avatars.open()
    gph = GarbageProtocolHandler(store=ss, garbage=7)
    gph.installOn(ss)
Example #4
0
    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
Example #5
0
    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
Example #6
0
def createDatabase(s):
    ls = LoginSystem(store=s)
    ls.installOn(s)
    acc = ls.addAccount('test', 'example.com', 'asdf')
    ss = acc.avatars.open()
    gph = GarbageProtocolHandler(store=ss, garbage=7)
    gph.installOn(ss)
Example #7
0
    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()
Example #8
0
def createDatabase(s):
    ls = LoginSystem(store=s)
    ls.installOn(s)
    acc = ls.addAccount(*CREDENTIALS)
    ss = acc.avatars.open()
    gph = GarbageProtocolHandler(store=ss, garbage=GARBAGE_LEVEL)
    gph.installOn(ss)
def createDatabase(s):
    loginSystem = LoginSystem(store=s)
    loginSystem.installOn(s)
    sip = SIPServer(store=s)
    sip.startService()
    account = loginSystem.addAccount(u'testuser', u'localhost', None)
    subStore = account.avatars.open()
    VoicemailDispatcher(store=subStore,
                        localHost='localhost').installOn(subStore)
    sip.stopService()
def createDatabase(store):
    """
    Instantiate a L{PrivateApplication} in C{store} and install it.
    """
    loginSystem = LoginSystem(store=store)
    installOn(loginSystem, store)
    account = loginSystem.addAccount(USERNAME, DOMAIN, None)
    subStore = account.avatars.open()

    app = PrivateApplication(store=subStore, preferredTheme=PREFERRED_THEME, privateKey=PRIVATE_KEY)
    installOn(app, subStore)
Example #11
0
def createDatabase(store):
    """
    Instantiate a L{PrivateApplication} in C{store} and install it.
    """
    loginSystem = LoginSystem(store=store)
    installOn(loginSystem, store)
    account = loginSystem.addAccount(USERNAME, DOMAIN, None)
    subStore = account.avatars.open()

    app = PrivateApplication(
        store=subStore,
        preferredTheme=PREFERRED_THEME,
        privateKey=PRIVATE_KEY)
    installOn(app, subStore)
def createDatabase(s):
    """
    Create an account in the given store and install a MailTransferAgent on
    both the given store and the substore for that account.
    """
    Scheduler(store=s).installOn(s)

    loginSystem = LoginSystem(store=s)
    loginSystem.installOn(s)

    mta = MailTransferAgent(store=s)
    mta.installOn(s)

    account = loginSystem.addAccount(u'testuser', u'localhost', None)
    subStore = account.avatars.open()
    SubScheduler(store=subStore).installOn(subStore)
    mda = MailTransferAgent(store=subStore)
    mda.installOn(subStore)
Example #13
0
def createDatabase(s):
    """
    Create an account in the given store and install a MailTransferAgent on
    both the given store and the substore for that account.
    """
    Scheduler(store=s).installOn(s)

    loginSystem = LoginSystem(store=s)
    loginSystem.installOn(s)

    mta = MailTransferAgent(store=s)
    mta.installOn(s)

    account = loginSystem.addAccount(u'testuser', u'localhost', None)
    subStore = account.avatars.open()
    SubScheduler(store=subStore).installOn(subStore)
    mda = MailTransferAgent(store=subStore)
    mda.installOn(subStore)
Example #14
0
class WebSharingTestCase(TestCase):
    """
    Tests for L{xmantissa.websharing.linkTo}
    """
    def setUp(self):
        """
        Set up some state.
        """
        self.s = Store()
        self.ls = LoginSystem(store=self.s)
        installOn(self.ls, self.s)
        acct = self.ls.addAccount(
            u'right', u'host', u'', verified=True, internal=True)
        acct.addLoginMethod(
            u'wrong', u'host', internal=False, verified=False)
        self.share = sharing.shareItem(self.ls, shareID=u'loginsystem')


    def test_noLoginMethods(self):
        """
        L{websharing.linkTo} raises a L{RuntimeError} when the shared item is
        in a store with no internal L{LoginMethod}s.
        """
        for lm in self.s.query(LoginMethod):
            lm.internal = False
        self.assertRaises(RuntimeError, websharing.linkTo, self.share)


    def test_linkToShare(self):
        """
        Test that L{xmantissa.websharing.linkTo} generates a URL using the
        localpart of the account's internal L{axiom.userbase.LoginMethod}
        """
        self._verifyPath(websharing.linkTo(self.share))


    def _verifyPath(self, linkURL):
        """
        Verify that the given url matches the test's expectations.
        """
        self.failUnless(isinstance(linkURL, url.URL),
                        "linkTo should return a nevow.url.URL, not %r" %
                        (type(linkURL)))
        self.assertEquals(str(linkURL), '/users/right/loginsystem')


    def test_linkToProxy(self):
        """
        Test that L{xmantissa.websharing.linkTo} generates a URL that I can
        link to.
        """
        self._verifyPath(
            websharing.linkTo(sharing.getShare(self.s, sharing.getEveryoneRole(
                        self.s), u'loginsystem')))


    def test_shareURLInjectsShareID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} injects the share ID the
        constructor is passed when C{child} is called.
        """
        for (shareID, urlID) in [(u'a', 'a'), (u'\xe9', '%C3%A9')]:
            shareURL = websharing._ShareURL(shareID, netloc='', scheme='')
            self.assertEqual(str(shareURL.child('c')), '/%s/c' % urlID)
            # make sure subsequent child calls on the original have the same
            # behaviour
            self.assertEqual(str(shareURL.child('d')), '/%s/d' % urlID)
            # and that child calls on the returned urls don't (i.e. not
            # '/a/c/a/d'
            self.assertEqual(str(shareURL.child('c').child('d')),
                             '/%s/c/d' % urlID)


    def test_shareURLNoStoreID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} behaves like a regular
        L{nevow.url.URL} when no store ID is passed.
        """
        shareURL = websharing._ShareURL(None, netloc='', scheme='')
        self.assertEqual(str(shareURL.child('a')), '/a')
        self.assertEqual(str(shareURL.child('a').child('b')), '/a/b')


    def test_shareURLNoClassmethodConstructors(self):
        """
        Verify that the C{fromRequest}, C{fromContext} and C{fromString}
        constructors on L{xmantissa.websharing._ShareURL} throw
        L{NotImplementedError}.
        """
        for meth in (websharing._ShareURL.fromRequest,
                     websharing._ShareURL.fromString,
                     websharing._ShareURL.fromContext):
            self.assertRaises(
                NotImplementedError,
                lambda: meth(None))


    def test_shareURLCloneMaintainsShareID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} can be cloned, and that
        clones will remember the share ID.
        """
        shareURL = websharing._ShareURL(u'a', netloc='', scheme='')
        shareURL = shareURL.cloneURL('', '', None, None, '')
        self.assertEqual(shareURL._shareID, u'a')


    def test_defaultShareIDInteractionMatching(self):
        """
        Verify that L{websharing.linkTo} does not explicitly include a share
        ID in the URL if the ID of the share it is passed matches the default.
        """
        websharing.addDefaultShareID(self.s, u'share-id', 0)
        sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
        share = sharing.getShare(
            self.s, sharing.getEveryoneRole(self.s), u'share-id')
        url = websharing.linkTo(share)
        self.assertEqual(str(url), '/users/right/')
        # and if we call child()
        self.assertEqual(str(url.child('child')), '/users/right/share-id/child')


    def test_defaultShareIDInteractionNoMatch(self):
        """
        Verify that L{websharing.linkTo} explicitly includes a share ID in the
        URL if the ID of the share it is passed doesn't match the default.
        """
        websharing.addDefaultShareID(self.s, u'share-id', 0)
        shareable = Shareable(store=self.s)
        sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
        share = sharing.getShare(
            self.s, sharing.getEveryoneRole(self.s), u'not-the-share-id')
        url = websharing.linkTo(share)
        self.assertEqual(str(url), '/users/right/not-the-share-id')


    def test_appStoreLinkTo(self):
        """
        When L{websharing.linkTo} is called on a shared item in an app store,
        it returns an URL with a single path segment consisting of the app's
        name.
        """
        s = Store(dbdir=self.mktemp())
        Mantissa().installSite(s, u"localhost", u"", False)
        Mantissa().installAdmin(s, u'admin', u'localhost', u'asdf')
        off = offering.Offering(
            name=u'test_offering',
            description=u'Offering for creating a sample app store',
            siteRequirements=[],
            appPowerups=[TestAppPowerup],
            installablePowerups=[],
            loginInterfaces=[],
            themes=[],
            )
        userbase = s.findUnique(LoginSystem)
        adminAccount = userbase.accountByAddress(u'admin', u'localhost')
        conf = adminAccount.avatars.open().findUnique(
            offering.OfferingConfiguration)
        conf.installOffering(off, None)
        ss = userbase.accountByAddress(off.name, None).avatars.open()
        sharedItem = sharing.getEveryoneRole(ss).getShare(
            websharing.getDefaultShareID(ss))
        linkURL = websharing.linkTo(sharedItem)
        self.failUnless(isinstance(linkURL, url.URL),
                        "linkTo should return a nevow.url.URL, not %r" %
                        (type(linkURL)))
        self.assertEquals(str(linkURL), '/test_offering/')
Example #15
0
class WebSharingTestCase(TestCase):
    """
    Tests for L{xmantissa.websharing.linkTo}
    """
    def setUp(self):
        """
        Set up some state.
        """
        self.s = Store()
        self.ls = LoginSystem(store=self.s)
        installOn(self.ls, self.s)
        acct = self.ls.addAccount(u'right',
                                  u'host',
                                  u'',
                                  verified=True,
                                  internal=True)
        acct.addLoginMethod(u'wrong', u'host', internal=False, verified=False)
        self.share = sharing.shareItem(self.ls, shareID=u'loginsystem')

    def test_noLoginMethods(self):
        """
        L{websharing.linkTo} raises a L{RuntimeError} when the shared item is
        in a store with no internal L{LoginMethod}s.
        """
        for lm in self.s.query(LoginMethod):
            lm.internal = False
        self.assertRaises(RuntimeError, websharing.linkTo, self.share)

    def test_linkToShare(self):
        """
        Test that L{xmantissa.websharing.linkTo} generates a URL using the
        localpart of the account's internal L{axiom.userbase.LoginMethod}
        """
        self._verifyPath(websharing.linkTo(self.share))

    def _verifyPath(self, linkURL):
        """
        Verify that the given url matches the test's expectations.
        """
        self.failUnless(
            isinstance(linkURL, url.URL),
            "linkTo should return a nevow.url.URL, not %r" % (type(linkURL)))
        self.assertEquals(str(linkURL), '/users/right/loginsystem')

    def test_linkToProxy(self):
        """
        Test that L{xmantissa.websharing.linkTo} generates a URL that I can
        link to.
        """
        self._verifyPath(
            websharing.linkTo(
                sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                                 u'loginsystem')))

    def test_shareURLInjectsShareID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} injects the share ID the
        constructor is passed when C{child} is called.
        """
        for (shareID, urlID) in [(u'a', 'a'), (u'\xe9', '%C3%A9')]:
            shareURL = websharing._ShareURL(shareID, netloc='', scheme='')
            self.assertEqual(str(shareURL.child('c')), '/%s/c' % urlID)
            # make sure subsequent child calls on the original have the same
            # behaviour
            self.assertEqual(str(shareURL.child('d')), '/%s/d' % urlID)
            # and that child calls on the returned urls don't (i.e. not
            # '/a/c/a/d'
            self.assertEqual(str(shareURL.child('c').child('d')),
                             '/%s/c/d' % urlID)

    def test_shareURLNoStoreID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} behaves like a regular
        L{nevow.url.URL} when no store ID is passed.
        """
        shareURL = websharing._ShareURL(None, netloc='', scheme='')
        self.assertEqual(str(shareURL.child('a')), '/a')
        self.assertEqual(str(shareURL.child('a').child('b')), '/a/b')

    def test_shareURLNoClassmethodConstructors(self):
        """
        Verify that the C{fromRequest}, C{fromContext} and C{fromString}
        constructors on L{xmantissa.websharing._ShareURL} throw
        L{NotImplementedError}.
        """
        for meth in (websharing._ShareURL.fromRequest,
                     websharing._ShareURL.fromString,
                     websharing._ShareURL.fromContext):
            self.assertRaises(NotImplementedError, lambda: meth(None))

    def test_shareURLCloneMaintainsShareID(self):
        """
        Test that L{xmantissa.websharing._ShareURL} can be cloned, and that
        clones will remember the share ID.
        """
        shareURL = websharing._ShareURL(u'a', netloc='', scheme='')
        shareURL = shareURL.cloneURL('', '', None, None, '')
        self.assertEqual(shareURL._shareID, u'a')

    def test_defaultShareIDInteractionMatching(self):
        """
        Verify that L{websharing.linkTo} does not explicitly include a share
        ID in the URL if the ID of the share it is passed matches the default.
        """
        websharing.addDefaultShareID(self.s, u'share-id', 0)
        sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
        share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                                 u'share-id')
        url = websharing.linkTo(share)
        self.assertEqual(str(url), '/users/right/')
        # and if we call child()
        self.assertEqual(str(url.child('child')),
                         '/users/right/share-id/child')

    def test_defaultShareIDInteractionNoMatch(self):
        """
        Verify that L{websharing.linkTo} explicitly includes a share ID in the
        URL if the ID of the share it is passed doesn't match the default.
        """
        websharing.addDefaultShareID(self.s, u'share-id', 0)
        shareable = Shareable(store=self.s)
        sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
        share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                                 u'not-the-share-id')
        url = websharing.linkTo(share)
        self.assertEqual(str(url), '/users/right/not-the-share-id')

    def test_appStoreLinkTo(self):
        """
        When L{websharing.linkTo} is called on a shared item in an app store,
        it returns an URL with a single path segment consisting of the app's
        name.
        """
        s = Store(dbdir=self.mktemp())
        Mantissa().installSite(s, u"localhost", u"", False)
        Mantissa().installAdmin(s, u'admin', u'localhost', u'asdf')
        off = offering.Offering(
            name=u'test_offering',
            description=u'Offering for creating a sample app store',
            siteRequirements=[],
            appPowerups=[TestAppPowerup],
            installablePowerups=[],
            loginInterfaces=[],
            themes=[],
        )
        userbase = s.findUnique(LoginSystem)
        adminAccount = userbase.accountByAddress(u'admin', u'localhost')
        conf = adminAccount.avatars.open().findUnique(
            offering.OfferingConfiguration)
        conf.installOffering(off, None)
        ss = userbase.accountByAddress(off.name, None).avatars.open()
        sharedItem = sharing.getEveryoneRole(ss).getShare(
            websharing.getDefaultShareID(ss))
        linkURL = websharing.linkTo(sharedItem)
        self.failUnless(
            isinstance(linkURL, url.URL),
            "linkTo should return a nevow.url.URL, not %r" % (type(linkURL)))
        self.assertEquals(str(linkURL), '/test_offering/')