source: products/qPloneGoogleSitemaps/tags/0.5/tests/testqPloneGoogleSitemaps.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 14 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1#
2# Tests for qPloneGoogleSitemaps
3#
4import os, sys
5if __name__ == '__main__':
6    execfile(os.path.join(sys.path[0], 'framework.py'))
7
8from Products.PloneTestCase import PloneTestCase
9from XMLParser import parse, hasURL
10
11PRODUCT = 'qPloneGoogleSitemaps'
12PRODUCTS = (PRODUCT,)
13PloneTestCase.installProduct(PRODUCT)
14PloneTestCase.setupPloneSite(products = PRODUCTS)
15
16class TestqPloneGoogleSitemaps(PloneTestCase.FunctionalTestCase):
17
18    def afterSetUp(self):
19        self.loginAsPortalOwner()
20
21        self.membership = self.portal.portal_membership
22        self.workflow = self.portal.portal_workflow
23        self.auth = 'admin:admin'
24        self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps'
25        self.membership.addMember('admin', 'admin', ('Manager',), [])
26
27        # Add testing document to portal
28        my_doc = self.portal.invokeFactory('Document', id='my_doc')
29        self.my_doc = self.portal['my_doc']
30        self.my_doc.edit(text_format='plain', text='hello world')
31
32    def testInstallation(self):
33        installed = self.portal.portal_quickinstaller.isProductInstalled(PRODUCT)
34        self.assert_(installed, 'Product not installed')
35
36    def testSitemap(self):
37        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
38        parsed_sitemap = parse(sitemap)
39        start = parsed_sitemap['start']
40        data = parsed_sitemap['data']
41        self.assertEqual(len(start.keys()), 1)
42        self.assert_('urlset' in start.keys())
43
44        self.workflow.doActionFor(self.my_doc, 'publish')
45
46        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
47        parsed_sitemap = parse(sitemap)
48        start = parsed_sitemap['start']
49        data = parsed_sitemap['data']
50        self.assertEqual(len(start.keys()), 4)
51        self.assert_('urlset' in start.keys())
52        self.assert_('url' in start.keys())
53        self.assert_('loc' in start.keys())
54        self.assert_('lastmod' in start.keys())
55
56        self.assert_(data[0] == self.my_doc.absolute_url(0), 'Incorect url')
57
58    def testVerificationFile(self):
59        self.portal.gsm_create_verify_file('verif_file')
60        vf_created = hasattr(self.portal, 'verif_file')
61        self.assert_(vf_created, 'Verification file not created')
62
63        self.portal.gsm_delete_verify_file()
64        vf_created = hasattr(self.portal, 'verif_file')
65        self.assert_(not vf_created, 'Verification file not removed')
66
67class TestSettings(PloneTestCase.FunctionalTestCase):
68
69    def afterSetUp(self):
70        self.loginAsPortalOwner()
71
72        self.membership = self.portal.portal_membership
73        self.workflow = self.portal.portal_workflow
74        self.gsm_props = self.portal.portal_properties['googlesitemap_properties']
75        self.auth = 'admin:admin'
76        self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps'
77
78        self.membership.addMember('admin', 'admin', ('Manager',), [])
79
80        # Add testing document to portal
81        my_doc = self.portal.invokeFactory('Document', id='my_doc')
82        self.my_doc = self.portal['my_doc']
83        self.my_doc.edit(text_format='plain', text='hello world')
84        self.my_doc_url = self.my_doc.absolute_url()
85
86    def testMetaTypeToDig(self):
87        self.workflow.doActionFor(self.my_doc, 'publish')
88        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
89        self.assert_(hasURL(sitemap, self.my_doc_url))
90
91        self.gsm_props.manage_changeProperties(portalTypes = [])
92
93        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
94        self.assert_(not hasURL(sitemap, self.my_doc_url))
95
96        self.gsm_props.manage_changeProperties(portalTypes = ['Document'])
97
98        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
99        self.assert_(hasURL(sitemap, self.my_doc_url))
100
101    def testStates(self):
102        self.workflow.doActionFor(self.my_doc, 'publish')
103        self.gsm_props.manage_changeProperties(states = ['visible'])
104
105        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
106        self.assert_(not hasURL(sitemap, self.my_doc_url))
107
108        self.gsm_props.manage_changeProperties(states = ['published'])
109
110        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
111        self.assert_(hasURL(sitemap, self.my_doc_url))
112
113    def test_blackout_entries(self):
114        self.workflow.doActionFor(self.my_doc, 'publish')
115        self.gsm_props.manage_changeProperties(blackout_list = (self.my_doc.getId(),))
116        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
117        self.assert_(not hasURL(sitemap, self.my_doc_url))
118
119        self.gsm_props.manage_changeProperties(blackout_list = [])
120        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
121        self.assert_(hasURL(sitemap, self.my_doc_url))
122
123    def test_regexp(self):
124        self.workflow.doActionFor(self.my_doc, 'publish')
125        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
126        self.assert_(not hasURL(sitemap, self.portal.absolute_url()))
127
128        regexp = 's//%s//'%self.my_doc.getId()
129        self.gsm_props.manage_changeProperties(reg_exp = [regexp])
130
131        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
132        self.assert_(hasURL(sitemap, self.portal.absolute_url()))
133
134    def test_add_urls(self):
135        self.gsm_props.manage_changeProperties(urls = ['http://w1', 'w2', '/w3'])
136        w1_url = 'http://w1'
137        w2_url = self.portal.absolute_url() + '/w2'
138        w3_url = self.portal.getPhysicalRoot().absolute_url() + '/w3'
139        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
140
141        self.assert_(hasURL(sitemap, w1_url))
142        self.assert_(hasURL(sitemap, w2_url))
143        self.assert_(hasURL(sitemap, w3_url))
144
145def test_suite():
146    from unittest import TestSuite, makeSuite
147    suite = TestSuite()
148    suite.addTest(makeSuite(TestqPloneGoogleSitemaps))
149    suite.addTest(makeSuite(TestSettings))
150    return suite
151
152if __name__ == '__main__':
153    framework()
Note: See TracBrowser for help on using the repository browser.