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