1 | from quintagroup.seoptimizer.tests.base import FunctionalTestCase |
---|
2 | from Products.PloneTestCase.PloneTestCase import portal_owner, \ |
---|
3 | default_password |
---|
4 | |
---|
5 | from zope.formlib.form import FormFields |
---|
6 | from zope.schema.interfaces import IBool |
---|
7 | from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema |
---|
8 | |
---|
9 | |
---|
10 | class TestConfiglet(FunctionalTestCase): |
---|
11 | |
---|
12 | def afterSetUp(self): |
---|
13 | self.sp = self.portal.portal_properties.site_properties |
---|
14 | self.seo = self.portal.portal_properties.seo_properties |
---|
15 | self.basic_auth = ':'.join((portal_owner, default_password)) |
---|
16 | self.loginAsPortalOwner() |
---|
17 | self.save_url = self.portal.id + '/@@seo-controlpanel?' \ |
---|
18 | 'form.actions.save=1&_authenticator=%s' \ |
---|
19 | % self._getauth() |
---|
20 | |
---|
21 | def test_exposeDCMetaTags_On(self): |
---|
22 | self.publish(self.save_url + '&form.exposeDCMetaTags=on', |
---|
23 | self.basic_auth) |
---|
24 | self.assert_(self.sp.exposeDCMetaTags) |
---|
25 | |
---|
26 | def test_exposeDCMetaTags_Off(self): |
---|
27 | self.publish(self.save_url + '&form.exposeDCMetaTags=', |
---|
28 | self.basic_auth) |
---|
29 | self.assertTrue(not self.sp.exposeDCMetaTags) |
---|
30 | |
---|
31 | def test_defaultCustomMetatags_On(self): |
---|
32 | expect = ('test', 'custom', 'metatags') |
---|
33 | formdata = "\n".join(expect) |
---|
34 | self.publish(self.save_url + '&form.default_custom_metatags=%s' |
---|
35 | % formdata, self.basic_auth) |
---|
36 | |
---|
37 | dcm = self.seo.getProperty("default_custom_metatags", ()) |
---|
38 | self.assertTrue(dcm == expect, '"default_custom_metatags" property ' \ |
---|
39 | 'contains: "%s", must: "%s"' % (dcm, expect)) |
---|
40 | |
---|
41 | def test_defaultCustomMetatags_Off(self): |
---|
42 | data = ('test', 'custom', 'metatags') |
---|
43 | self.seo._updateProperty("default_custom_metatags", data) |
---|
44 | self.publish(self.save_url + '&form.default_custom_metatags=', |
---|
45 | self.basic_auth) |
---|
46 | |
---|
47 | dcm = self.seo.getProperty("default_custom_metatags", ()) |
---|
48 | self.assertTrue(dcm == (), '"default_custom_metatags" property ' \ |
---|
49 | 'contains: "%s", must be empty"' % str(dcm)) |
---|
50 | |
---|
51 | def test_metatagsOrder_On(self): |
---|
52 | expect = ('test', 'metatags', 'order') |
---|
53 | formdata = "\n".join(expect) |
---|
54 | self.publish(self.save_url + '&form.metatags_order=%s' % formdata, |
---|
55 | self.basic_auth) |
---|
56 | |
---|
57 | mo = self.seo.getProperty("metatags_order", ()) |
---|
58 | self.assertTrue(mo == expect, '"metatags_order" property ' \ |
---|
59 | 'contains: "%s", must: "%s"' % (mo, expect)) |
---|
60 | |
---|
61 | def test_metatagsOrder_Off(self): |
---|
62 | data = ('test', 'metatags', 'order') |
---|
63 | self.seo._updateProperty("metatags_order", data) |
---|
64 | self.publish(self.save_url + '&form.metatags_order=', |
---|
65 | self.basic_auth) |
---|
66 | |
---|
67 | mo = self.seo.getProperty("metatags_order", ()) |
---|
68 | self.assertTrue(mo == (), '"metatags_order" property ' \ |
---|
69 | 'contains: "%s", must be empty"' % str(mo)) |
---|
70 | |
---|
71 | def test_typesSEOEnabled_On(self): |
---|
72 | expect = 'Event' |
---|
73 | self.publish(self.save_url + "&form.types_seo_enabled=%s" % expect, |
---|
74 | self.basic_auth) |
---|
75 | tse = self.seo.getProperty("content_types_with_seoproperties", ()) |
---|
76 | self.assertTrue(tse == (expect,), |
---|
77 | '"content_types_with_seoproperties" property ' \ |
---|
78 | 'contains:" %s", must: "%s"' % (tse, expect)) |
---|
79 | |
---|
80 | def test_typesSEOEnabled_Off(self): |
---|
81 | self.publish(self.save_url + '&form.types_seo_enabled-empty-marker=1', |
---|
82 | self.basic_auth) |
---|
83 | |
---|
84 | tse = self.seo.getProperty("content_types_with_seoproperties", ()) |
---|
85 | self.assertTrue(tse == (), '"content_types_with_seoproperties" ' \ |
---|
86 | 'property contains: "%s", must be empty"' % str(tse)) |
---|
87 | |
---|
88 | def test_CustomScriptAdd(self): |
---|
89 | expect = "<script>\n<!-- Test custom script -->\n</script>" |
---|
90 | |
---|
91 | self.publish(self.save_url + '&form.custom_script=%s' % expect, |
---|
92 | self.basic_auth) |
---|
93 | |
---|
94 | cs = self.seo.getProperty("custom_script", "") |
---|
95 | self.assertTrue(cs == expect, '"custom_script" property ' \ |
---|
96 | 'contains: "%s", but "%s" must be"' % (cs, expect)) |
---|
97 | |
---|
98 | def test_CustomScriptDel(self): |
---|
99 | self.publish(self.save_url + '&form.custom_script=', |
---|
100 | self.basic_auth) |
---|
101 | |
---|
102 | cs = self.seo.getProperty("custom_script", "") |
---|
103 | self.assertTrue(cs == "", '"custom_script" property ' \ |
---|
104 | 'contains: "%s", must be empty"' % cs) |
---|
105 | |
---|
106 | def test_fieldsAdd(self): |
---|
107 | expect = ('field1', 'field2') |
---|
108 | formdata = "\n".join(expect) |
---|
109 | self.publish(self.save_url + '&form.fields=%s' % formdata, |
---|
110 | self.basic_auth) |
---|
111 | |
---|
112 | f = self.seo.getProperty("fields", ()) |
---|
113 | self.assertTrue(f == expect, '"fields" property ' \ |
---|
114 | 'contains: "%s", must: "%s"' % (f, expect)) |
---|
115 | |
---|
116 | def test_fieldsDel(self): |
---|
117 | data = ('field1', 'field2') |
---|
118 | self.seo._updateProperty("fields", data) |
---|
119 | self.publish(self.save_url + '&form.fields=', |
---|
120 | self.basic_auth) |
---|
121 | |
---|
122 | f = self.seo.getProperty("fields", ()) |
---|
123 | self.assertTrue(f == (), '"fields" property ' \ |
---|
124 | 'contains: "%s", must be empty"' % str(f)) |
---|
125 | |
---|
126 | def test_stopWordsAdd(self): |
---|
127 | expect = ('sw1', 'sw2', 'sw3') |
---|
128 | formdata = "\n".join(expect) |
---|
129 | self.publish(self.save_url + '&form.stop_words=%s' % formdata, |
---|
130 | self.basic_auth) |
---|
131 | |
---|
132 | f = self.seo.getProperty("stop_words", ()) |
---|
133 | self.assertTrue(f == expect, '"stop_words" property ' \ |
---|
134 | 'contains: "%s", must: "%s"' % (f, expect)) |
---|
135 | |
---|
136 | def test_stopWordsDel(self): |
---|
137 | data = ('sw1', 'sw2', 'sw3') |
---|
138 | self.seo._updateProperty("stop_words", data) |
---|
139 | self.publish(self.save_url + '&form.stop_words=', |
---|
140 | self.basic_auth) |
---|
141 | |
---|
142 | f = self.seo.getProperty("stop_words", ()) |
---|
143 | self.assertTrue(f == (), '"stop_words" property ' \ |
---|
144 | 'contains: "%s", must be empty"' % str(f)) |
---|
145 | |
---|
146 | def test_externalKeywordTest(self): |
---|
147 | fields = FormFields(ISEOConfigletSchema) |
---|
148 | ffield = fields.get("external_keywords_test") |
---|
149 | self.assertTrue(ffield is not None, |
---|
150 | 'Not found "external_keywords_test" field in ' \ |
---|
151 | 'ISEOConfigletSchema interface') |
---|
152 | self.assertTrue(IBool.providedBy(ffield.field), |
---|
153 | '"external_keywords_test" is not boolean type field') |
---|
154 | self.assertTrue(ffield.field.default == False, |
---|
155 | '"external_keywords_test" field default value ' \ |
---|
156 | 'is not set to False') |
---|
157 | |
---|
158 | def test_externalKeyword_On(self): |
---|
159 | self.publish(self.save_url + '&form.external_keywords_test=on', |
---|
160 | self.basic_auth) |
---|
161 | self.assert_(self.seo.external_keywords_test) |
---|
162 | |
---|
163 | def test_externalKeyword_Off(self): |
---|
164 | self.publish(self.save_url + '&form.external_keywords_test=', |
---|
165 | self.basic_auth) |
---|
166 | self.assertTrue(not self.seo.external_keywords_test) |
---|
167 | |
---|
168 | |
---|
169 | def test_suite(): |
---|
170 | from unittest import TestSuite, makeSuite |
---|
171 | suite = TestSuite() |
---|
172 | suite.addTest(makeSuite(TestConfiglet)) |
---|
173 | return suite |
---|