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
Beispiel #2
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
 def setUp(self):
     """
     Create a store and a scrolling fragment
     """
     self.store = Store()
     self.scrollingFragment = MailboxScrollingFragment(self.store)
class ScrollingFragmentTestCase(TestCase):
    """
    Tests for L{xquotient.inbox.MailboxScrollingFragment}
    """
    def _makeMessages(self):
        """
        Make 3 incoming messages

        @rtype: C{list} of L{xquotient.exmess.Message}
        """
        msgs = []
        for (subject, timestamp) in ((u'3', 67), (u'1', 43), (u'2', 55)):
            msgs.append(
                testMessageFactory(
                    store=self.store,
                    read=False,
                    spam=False,
                    subject=subject,
                    receivedWhen=Time.fromPOSIXTimestamp(timestamp)))
        return msgs

    def setUp(self):
        """
        Create a store and a scrolling fragment
        """
        self.store = Store()
        self.scrollingFragment = MailboxScrollingFragment(self.store)

    def _checkSortOrder(self, ascending):
        """
        Check the sort order of messages in L{self.scrollingFragment}

        @param ascending: should the messages be sorted in ascending order
        """
        msgs = self.scrollingFragment.performQuery(
            0, self.scrollingFragment.performCount())
        timestamps = list(m.receivedWhen for m in msgs)
        sortedTimestamps = sorted(timestamps)
        if not ascending:
            sortedTimestamps.reverse()
        self.assertEquals(timestamps, sortedTimestamps)

    def _changeView(self, newView):
        """
        Change the 'view' parameter of L{self.scrollingFragment}'s view
        selection to C{newView}

        @param newView: the view name
        @type newView: C{unicode}
        """
        viewSelection = self.scrollingFragment.viewSelection.copy()
        viewSelection['view'] = newView
        self.scrollingFragment.setViewSelection(viewSelection)

    def test_defaultSortAscending(self):
        """
        Test that the default sort of
        L{xquotient.inbox.MailboxScrollingFragment} is ascending on the
        C{receivedWhen} column, as inbox is the default view
        """
        self._makeMessages()
        self._checkSortOrder(ascending=True)

    def test_inboxSortAscending(self):
        """
        Test that the sort order of
        L{xquotient.inbox.MailboxScrollingFragment} for the inbox view is
        correct when the view is selected explicitly
        """
        self._makeMessages()

        self._changeView(ARCHIVE_STATUS)
        self._changeView(INBOX_STATUS)

        self._checkSortOrder(ascending=True)

    def test_touchOnceSortOrder(self):
        """
        Test that the sort of L{xquotient.inbox.MailboxScrollingFragment} is
        only ascending for touch once views
        """
        for view in set(VIEWS) - set(TOUCH_ONCE_VIEWS):
            for msg in self._makeMessages():
                msg.addStatus(view)

            self._changeView(view)
            self._checkSortOrder(ascending=False)
Beispiel #5
0
 def setUp(self):
     """
     Create a store and a scrolling fragment
     """
     self.store = Store()
     self.scrollingFragment = MailboxScrollingFragment(self.store)
Beispiel #6
0
class ScrollingFragmentTestCase(TestCase):
    """
    Tests for L{xquotient.inbox.MailboxScrollingFragment}
    """

    def _makeMessages(self):
        """
        Make 3 incoming messages

        @rtype: C{list} of L{xquotient.exmess.Message}
        """
        msgs = []
        for (subject, timestamp) in ((u'3', 67), (u'1', 43), (u'2', 55)):
            msgs.append(
                testMessageFactory(
                    store=self.store,
                    read=False,
                    spam=False,
                    subject=subject,
                    receivedWhen=Time.fromPOSIXTimestamp(timestamp)))
        return msgs


    def setUp(self):
        """
        Create a store and a scrolling fragment
        """
        self.store = Store()
        self.scrollingFragment = MailboxScrollingFragment(self.store)


    def _checkSortOrder(self, ascending):
        """
        Check the sort order of messages in L{self.scrollingFragment}

        @param ascending: should the messages be sorted in ascending order
        """
        msgs = self.scrollingFragment.performQuery(
            0, self.scrollingFragment.performCount())
        timestamps = list(m.receivedWhen for m in msgs)
        sortedTimestamps = sorted(timestamps)
        if not ascending:
            sortedTimestamps.reverse()
        self.assertEquals(timestamps, sortedTimestamps)


    def _changeView(self, newView):
        """
        Change the 'view' parameter of L{self.scrollingFragment}'s view
        selection to C{newView}

        @param newView: the view name
        @type newView: C{unicode}
        """
        viewSelection = self.scrollingFragment.viewSelection.copy()
        viewSelection['view'] = newView
        self.scrollingFragment.setViewSelection(viewSelection)


    def test_defaultSortAscending(self):
        """
        Test that the default sort of
        L{xquotient.inbox.MailboxScrollingFragment} is ascending on the
        C{receivedWhen} column, as inbox is the default view
        """
        self._makeMessages()
        self._checkSortOrder(ascending=True)


    def test_inboxSortAscending(self):
        """
        Test that the sort order of
        L{xquotient.inbox.MailboxScrollingFragment} for the inbox view is
        correct when the view is selected explicitly
        """
        self._makeMessages()

        self._changeView(ARCHIVE_STATUS)
        self._changeView(INBOX_STATUS)

        self._checkSortOrder(ascending=True)

    def test_touchOnceSortOrder(self):
        """
        Test that the sort of L{xquotient.inbox.MailboxScrollingFragment} is
        only ascending for touch once views
        """
        for view in set(VIEWS) - set(TOUCH_ONCE_VIEWS):
            for msg in self._makeMessages():
                msg.addStatus(view)

            self._changeView(view)
            self._checkSortOrder(ascending=False)