Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 130 lines (95 sloc) 4.281 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
# -*- coding: utf-8 -*-
"""Module where all TestCases live."""

from collective.transmogrifier.transmogrifier import Transmogrifier
from plone.app.testing import IntegrationTesting
from plone.app.testing import login
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from Products.CMFCore.utils import getToolByName

import transaction
import unittest2 as unittest

QUERY = {
    'b_size': 10,
    'portal_type': ['News Item', 'Image', 'Topic', 'Link', 'File', 'Folder', 'Document', 'Event'],
    'SearchableText': 'dog',
    'show_inactive': False,
    'b_start': 0,
    'path': '/plone'
}


class CatalogRegressionLayer(PloneSandboxLayer):

    defaultBases = (PLONE_FIXTURE,)

    def setUpZope(self, app, configurationContext):
        """Set up Zope."""
        # Load ZCML
        import catalog.regression
        self.loadZCML(package=catalog.regression)

    def setUpPloneSite(self, portal):
        """Set up Plone."""
        # Install into Plone site using portal_setup
        #applyProfile(portal, 'niteoweb.plr:default')

        # Login as Manager
        setRoles(portal, TEST_USER_ID, ['Manager'])
        login(portal, TEST_USER_NAME)


FIXTURE = CatalogRegressionLayer()
INTEGRATION_TESTING = IntegrationTesting(
    bases=(FIXTURE,), name="CatalogRegressionLayer:Integration")


class IntegrationTestCase(unittest.TestCase):
    """Base class for integration tests."""

    layer = INTEGRATION_TESTING


class Test3Articles(IntegrationTestCase):
    """Test search results alternation for 3 articles."""

    def test_search_alternation(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.catalog = getToolByName(self.portal, 'portal_catalog')

        # Create test content by importing test articles with Transmogrifier
        transmogrifier = Transmogrifier(self.portal)
        transmogrifier('Import 3 articles')

        # Commit all changes
        self.portal.portal_catalog.clearFindAndRebuild()
        transaction.commit()

        # query catalog twice
        first = self.catalog(QUERY)[:3]
        second = self.catalog(QUERY)[:3]

        self.assertEquals(first[0].id, second[0].id,
            "FAIL: first and second query returned a differnet top result: '%s' vs. '%s '"
                % (first[0].id, second[0].id))


class Test10Articles(IntegrationTestCase):
    """Test search results alternation for 10 articles."""

    def test_search_alternation(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.catalog = getToolByName(self.portal, 'portal_catalog')

        # Create test content by importing test articles with Transmogrifier
        transmogrifier = Transmogrifier(self.portal)
        transmogrifier('Import 10 articles')

        # Commit all changes
        self.portal.portal_catalog.clearFindAndRebuild()
        transaction.commit()

        # query catalog twice
        first = self.catalog(QUERY)[:3]
        second = self.catalog(QUERY)[:3]

        self.assertEquals(first[0].id, second[0].id,
            "FAIL: first and second query returned a differnet top result: '%s' vs. '%s '"
                % (first[0].id, second[0].id))


class Test100Articles(IntegrationTestCase):
    """Test search results alternation for 100 articles."""

    def test_search_alternation(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.catalog = getToolByName(self.portal, 'portal_catalog')

        # Create test content by importing test articles with Transmogrifier
        transmogrifier = Transmogrifier(self.portal)
        transmogrifier('Import 100 articles')

        # Commit all changes
        self.portal.portal_catalog.clearFindAndRebuild()
        transaction.commit()

        # query catalog twice
        first = self.catalog(QUERY)[:3]
        second = self.catalog(QUERY)[:3]

        self.assertEquals(first[0].id, second[0].id,
            "FAIL: first and second query returned a different top result: '%s' vs. '%s '"
                % (first[0].id, second[0].id))
Something went wrong with that request. Please try again.