Ejemplo n.º 1
0
    def setUp(self):
        """
        Set up an inequality model (by way of L{TestableInequalityModel}) backed by
        a user store with some sample data, and an L{IWebTranslator} powerup,
        to provide a somewhat realistic test setup.

        The data provided has some duplicates in the sort column, and it is
        intentionally inserted out of order, so that storeID order and sort
        column ordering will not coincide.
        """
        self.store = Store()
        privApp = PrivateApplication(store=self.store)
        installOn(privApp, self.store)

        self.data = []
        for a, b, c in [
            (9, 1928, u'nine'),
            (1, 983, u'one'),
            (8, 843, u'eight'),
            (2, 827, u'two'),
                # (8, 1874, u'eight (DUP)'), (2, 294, u'two (DUP)'),
            (7, 18, u'seven'),
            (3, 19, u'three'),
            (6, 218, u'six'),
            (4, 2198, u'four'),
            (5, 1982, u'five'),
            (0, 10, u'zero')
        ]:
            self.data.append(DataThunk(store=self.store, a=a, b=b, c=c))
        self.data.sort(key=lambda item: (item.a, item.storeID))

        self.model = TestableInequalityModel(
            self.store, DataThunk, None,
            [DataThunk.a, DataThunk.b, DataThunk.c], DataThunk.a, True)
Ejemplo n.º 2
0
    def test_partDisplayerScrubbedContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        to the length of the content after it has been transformed by
        the scrubber.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        body = u'<div><script>haha</script>this is ok</div>'
        part = PartItem(store=s,
                        contentType=u'text/html',
                        bodyLength=len(body),
                        body=body)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)

        def checkLength(renderedBody):
            self.assertEqual(int(req.headers.get('content-length')),
                             len(renderedBody))

        D.addCallback(checkLength)
        return D
Ejemplo n.º 3
0
 def getScrollingWidget(self, howManyElements=0):
     store = Store()
     installOn(PrivateApplication(store=store), store)
     for n in xrange(howManyElements):
         testMessageFactory(store, spam=False)
     f = MailboxScrollingFragment(store)
     f.docFactory = getLoader(f.fragmentName)
     f.setFragmentParent(self)
     return f
Ejemplo n.º 4
0
 def testZipFileName(self):
     """
     Test L{xquotient.exmess.MessageDetail._getZipFileName}
     """
     s = Store()
     installOn(PrivateApplication(store=s), s)
     installOn(QuotientPreferenceCollection(store=s), s)
     md = MessageDetail(
         Message(store=s, subject=u'a/b/c', sender=u'foo@bar'))
     self.assertEqual(md.zipFileName, '*****@*****.**')
Ejemplo n.º 5
0
    def addUser(self, username=u'nobody', domain=u'nowhere'):
        """
        Add a user to the site store, and install a L{PrivateApplication}.

        @return: the user store of the added user.
        """
        userStore = self.siteStore.findUnique(LoginSystem).addAccount(
            username, domain, u'asdf', internal=True).avatars.open()
        installOn(PrivateApplication(store=userStore), userStore)
        return userStore
Ejemplo n.º 6
0
    def setUp(self):
        self.siteStore = Store(filesdir=self.mktemp())
        Mantissa().installSite(self.siteStore, u"example.com", u"", False)

        self.userAccount = Create().addAccount(
            self.siteStore, u'testuser', u'example.com', u'password')
        self.userStore = self.userAccount.avatars.open()

        self.privapp = PrivateApplication(store=self.userStore)
        installOn(self.privapp, self.userStore)
        self.webViewer = IWebViewer(self.userStore)
Ejemplo n.º 7
0
 def getScrollingWidget(self, key, rowCount=10):
     store = Store()
     installOn(PrivateApplication(store=store), store)
     elements = [
         ScrollElement(store=store, column=i) for i in range(rowCount)
     ]
     columns = [ScrollElement.column]
     f = SequenceScrollingFragment(store, elements, columns)
     f.docFactory = getLoader(f.fragmentName)
     f.setFragmentParent(self)
     self.perTestData[key] = (store, elements, f)
     return f
Ejemplo n.º 8
0
 def setUp(self):
     self.store = Store()
     installOn(PrivateApplication(store=self.store), self.store)
     self.six = DataThunk(a=6, b=8157, c=u'six', store=self.store)
     self.three = DataThunk(a=3, b=821375, c=u'three', store=self.store)
     self.seven = DataThunk(a=7, b=4724, c=u'seven', store=self.store)
     self.eight = DataThunk(a=8, b=61, c=u'eight', store=self.store)
     self.one = DataThunk(a=1, b=435716, c=u'one', store=self.store)
     self.two = DataThunk(a=2, b=67145, c=u'two', store=self.store)
     self.four = DataThunk(a=4, b=6327, c=u'four', store=self.store)
     self.five = DataThunk(a=5, b=91856, c=u'five', store=self.store)
     self.scrollFragment = self.getScrollFragment()
