1 | import re, string |
---|
2 | from base import * |
---|
3 | |
---|
4 | class TestConfiglet(ptc.FunctionalTestCase): |
---|
5 | |
---|
6 | def afterSetUp(self): |
---|
7 | self.sp = self.portal.portal_properties.site_properties |
---|
8 | self.basic_auth = ':'.join((portal_owner,default_password)) |
---|
9 | self.loginAsPortalOwner() |
---|
10 | self.addProduct(PRODUCT_NAME) |
---|
11 | |
---|
12 | self.capprops = self.portal.portal_properties[PROPERTY_SHEET] |
---|
13 | self.save_url = self.portal.id + \ |
---|
14 | '/prefs_captchas_setup_form?form.submitted=1' + \ |
---|
15 | '&form.button.form_submit=Save' |
---|
16 | |
---|
17 | def layerInSkins(self, layer): |
---|
18 | res = False |
---|
19 | skins = self.portal.portal_skins |
---|
20 | for skin in skins.getSkinSelections(): |
---|
21 | path = skins.getSkinPath(skin) |
---|
22 | path = map( string.strip, string.split( path,',' )) |
---|
23 | if not layer in path: |
---|
24 | return False |
---|
25 | |
---|
26 | return True |
---|
27 | |
---|
28 | def test_staticOn(self): |
---|
29 | self.publish(self.save_url + '&static_captchas=static', |
---|
30 | self.basic_auth) |
---|
31 | |
---|
32 | self.assertTrue(self.layerInSkins(LAYER_STATIC_CAPTCHAS), |
---|
33 | "No '%s' skin layer in some skins" % LAYER_STATIC_CAPTCHAS) |
---|
34 | |
---|
35 | def test_dynamicOn(self): |
---|
36 | res = self.publish(self.save_url + '&static_captchas=dynamic', |
---|
37 | self.basic_auth).getBody() |
---|
38 | |
---|
39 | open('/tmp/captcha.configlet.html','w').write(res) |
---|
40 | self.assertTrue(self.layerInSkins(LAYER_DYNAMIC_CAPTCHAS), |
---|
41 | "No '%s' skin layer in some skins" % LAYER_DYNAMIC_CAPTCHAS) |
---|
42 | |
---|
43 | def test_imageSize(self): |
---|
44 | expect = 35 |
---|
45 | self.publish(self.save_url + '&image_size=%s' % expect, |
---|
46 | self.basic_auth) |
---|
47 | |
---|
48 | imsize = self.capprops.getProperty("image_size", 0) |
---|
49 | self.assertTrue(imsize == expect, '"image_size" property ' \ |
---|
50 | 'contains: "%s", must: "%s"' % (imsize, expect)) |
---|
51 | |
---|
52 | def test_background(self): |
---|
53 | prop, expect = "background", "test-color" |
---|
54 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
55 | self.basic_auth) |
---|
56 | |
---|
57 | fact = self.capprops.getProperty(prop, "") |
---|
58 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
59 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
60 | |
---|
61 | def test_fontColor(self): |
---|
62 | prop, expect = "font_color", "test-font-color" |
---|
63 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
64 | self.basic_auth) |
---|
65 | |
---|
66 | fact = self.capprops.getProperty(prop, "") |
---|
67 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
68 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
69 | |
---|
70 | def test_period(self): |
---|
71 | prop, expect = "period", 22.3 |
---|
72 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
73 | self.basic_auth) |
---|
74 | |
---|
75 | fact = self.capprops.getProperty(prop, 0) |
---|
76 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
77 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
78 | |
---|
79 | def test_amplitude(self): |
---|
80 | prop, expect = "amplitude", 11.2 |
---|
81 | self.publish(self.save_url + '&%s=%s' % (prop, expect), |
---|
82 | self.basic_auth) |
---|
83 | |
---|
84 | fact = self.capprops.getProperty(prop, 0) |
---|
85 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
86 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
87 | |
---|
88 | def test_random(self): |
---|
89 | prop, expect = "random_params", False |
---|
90 | self.publish(self.save_url, self.basic_auth) |
---|
91 | |
---|
92 | fact = self.capprops.getProperty(prop, None) |
---|
93 | self.assertTrue(fact == expect, '"%s" property ' \ |
---|
94 | 'contains: "%s", must: "%s"' % (prop, fact, expect)) |
---|
95 | |
---|
96 | |
---|
97 | def test_suite(): |
---|
98 | from unittest import TestSuite, makeSuite |
---|
99 | suite = TestSuite() |
---|
100 | suite.addTest(makeSuite(TestConfiglet)) |
---|
101 | return suite |
---|