source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testInstallation.py @ 3152

Last change on this file since 3152 was 3152, checked in by zidane, 9 years ago

fixes pep8

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1from base import *
2from zope.component import getSiteManager
3from archetypes.schemaextender.interfaces import ISchemaExtender
4from Products.CMFPlone.utils import _createObjectByType
5from quintagroup.canonicalpath.interfaces import ICanonicalLink
6
7
8class TestGoogleSitemapsInstallation(TestCase):
9
10    def testType(self):
11        pt = self.portal.portal_types
12        self.assert_('Sitemap' in pt.objectIds(),
13            'No "Sitemap" type after installation')
14        #Test views
15        views = pt.getTypeInfo('Sitemap').view_methods
16        self.assert_('sitemap.xml' in views,
17            'No "sitemap.xml" view for Sitemap type')
18        self.assert_('mobile-sitemap.xml' in views,
19            'No "mobile-sitemap.xml" view for Sitemap type')
20        self.assert_('news-sitemap.xml' in views,
21            'No "news-sitemap.xml" view for Sitemap type')
22
23    def testGSMProperties(self):
24        pp = self.portal.portal_properties
25
26        # Test types_not_searched
27        self.assert_("Sitemap" in \
28            pp['site_properties'].getProperty('types_not_searched'),
29            'No "Sitemap" added to types not searched on installation')
30        # Test metaTypesNotToList
31        self.assert_("Sitemap" in \
32            pp['navtree_properties'].getProperty('metaTypesNotToList'),
33            'No "Sitemap" added to types not to list on installation')
34
35        # Test 'googlesitemap_properties'
36        self.assert_('googlesitemap_properties' in pp.objectIds(),
37            'No "googlesitemap_properties" after installation')
38        qsmprops = pp['googlesitemap_properties']
39        self.assert_(qsmprops.hasProperty('verification_filenames'),
40            'No "verification_filenames" property added on installation')
41
42    def testSkins(self):
43        ps = self.portal.portal_skins
44        self.assert_('plonegooglesitemaps' in ps.objectIds(),
45            'No "plonegooglesitemaps" skin layer in portal_skins')
46        self.assert_('plonegooglesitemaps' in \
47                     ps.getSkinPath(ps.getDefaultSkin()),
48            'No "plonegooglesitemaps" skin layer in default skin')
49
50    def testConfiglet(self):
51        cp = self.portal.portal_controlpanel
52        self.assert_([1 for ai in cp.listActionInfos() \
53                      if ai['id'] == 'GoogleSitemaps'],
54            'No "GoogleSitemaps" configlet added to plone control panel')
55
56    def testNewsSchemaExtenderRegistered(self):
57        lsm = getSiteManager(self.portal)
58        news = self.portal.invokeFactory("News Item", id="test_news")
59        news = getattr(self.portal, "test_news")
60        self.assertNotEqual(lsm.queryAdapter(
61                news, interface=ISchemaExtender,
62                name="quintagroup.plonegooglesitemaps.newssitemapextender"),
63            None)
64
65    def testUpdateCatalog(self):
66        # Test added new columns in catalog
67        Language = 'test_language'
68        gsm_access = 'test_gsm_access'
69        gsm_genres = (u'test_gsm_genres',)
70        gsm_stock = 'test_gsm_stock'
71        cols = ["canonical_link", "Language", "gsm_access",
72                "gsm_genres", "gsm_stock"]
73        lsm = getSiteManager(self.portal)
74        catalog = self.portal.portal_catalog
75        setuptools = self.portal.portal_setup
76        for col in cols:
77            self.assertEqual(col in catalog._catalog.names, True)
78
79        # Test update catalog
80        # Create news
81        news = _createObjectByType('News Item', self.portal, id='test_news')
82        news_cpath = "/my_test_news"
83        news_clink = self.portal.absolute_url() + news_cpath
84
85        # The canonical_link, Language, gsm_access, gsm_genres, gsm_stock
86        # brain must contains not updated canonical_link data
87        brain = catalog(id="test_news")[0]
88        self.assertNotEqual(brain.canonical_link, news_clink)
89        self.assertNotEqual(brain.Language, Language)
90        self.assertNotEqual(brain.gsm_access, gsm_access)
91        self.assertNotEqual(brain.gsm_genres, gsm_genres)
92        self.assertNotEqual(brain.gsm_stock, gsm_stock)
93
94        # Update fields
95        ICanonicalLink(news).canonical_link = news_clink
96        news.update(
97            language=Language, gsm_access=gsm_access,
98            gsm_genres=gsm_genres, gsm_stock=gsm_stock)
99        setuptools.runImportStepFromProfile(
100            'profile-quintagroup.plonegooglesitemaps:default', 'catalog')
101
102        # The canonical_link, Language, gsm_access, gsm_genres, gsm_stock
103        # brain must contains updated canonical_link data
104        brain = catalog(id="test_news")[0]
105        self.assertEqual(brain.canonical_link, news_clink)
106        self.assertEqual(brain.Language, Language)
107        self.assertEqual(brain.gsm_access, gsm_access)
108        self.assertEqual(brain.gsm_genres, gsm_genres)
109        self.assertEqual(brain.gsm_stock, gsm_stock)
110
111    def test_browser_layer(self):
112        if not SUPPORT_BLAYER:
113            return
114
115        from plone.browserlayer import utils
116        self.assert_(IGoogleSitemapsLayer in utils.registered_layers(),
117                     "Not registered 'IGoogleSitemapsLayer' browser layer")
118
119
120class TestGoogleSitemapsUninstallation(TestCase):
121
122    def afterSetUp(self):
123        super(TestGoogleSitemapsUninstallation, self).afterSetUp()
124        self.portal.portal_quickinstaller.uninstallProducts(
125            products=['quintagroup.plonegooglesitemaps', ])
126        self._refreshSkinData()
127
128    def testNewsSchemaExtenderUnregistered(self):
129        lsm = getSiteManager(self.portal)
130        news = self.portal.invokeFactory("News Item", id="test_news")
131        news = getattr(self.portal, "test_news")
132        self.assertEqual(lsm.queryAdapter(news, interface=ISchemaExtender),
133            None)
134
135    def testConfigletUninstall(self):
136        self.assertNotEqual(
137            self.portal.portal_quickinstaller.isProductInstalled(PRODUCT),
138            True, '%s is already installed' % PRODUCT)
139        configTool = self.portal.portal_controlpanel
140        self.assertEqual('GoogleSitemaps' in [a.getId() for a in \
141                                              configTool.listActions()], False,
142            'Configlet found after uninstallation')
143
144    def test_browserlayer_uninstall(self):
145        if not SUPPORT_BLAYER:
146            return
147
148        from plone.browserlayer import utils
149        self.assertEqual(IGoogleSitemapsLayer in utils.registered_layers(),
150            False, "Still registered 'IGoogleSitemapsLayer' browser layer")
151
152
153def test_suite():
154    from unittest import TestSuite, makeSuite
155    suite = TestSuite()
156    suite.addTest(makeSuite(TestGoogleSitemapsInstallation))
157    suite.addTest(makeSuite(TestGoogleSitemapsUninstallation))
158    return suite
159
160if __name__ == '__main__':
161    unittest.main(defaultTest='test_suite')
162#    framework()
Note: See TracBrowser for help on using the repository browser.