Ejemplo n.º 9
0
 def setUp(self):
     self.store = Store()
     privApp = PrivateApplication(store=self.store)
     installOn(privApp, self.store)
     self.model = TestableInequalityModel(self.store, DataThunkWithIndex,
                                          None, [DataThunkWithIndex.a],
                                          DataThunkWithIndex.a, True,
                                          privApp)
     self.counter = QueryCounter(self.store)
     self.data = []
     for i in range(4):
         self.data.append(DataThunkWithIndex(store=self.store, a=i))
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def setUp(self):
        self.store = Store()
        privApp = PrivateApplication(store=self.store)
        installOn(privApp, self.store)

        # Create some data to test with in an order which is not naturally
        # sorted in any way.

        # 4 1s, 4 0s, 4 2s
        self.data = []
        for number in [1, 0, 2, 2, 0, 1, 1, 0, 2, 0, 2, 1]:
            self.data.append(DataThunk(store=self.store, a=number))

        # But order it for the sake of simplicity while testing.
        self.data.sort(key=lambda item: (item.a, item.storeID))

        self.model = TestableInequalityModel(
            self.store, DataThunk, None,
            [DataThunk.a, DataThunk.b, DataThunk.c], DataThunk.a, True)
Ejemplo n.º 12
0
    def test_setTabURLs(self):
        """
        Check that L{webnav.setTabURLs} correctly sets the C{linkURL}
        attribute of L{webnav.Tab} instances to the result of
        passing tab.storeID to L{xmantissa.ixmantissa.IWebTranslator.linkTo}
        if C{linkURL} is not set, and that it leaves it alone if it is
        """

        s = Store()

        privapp = PrivateApplication(store=s)
        installOn(privapp,s)

        tabs = [webnav.Tab('PrivateApplication', privapp.storeID, 0),
                webnav.Tab('Something Else', None, 0, linkURL='/foo/bar')]

        webnav.setTabURLs(tabs, privapp)

        self.assertEqual(tabs[0].linkURL, privapp.linkTo(privapp.storeID))
        self.assertEqual(tabs[1].linkURL, '/foo/bar')
Ejemplo n.º 13
0
    def test_partDisplayerContentLength(self):
        """
        Test that L{PartDisplayer} sets the C{Content-Length} header
        on the request.
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)
        part = PartItem(store=s,
                        contentType=u'text/plain',
                        bodyLength=31,
                        body=u'x' * 31)
        partDisplayer = PartDisplayer(None)
        partDisplayer.item = part

        req = makeRequest()
        D = deferredRender(partDisplayer, req)

        def checkLength(ign):
            self.assertEqual(int(req.headers.get('content-length')), 31)

        D.addCallback(checkLength)
        return D
Ejemplo n.º 14
0
    def setUp(self):
        """
        Set up a fake objects and methods for the password reset tests.
        """
        siteStore = Store(filesdir=self.mktemp())
        Mantissa().installSite(siteStore, u"divmod.com", u"", False)
        self.loginSystem = siteStore.findUnique(userbase.LoginSystem)
        self.site = siteStore.findUnique(SiteConfiguration)

        la = self.loginSystem.addAccount(
            u'joe', u'divmod.com', u'secret', internal=True)

        la.addLoginMethod(
            u'joe', u'external.com',
            protocol=u'zombie dance',
            verified=False,
            internal=False)

        # create an account with no external mail address
        account = self.loginSystem.addAccount(
            u'jill', u'divmod.com', u'secret', internal=True)

        account.addLoginMethod(
            u'jill', u'divmod.com',
            protocol=u'zombie dance',
            verified=True,
            internal=True)

        self.siteStore = siteStore

        # Set up the user store to have all the elements necessary to redirect
        # in the case where the user is already logged in.
        substore = la.avatars.open()
        installOn(PrivateApplication(store=substore), substore)

        self.userStore = substore
        self.loginAccount = la
        self.nonExternalAccount = account
        self.reset = PasswordResetResource(self.siteStore)
Ejemplo n.º 15
0
    def _testPartDisplayerScrubbing(self, input, scrub=True):
        """
        Set up a store, a PartItem with a body of C{input},
        pass it to the PartDisplayer, render it, and return
        a deferred that'll fire with the string result of
        the rendering.

        @param scrub: if False, the noscrub URL arg will
                      be added to the PartDisplayer request
        """
        s = Store()
        installOn(PrivateApplication(store=s), s)

        part = PartItem(store=s, contentType=u'text/html', body=input)

        pd = PartDisplayer(None)
        pd.item = part

        req = makeRequest()
        if not scrub:
            req.args = {'noscrub': True}

        return deferredRender(pd, req)
Ejemplo n.º 16
0
 def setUp(self):
     store = Store()
     ss = SubStore.createNew(store, ['test']).open()
     self.pa = PrivateApplication(store=ss)
     installOn(self.pa, ss)
     self.webViewer = IWebViewer(ss)
Ejemplo n.º 17
0
        def userStoreTxn():
            self.privateApp = PrivateApplication(store=self.userStore)
            installOn(self.privateApp, self.userStore)

            self.navpage = self.createPage(None)
Ejemplo n.º 18
0
 def userStoreTxn():
     self.privateApp = PrivateApplication(store=self.userStore)
     installOn(self.privateApp, self.userStore)
Ejemplo n.º 19
0
def createDatabase(s):
    PrivateApplication(store=s)