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

Last change on this file since 2535 was 2535, checked in by mylan, 9 years ago

#206: move mobile sitemap code preparation into base module

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