source: products/qPloneGoogleSitemaps/trunk/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.9 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       
61        vf_created = hasattr(self.portal, 'verif_file')
62        self.assert_(vf_created, 'Verification file not created')
63
64        self.portal.gsm_delete_verify_file()
65        vf_created = hasattr(self.portal, 'verif_file')
66        self.assert_(not vf_created, 'Verification file not removed')
67
68class TestSettings(PloneTestCase.FunctionalTestCase):
69
70    def afterSetUp(self):
71        self.loginAsPortalOwner()
72
73        self.membership = self.portal.portal_membership
74        self.workflow = self.portal.portal_workflow
75        self.gsm_props = self.portal.portal_properties['googlesitemap_properties']
76        self.auth = 'admin:admin'
77        self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps'
78
79        self.membership.addMember('admin', 'admin', ('Manager',), [])
80
81        # Add testing document to portal
82        my_doc = self.portal.invokeFactory('Document', id='my_doc')
83        self.my_doc = self.portal['my_doc']
84        self.my_doc.edit(text_format='plain', text='hello world')
85        self.my_doc_url = self.my_doc.absolute_url()
86
87    def testMetaTypeToDig(self):
88        self.workflow.doActionFor(self.my_doc, 'publish')
89        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
90        self.assert_(hasURL(sitemap, self.my_doc_url))
91
92        self.gsm_props.manage_changeProperties(portalTypes = [])
93
94        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
95        self.assert_(not hasURL(sitemap, self.my_doc_url))
96
97        self.gsm_props.manage_changeProperties(portalTypes = ['Document'])
98
99        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
100        self.assert_(hasURL(sitemap, self.my_doc_url))
101
102    def testStates(self):
103        self.workflow.doActionFor(self.my_doc, 'publish')
104        self.gsm_props.manage_changeProperties(states = ['visible'])
105
106        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
107        self.assert_(not hasURL(sitemap, self.my_doc_url))
108
109        self.gsm_props.manage_changeProperties(states = ['published'])
110
111        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
112        self.assert_(hasURL(sitemap, self.my_doc_url))
113
114    def test_blackout_entries(self):
115        self.workflow.doActionFor(self.my_doc, 'publish')
116        self.gsm_props.manage_changeProperties(blackout_list = (self.my_doc.getId(),))
117        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
118        self.assert_(not hasURL(sitemap, self.my_doc_url))
119
120        self.gsm_props.manage_changeProperties(blackout_list = [])
121        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
122        self.assert_(hasURL(sitemap, self.my_doc_url))
123
124    def test_regexp(self):
125        self.workflow.doActionFor(self.my_doc, 'publish')
126        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
127        self.assert_(not hasURL(sitemap, self.portal.absolute_url()))
128
129        regexp = "s/\/%s//"%self.my_doc.getId()
130        self.gsm_props.manage_changeProperties(reg_exp = [regexp])
131
132        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
133        self.assert_(hasURL(sitemap, self.portal.absolute_url()))
134
135    def test_add_urls(self):
136        self.gsm_props.manage_changeProperties(urls = ['http://w1', 'w2', '/w3'])
137        w1_url = 'http://w1'
138        w2_url = self.portal.absolute_url() + '/w2'
139        w3_url = self.portal.getPhysicalRoot().absolute_url() + '/w3'
140        sitemap = self.publish(self.sitemapUrl, self.auth).getBody()
141
142        self.assert_(hasURL(sitemap, w1_url))
143        self.assert_(hasURL(sitemap, w2_url))
144        self.assert_(hasURL(sitemap, w3_url))
145
146def test_suite():
147    from unittest import TestSuite, makeSuite
148    suite = TestSuite()
149    suite.addTest(makeSuite(TestqPloneGoogleSitemaps))
150    suite.addTest(makeSuite(TestSettings))
151    return suite
152
153if __name__ == '__main__':
154    framework()
Note: See TracBrowser for help on using the repository browser.