1 | import re |
---|
2 | import string |
---|
3 | from base import * |
---|
4 | |
---|
5 | |
---|
6 | class TestConfiglet(ptc.FunctionalTestCase): |
---|
7 | |
---|
8 | def afterSetUp(self): |
---|
9 | self.sp = self.portal.portal_properties.site_properties |
---|
10 | self.basic_auth = ':'.join((portal_owner, default_password)) |
---|
11 | self.loginAsPortalOwner() |
---|
12 | self.addProduct(PRODUCT_NAME) |
---|
13 | |
---|
14 | self.capprops = self.portal.portal_properties[PROPERTY_SHEET] |
---|
15 | self.save_url = self.portal.id + \ |
---|
16 | '/prefs_captchas_setup_form?form.submitted=1' + \ |
---|
17 | '&form.button.form_submit=Save' |
---|
18 | |
---|
19 | def layerInSkins(self, layer): |
---|
20 | res = False |
---|
21 | skins = self.portal.portal_skins |
---|
22 | for skin in skins.getSkinSelections(): |
---|
23 | path = skins.getSkinPath(skin) |
---|
24 | path = map(string.strip, string.split(path, ',')) |
---|
25 | if not layer in path: |
---|
26 | return False |
---|
27 | |
---|
28 | return True |
---|
29 | |
---|
30 | def test_staticOn(self): |
---|
31 | self.publish(self.save_url + '&static_captchas=static', |
---|
32 | self.basic_auth) |
---|
33 | |
---|
34 | self.assertTrue(self.layerInSkins(LAYER_STATIC_CAPTCHAS), |
---|
35 | "No '%s' skin layer in some skins" % LAYER_STATIC_CAPTCHAS) |
---|
36 | |
---|
37 | def test_dynamicOn(self): |
---|
38 | res = self.publish(self.save_url + '&static_captchas=dynamic', |
---|
39 | self.basic_auth).getBody() |
---|
40 | |
---|
41 | self.assertTrue(self.layerInSkins(LAYER_DYNAMIC_CAPTCHAS), |
---|
42 | "No '%s' skin layer in some skins" % LAYER_DYNAMIC_CAPTCHAS) |
---|
43 | |
---|
44 | def test_imageSize(self): |
---|
45 | expect = 35 |
---|
46 | self.publish(self.save_url + '&image_size=%s' % expect, |
---|
47 | self.basic_auth) |
---|
48 | |
---|
49 | imsize = self.capprops.getProperty("image_size", 0) |
---|
50 | self.assertTrue(imsize == expect, '"image_size" property ' \ |
---|
51 | 'contains: "%s", must: "%s"' % (imsize, expect)) |
---|
52 | |
---|
53 | def test_background(self): |
---|
54 | prop, expect = "background", "test-color" |
---|
55 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
56 | self.basic_auth) |
---|
57 | |
---|
58 | fact = self.capprops.getProperty(prop, "") |
---|
59 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
60 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
61 | |
---|
62 | def test_fontColor(self): |
---|
63 | prop, expect = "font_color", "test-font-color" |
---|
64 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
65 | self.basic_auth) |
---|
66 | |
---|
67 | fact = self.capprops.getProperty(prop, "") |
---|
68 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
69 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
70 | |
---|
71 | def test_period(self): |
---|
72 | prop, expect = "period", 22.3 |
---|
73 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
74 | self.basic_auth) |
---|
75 | |
---|
76 | fact = self.capprops.getProperty(prop, 0) |
---|
77 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
78 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
79 | |
---|
80 | def test_amplitude(self): |
---|
81 | prop, expect = "amplitude", 11.2 |
---|
82 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
83 | self.basic_auth) |
---|
84 | |
---|
85 | fact = self.capprops.getProperty(prop, 0) |
---|
86 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
87 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
88 | |
---|
89 | def test_random(self): |
---|
90 | prop, expect = "random_params", False |
---|
91 | self.publish(self.save_url, self.basic_auth) |
---|
92 | |
---|
93 | fact = self.capprops.getProperty(prop, None) |
---|
94 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
95 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
96 | |
---|
97 | |
---|
98 | class TestConfigletView(ptc.FunctionalTestCase): |
---|
99 | |
---|
100 | def afterSetUp(self): |
---|
101 | self.loginAsPortalOwner() |
---|
102 | self.addProduct(PRODUCT_NAME) |
---|
103 | captcha_pref_path = self.portal.id + '/prefs_captchas_setup_form' |
---|
104 | basic_auth = portal_owner + ":" + default_password |
---|
105 | self.view = self.publish(captcha_pref_path, basic_auth).getBody() |
---|
106 | |
---|
107 | def matchinput(self, name): |
---|
108 | return re.match('.*<input\s+[^\>]*name=\"%s\"[^>]*>' % name, |
---|
109 | self.view, re.I | re.S) |
---|
110 | |
---|
111 | def test_basic_form(self): |
---|
112 | reg_expr = '.*<form\s+[^\>]*action=\"[^\"]*?'\ |
---|
113 | 'prefs_captchas_setup_form\"[^>]*>' |
---|
114 | form = re.match(reg_expr, self.view, re.I | re.S) |
---|
115 | self.assertNotEqual(form, None, |
---|
116 | "No 'Plone Captchas Setup' form present on the configlet view") |
---|
117 | self.assertNotEqual(self.matchinput('form\.button\.form_submit'), None, |
---|
118 | "No submit button on the form") |
---|
119 | self.assertNotEqual(self.matchinput('static_captchas'), None, |
---|
120 | "No static/dynamic radio button present on the configlet") |
---|
121 | |
---|
122 | def test_dynamic(self): |
---|
123 | params = ["image_size", "background", "font_color", |
---|
124 | "period", "amplitude", "random_params"] |
---|
125 | for param in params: |
---|
126 | self.assertNotEqual(self.matchinput(param), None, |
---|
127 | "'%s' form element absence on the configlet form" % param) |
---|
128 | |
---|
129 | |
---|
130 | def test_suite(): |
---|
131 | from unittest import TestSuite, makeSuite |
---|
132 | suite = TestSuite() |
---|
133 | suite.addTest(makeSuite(TestConfiglet)) |
---|
134 | suite.addTest(makeSuite(TestConfigletView)) |
---|
135 | return suite |
---|