1 | import re, string |
---|
2 | from base import * |
---|
3 | |
---|
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 | open('/tmp/captcha.configlet.html','w').write(res) |
---|
42 | self.assertTrue(self.layerInSkins(LAYER_DYNAMIC_CAPTCHAS), |
---|
43 | "No '%s' skin layer in some skins" % LAYER_DYNAMIC_CAPTCHAS) |
---|
44 | |
---|
45 | def test_imageSize(self): |
---|
46 | expect = 35 |
---|
47 | self.publish(self.save_url + '&image_size=%s' % expect, |
---|
48 | self.basic_auth) |
---|
49 | |
---|
50 | imsize = self.capprops.getProperty("image_size", 0) |
---|
51 | self.assertTrue(imsize == expect, '"image_size" property ' \ |
---|
52 | 'contains: "%s", must: "%s"' % (imsize, expect)) |
---|
53 | |
---|
54 | def test_background(self): |
---|
55 | prop, expect = "background", "test-color" |
---|
56 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
57 | self.basic_auth) |
---|
58 | |
---|
59 | fact = self.capprops.getProperty(prop, "") |
---|
60 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
61 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
62 | |
---|
63 | def test_fontColor(self): |
---|
64 | prop, expect = "font_color", "test-font-color" |
---|
65 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
66 | self.basic_auth) |
---|
67 | |
---|
68 | fact = self.capprops.getProperty(prop, "") |
---|
69 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
70 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
71 | |
---|
72 | def test_period(self): |
---|
73 | prop, expect = "period", 22.3 |
---|
74 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
75 | self.basic_auth) |
---|
76 | |
---|
77 | fact = self.capprops.getProperty(prop, 0) |
---|
78 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
79 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
80 | |
---|
81 | def test_amplitude(self): |
---|
82 | prop, expect = "amplitude", 11.2 |
---|
83 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
84 | self.basic_auth) |
---|
85 | |
---|
86 | fact = self.capprops.getProperty(prop, 0) |
---|
87 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
88 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
89 | |
---|
90 | def test_random(self): |
---|
91 | prop, expect = "random_params", False |
---|
92 | self.publish(self.save_url, self.basic_auth) |
---|
93 | |
---|
94 | fact = self.capprops.getProperty(prop, None) |
---|
95 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
96 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
97 | |
---|
98 | |
---|
99 | def test_suite(): |
---|
100 | from unittest import TestSuite, makeSuite |
---|
101 | suite = TestSuite() |
---|
102 | suite.addTest(makeSuite(TestConfiglet)) |
---|
103 | return suite |
---|