source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testQSEOptimizerAdditionalKeywords.py @ 1608

Last change on this file since 1608 was 1608, checked in by liebster, 14 years ago

Added tests for setup using keywords

File size: 7.4 KB
Line 
1import urllib, re
2from Acquisition import aq_inner
3from base import getToolByName, FunctionalTestCase, newSecurityManager
4from config import *
5
6class TestAdditionalKeywords(FunctionalTestCase):
7
8    def afterSetUp(self):
9        self.qi = self.portal.portal_quickinstaller
10        self.qi.installProduct(PROJECT_NAME)
11        self.sp = self.portal.portal_properties.seo_properties
12        self.pu = self.portal.plone_utils
13
14        self.basic_auth = 'portal_manager:secret'
15        uf = self.app.acl_users
16        uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], [])
17        user = uf.getUserById('portal_manager')
18        if not hasattr(user, 'aq_base'):
19            user = user.__of__(uf)
20        newSecurityManager(None, user)
21
22        '''Preparation for functional testing'''
23        self.my_doc = self.portal.invokeFactory('Document', id='my_doc')
24        self.my_doc = self.portal['my_doc']
25
26    def test_default_values_radiobutton_in_configlet(self):
27        self.assertEqual(self.sp.getProperty('settings_use_keywords_sg', 0), 1)
28        self.assertEqual(self.sp.getProperty('settings_use_keywords_lg', 0), 1)
29
30    def test_changes_using_keywords_in_configlet(self):
31        for sg, lg in ((1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2)):
32            path = self.portal.id+'/@@seo-controlpanel?settingsUseKeywordsSG=%s'\
33                                '&settingsUseKeywordsLG=%s&form.submitted=1' % (sg, lg)
34            self.publish(path, self.basic_auth)
35            self.assertEqual(self.sp.getProperty('settings_use_keywords_sg', 0), sg)
36            self.assertEqual(self.sp.getProperty('settings_use_keywords_lg', 0), lg)
37
38    def test_additional_keywords_in_configlet(self):
39        quoted_keywords = urllib.quote('foo\nbar')
40        path = self.portal.id+'/@@seo-controlpanel?additionalKeywords:lines=%s&form.submitted=1'%quoted_keywords
41        self.publish(path, self.basic_auth)
42        self.assertEqual(self.sp.additional_keywords, ('foo', 'bar'))
43        self.publish(self.portal.id+'/@@seo-controlpanel?form.submitted=1', self.basic_auth)
44        self.assertEqual(self.sp.additional_keywords, ())
45
46    def test_listMetaTags_empty(self):
47        metatags = self.pu.listMetaTags(self.my_doc)
48        self.assert_('keywords' not in metatags)
49
50    def test_listMetaTags_one(self):
51        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
52        self.my_doc.manage_addProperty('qSEO_keywords', ('foo',), 'lines')
53        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
54        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="foo"\s*)){2}/>)', self.html, re.S|re.M)
55        self.assert_(m, "No 'foo' keyword find")
56
57    def test_listMetaTags_two(self):
58        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
59        self.my_doc.manage_addProperty('qSEO_keywords', ('foo', 'bar'), 'lines')
60        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
61        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:foo|bar),\s*(?:foo|bar)"\s*)){2}/>)',
62                     self.html, re.S|re.M)
63        self.assert_(m, "No 'foo, bar' keyword find")
64
65    def test_additional_keywords_in_listMetaTags_empty(self):
66        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
67        self.sp.additional_keywords = ('foo',)
68        metatags = self.pu.listMetaTags(self.my_doc)
69        self.assert_('keywords' not in metatags)
70
71    def test_additional_keywords_in_listMetaTags_one(self):
72        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
73        #self.my_doc.setText('<p>foo</p>') # XXX
74        self.sp.additional_keywords = ('foo',)
75        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
76        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="foo"\s*)){2}/>)', self.html, re.S|re.M)
77        self.assert_(m, "No 'foo' keyword find")
78
79    def test_additional_keywords_in_listMetaTags_two(self):
80        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
81        #self.my_doc.setText('<p>foo bar</p>') # XXX
82        self.sp.additional_keywords = ('foo', 'bar')
83        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
84        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:foo|bar),\s*(?:foo|bar)"\s*)){2}/>)',
85                    self.html, re.S|re.M)
86        self.assert_(m, "No 'foo, bar' keyword find")
87
88    def setup_testing_render_keywords(self):
89        self.sp.additional_keywords = (('global',))
90        self.my_doc.manage_addProperty('qSEO_keywords', ('local'), 'lines')
91        aq_inner(self.my_doc).aq_explicit.setSubject('subject')
92        html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth))
93        return html
94
95    def test_render_only_subject(self):
96        self.sp.manage_changeProperties(settings_use_keywords_sg=1, settings_use_keywords_lg=1)
97        self.html = self.setup_testing_render_keywords()
98        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="subject"\s*)){2}/>)', self.html, re.S|re.M)
99        self.assert_(m, "No 'subject' keyword find")
100
101    def test_render_subject_and_local_seokeywords(self):
102        self.sp.manage_changeProperties(settings_use_keywords_sg=1, settings_use_keywords_lg=2)
103        self.html = self.setup_testing_render_keywords()
104        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:subject|local),\s*(?:subject|local)"\s*)){2}/>)',
105                    self.html, re.S|re.M)
106        self.assert_(m, "No 'subject, local' keywords find")
107
108    def test_render_only_global_seokeywords(self):
109        self.sp.manage_changeProperties(settings_use_keywords_sg=2, settings_use_keywords_lg=1)
110        self.html = self.setup_testing_render_keywords()
111        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="global"\s*)){2}/>)', self.html, re.S|re.M)
112        self.assert_(m, "No 'global' keyword find")
113
114    def test_render_global_and_local_seokeywords(self):
115        self.sp.manage_changeProperties(settings_use_keywords_sg=2, settings_use_keywords_lg=2)
116        self.html = self.setup_testing_render_keywords()
117        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:global|local),\s*(?:global|local)"\s*)){2}/>)',
118                    self.html, re.S|re.M)
119        self.assert_(m, "No 'global, local' keywords find")
120
121    def test_render_subject_and_global_seokeywords(self):
122        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=1)
123        self.html = self.setup_testing_render_keywords()
124        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:subject|global),\s*(?:subject|global)"\s*)){2}/>)',
125                    self.html, re.S|re.M)
126        self.assert_(m, "No 'subject, global' keywords find")
127
128    def test_render_subject_and_global_and_local_seokeywords(self):
129        self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2)
130        self.html = self.setup_testing_render_keywords()
131        m = re.match('.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="(?:subject|global|local),\s*(?:subject|global|local),\s*(?:subject|global|local)"\s*)){2}/>)',
132                    self.html, re.S|re.M)
133        self.assert_(m, "No 'subject, global, local' keywords find")
134
135
136def test_suite():
137    from unittest import TestSuite, makeSuite
138    suite = TestSuite()
139    suite.addTest(makeSuite(TestAdditionalKeywords))
140    return suite
Note: See TracBrowser for help on using the repository browser.