Ignore:
Timestamp:
Aug 11, 2010 6:31:04 PM (14 years ago)
Author:
mylan
Message:

#226: Added tests if sitemap search content related to the place, where it added to

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSitemaps.py

    r2538 r2741  
    33# 
    44from base import * 
     5from DateTime import DateTime 
     6from zope.interface import alsoProvides 
     7from zope.publisher.browser import TestRequest 
     8 
    59from Products.Archetypes import atapi 
    610from Products.CMFPlone.utils import _createObjectByType 
     11 
     12from quintagroup.plonegooglesitemaps.browser.sitemapview import SitemapView 
     13from quintagroup.plonegooglesitemaps.browser.newssitemapview import NewsSitemapView 
     14from quintagroup.plonegooglesitemaps.browser.mobilesitemapview import MobileSitemapView 
    715 
    816 
     
    213221 
    214222 
     223class TestContextSearch(TestCase): 
     224    """ Test if sitemaps collect objects from the container, 
     225        where it added to, but not from the portal root. 
     226    """ 
     227    def prepareTestContent(self, smtype, ptypes, ifaces=()): 
     228        # Create test folder 
     229        tfolder = _createObjectByType("Folder", self.portal, id="test-folder") 
     230        # Add SiteMap in the test folder 
     231        self.sm = _createObjectByType("Sitemap", tfolder, id='sitemap', 
     232                                      sitemapType=smtype, portalTypes=ptypes) 
     233        self.sm.at_post_create_script() 
     234        # Add content in root and in the test folder 
     235        pubdate = (DateTime()+1).strftime("%Y-%m-%d") 
     236        root_content = _createObjectByType(ptypes[0], self.portal, id='root-content') 
     237        inner_content = _createObjectByType(ptypes[0], tfolder, id='inner-content') 
     238        for obj in (root_content, inner_content): 
     239            self.workflow.doActionFor(obj, 'publish') 
     240            if ifaces: 
     241                alsoProvides(obj, ifaces) 
     242            obj.edit(effectiveDate=pubdate) # this also reindex object 
     243        self.inner_path = '/'.join(inner_content.getPhysicalPath()) 
     244         
     245    def testGoogleSitemap(self): 
     246        self.prepareTestContent("content", ("Document",)) 
     247        filtered = SitemapView(self.sm, TestRequest()).getFilteredObjects() 
     248        self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     249 
     250    def testNewsSitemap(self): 
     251        self.prepareTestContent("news", ("News Item",)) 
     252        filtered = NewsSitemapView(self.sm, TestRequest()).getFilteredObjects() 
     253        self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     254 
     255    def testMobileSitemap(self): 
     256        self.patchMobile() 
     257        self.prepareTestContent("content", ("Document",), (IMobileMarker,)) 
     258        filtered = MobileSitemapView(self.sm, TestRequest()).getFilteredObjects() 
     259        self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     260 
    215261 
    216262def test_suite(): 
     
    220266    suite.addTest(makeSuite(TestSettings)) 
    221267    suite.addTest(makeSuite(TestPinging)) 
     268    suite.addTest(makeSuite(TestContextSearch)) 
    222269    return suite 
    223270 
Note: See TracChangeset for help on using the changeset viewer.