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

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

fixes pyflakes and pylint

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