source: products/quintagroup.plonegooglesitemaps/branches/test_refactoring/quintagroup/plonegooglesitemaps/tests/testMobileSitemaps.py @ 2534

Last change on this file since 2534 was 2534, checked in by mylan, 14 years ago

#206: some cleanup, simplify tests

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1from base import *
2from DateTime import DateTime
3
4from zope.interface import Interface, alsoProvides
5from zope.component import queryMultiAdapter
6from zope.component import getSiteManager, getGlobalSiteManager
7from archetypes.schemaextender.interfaces import ISchemaExtender
8
9from Products.CMFPlone.utils import _createObjectByType
10
11from quintagroup.plonegooglesitemaps.browser import mobilesitemapview
12from quintagroup.plonegooglesitemaps.browser.commonview import CommonSitemapView
13from quintagroup.plonegooglesitemaps.browser.mobilesitemapview import MobileSitemapView
14
15class IMobileMarker(Interface):
16    """Marker interface for mobile objects"""
17
18class TestMobileSitemapsXML(FunctionalTestCase):
19
20    def afterSetUp(self):
21        super(TestMobileSitemapsXML, self).afterSetUp()
22        # patch mobile sitemap view
23        self.orig_mobile_ifaces = mobilesitemapview.MOBILE_INTERFACES
24        mobilesitemapview.MOBILE_INTERFACES = [IMobileMarker.__identifier__,]
25          # Create mobile sitemaps
26        _createObjectByType("Sitemap", self.portal, id="mobile-sitemap.xml",
27                            sitemapType="mobile", portalTypes=("Document",))
28        self.portal["mobile-sitemap.xml"].at_post_create_script()
29        # Add testing mobile item to portal
30        self.pubdate = (DateTime()+1).strftime("%Y-%m-%d")
31        self.my_mobile = _createObjectByType('Document', self.portal, id='my_mobile')
32        alsoProvides(self.my_mobile, IMobileMarker)
33        self.my_mobile.edit(text="Test mobile item", title="First mobile (test)",
34                            effectiveDate=self.pubdate)
35        self.workflow.doActionFor(self.my_mobile, "publish")
36        self.reParse()
37
38    def beforeTearDown(self):
39        mobilesitemapview.MOBILE_INTERFACES = self.orig_mobile_ifaces
40        super(TestMobileSitemapsXML, self).beforeTearDown() 
41
42    def reParse(self):
43        # Parse mobile sitemap
44        self.sitemap = self.publish("/"+self.portal.absolute_url(1) + "/mobile-sitemap.xml",
45                                    "%s:%s" % (portal_owner, default_password)).getBody()
46        parsed_sitemap = parse(self.sitemap)
47        self.start = parsed_sitemap["start"]
48        self.data = parsed_sitemap["data"]
49
50    def test_urlset(self):
51        self.assert_("urlset" in self.start.keys())
52        urlset = self.start["urlset"]
53        self.assertEqual(urlset.get("xmlns", ""), "http://www.sitemaps.org/schemas/sitemap/0.9")
54        self.assertEqual(urlset.get("xmlns:mobile", ""), "http://www.google.com/schemas/sitemap-mobile/1.0")
55
56    def test_url(self):
57        self.assert_("url" in self.start.keys())
58
59    def test_loc(self):
60        self.assert_("loc" in self.start.keys())
61        self.assert_(self.portal.absolute_url() + "/my_mobile" in self.data)
62
63    def test_lastmod(self):
64        md = [f for k,f in mobilesitemapview.MobileSitemapView.additional_maps \
65              if k=='modification_date'][0]
66        bmobile = self.portal.portal_catalog(id="my_mobile")[0]
67        self.assert_("lastmod" in self.start.keys())
68        self.assert_(md(bmobile) in self.data, "Wrong 'modified date':" \
69                     " must be '%s', but exist: '%s'" % (md(bmobile), self.data))
70
71class TestMobileSitemaps(TestCase):
72
73    def afterSetUp(self):
74        super(TestMobileSitemaps, self).afterSetUp()
75        # create mobile sitemap
76        _createObjectByType("Sitemap", self.portal, id="mobile-sitemap.xml",
77                            sitemapType="mobile", portalTypes=("Document",))
78        mobile_sm = self.portal["mobile-sitemap.xml"]
79        mobile_sm.at_post_create_script()
80        self.default_layout = mobile_sm.getProperty('layout', "")
81        self.mobile_view = queryMultiAdapter((mobile_sm, self.portal.REQUEST),
82                               name=self.default_layout)
83
84    def testLayout(self):
85        self.assert_(self.default_layout == "mobile-sitemap.xml")
86
87    def testInterface(self):
88        self.assert_(mobilesitemapview.ISitemapView.providedBy(self.mobile_view))
89
90    def testClasses(self):
91        self.assert_(isinstance(self.mobile_view, MobileSitemapView))
92        self.assert_(isinstance(self.mobile_view, CommonSitemapView))
93
94    def testAdditionalMaps(self):
95        self.assert_(hasattr(self.mobile_view, "additional_maps"))
96        self.assert_([1 for k,f in self.mobile_view.additional_maps \
97                 if k=="modification_date"])
98   
99
100def test_suite():
101    from unittest import TestSuite, makeSuite
102    suite = TestSuite()
103    suite.addTest(makeSuite(TestMobileSitemapsXML))
104    suite.addTest(makeSuite(TestMobileSitemaps))
105    return suite
Note: See TracBrowser for help on using the repository browser.