source: products/quintagroup.captcha.core/trunk/quintagroup/captcha/core/tests/testConfiglet.py @ 2447

Last change on this file since 2447 was 2447, checked in by mylan, 14 years ago

#196: Added test for configlet view

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1import re, string
2from base import *
3
4class 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        self.assertTrue(self.layerInSkins(LAYER_DYNAMIC_CAPTCHAS),
40            "No '%s' skin layer in some skins" % LAYER_DYNAMIC_CAPTCHAS)
41
42    def test_imageSize(self):
43        expect = 35
44        self.publish(self.save_url + '&image_size=%s' % expect,
45             self.basic_auth)
46
47        imsize = self.capprops.getProperty("image_size", 0)
48        self.assertTrue(imsize == expect, '"image_size" property ' \
49            'contains: "%s", must: "%s"' % (imsize, expect))
50
51    def test_background(self):
52        prop, expect = "background", "test-color"
53        self.publish(self.save_url + '&%s=%s' % (prop, expect),
54             self.basic_auth)
55
56        fact = self.capprops.getProperty(prop, "")
57        self.assertTrue(fact == expect, '"%s" property ' \
58            'contains: "%s", must: "%s"' % (prop, fact, expect))
59
60    def test_fontColor(self):
61        prop, expect = "font_color", "test-font-color"
62        self.publish(self.save_url + '&%s=%s' % (prop, expect),
63             self.basic_auth)
64
65        fact = self.capprops.getProperty(prop, "")
66        self.assertTrue(fact == expect, '"%s" property ' \
67            'contains: "%s", must: "%s"' % (prop, fact, expect))
68
69    def test_period(self):
70        prop, expect = "period", 22.3
71        self.publish(self.save_url + '&%s=%s' % (prop, expect),
72             self.basic_auth)
73
74        fact = self.capprops.getProperty(prop, 0)
75        self.assertTrue(fact == expect, '"%s" property ' \
76            'contains: "%s", must: "%s"' % (prop, fact, expect))
77
78    def test_amplitude(self):
79        prop, expect = "amplitude", 11.2
80        self.publish(self.save_url + '&%s=%s' % (prop, expect),
81             self.basic_auth)
82
83        fact = self.capprops.getProperty(prop, 0)
84        self.assertTrue(fact == expect, '"%s" property ' \
85            'contains: "%s", must: "%s"' % (prop, fact, expect))
86
87    def test_random(self):
88        prop, expect = "random_params", False
89        self.publish(self.save_url, self.basic_auth)
90
91        fact = self.capprops.getProperty(prop, None)
92        self.assertTrue(fact == expect, '"%s" property ' \
93            'contains: "%s", must: "%s"' % (prop, fact, expect))
94
95
96class TestConfigletView(ptc.FunctionalTestCase):
97
98    def afterSetUp(self):
99        self.loginAsPortalOwner()
100        self.addProduct(PRODUCT_NAME)
101        self.view = self.publish(self.portal.id+'/prefs_captchas_setup_form',
102                                 portal_owner+":"+default_password).getBody()
103 
104    def matchinput(self, name):
105        return re.match('.*<input\s+[^\>]*name=\"%s\"[^>]*>' % name,
106                        self.view, re.I|re.S)
107
108    def test_basic_form(self):
109        form = re.match('.*<form\s+[^\>]*action=\"[^\"]*?prefs_captchas_setup_form\"[^>]*>',
110                        self.view, re.I|re.S)
111        self.assertNotEqual(form, None,
112            "No 'Plone Captchas Setup' form present on the configlet view")
113        self.assertNotEqual(self.matchinput('form\.button\.form_submit'), None,
114            "No submit button on the form")
115        self.assertNotEqual(self.matchinput('static_captchas'), None,
116            "No static/dynamic radio button present on the configlet")
117
118    def test_dynamic(self):
119        params = ["image_size", "background", "font_color",
120                  "period", "amplitude", "random_params"]
121        for param in params:
122            self.assertNotEqual(self.matchinput(param), None,
123                "'%s' form element absence on the configlet form" % param)
124       
125
126def test_suite():
127    from unittest import TestSuite, makeSuite
128    suite = TestSuite()
129    suite.addTest(makeSuite(TestConfiglet))
130    suite.addTest(makeSuite(TestConfigletView))
131    return suite
Note: See TracBrowser for help on using the repository browser.