コード例 #1
0
    def test_result_batching(self):
        for idx in range(5):
            self.portal.invokeFactory('Document', 'document{}'.format(idx))
        request = self.request.clone()
        request.form['b_size'] = 5
        view = FolderView(self.portal, request)

        batch = view.batch()
        self.assertEqual(batch.length, 5)
        self.assertEqual(len([item for item in batch]), 5)
        self.assertFalse(batch.has_next)

        self.portal.invokeFactory('Document', 'document5')

        batch = view.batch()
        self.assertEqual(batch.length, 6)
        self.assertEqual(len([item for item in batch]), 6)
        self.assertFalse(batch.has_next)

        self.portal.invokeFactory('Document', 'document6')

        batch = view.batch()
        self.assertEqual(batch.length, 5)
        self.assertEqual(len([item for item in batch]), 5)
        self.assertTrue(batch.has_next)
        self.assertEqual(batch.next_item_count, 2)
コード例 #2
0
    def test_result_filtering(self):
        """Test, if portal_state's friendly_types and the result method's
        keyword arguments are included in the query.
        """

        self.portal.invokeFactory('News Item', 'newsitem')
        self.portal.invokeFactory('Document', 'document')
        view = FolderView(self.portal, self.request)

        # Test, if all results are found.
        view.portal_state.friendly_types = lambda: ['Document', 'News Item']
        res = view.results()
        self.assertEqual(len(res), 2)

        # Test, if friendly_types does filter for types.
        view.portal_state.friendly_types = lambda: ['Document']
        res = view.results()
        self.assertEqual(len(res), 1)

        # Test, if friendly_types does filter for types.
        view.portal_state.friendly_types = lambda: ['NotExistingType']
        res = view.results()
        self.assertEqual(len(res), 0)

        # Test, if kwargs filtering is applied.
        view.portal_state.friendly_types = lambda: ['NotExistingType']
        res = view.results(
            object_provides='plone.app.contenttypes.interfaces.IDocument'
        )
        self.assertEqual(len(res), 1)