1 | |
---|
2 | """ This module contains class that tests some scripts and templates in skins directory """ |
---|
3 | |
---|
4 | import os, sys, string |
---|
5 | if __name__ == '__main__': |
---|
6 | execfile(os.path.join(sys.path[0], 'framework.py')) |
---|
7 | |
---|
8 | from commonTestingStuff import * |
---|
9 | |
---|
10 | class TestFunctional(PloneTestCase.FunctionalTestCase): |
---|
11 | """ Class for functional testing """ |
---|
12 | |
---|
13 | def afterSetUp(self): |
---|
14 | """ AfterSetUp features """ |
---|
15 | self.loginAsPortalOwner() |
---|
16 | self.membership = getToolByName(self.portal, 'portal_membership', None) |
---|
17 | self.membership.addMember('another_member', user_password , ['Member'], []) |
---|
18 | #maps_login(self, user_name) |
---|
19 | #self.auth = user_name + ':' + user_password |
---|
20 | self.auth = 'portal_owner:secret' |
---|
21 | self.map_properties = getToolByName(self.portal, 'portal_properties').maps_properties |
---|
22 | |
---|
23 | def sendRequest(self, path, params={}, method="POST"): |
---|
24 | """ Utility function """ |
---|
25 | return self.publish(path, self.auth, extra=params, request_method=method) |
---|
26 | |
---|
27 | def testPrefsMapsKeySet(self): |
---|
28 | """ Test prefs_maps_key_set.py script """ |
---|
29 | response = self.sendRequest('%s/prefs_mapkeys_set' % self.portal.id, {'map_api_keys':[NEW_MAP_KEY,]}, "POST") |
---|
30 | self.failUnlessEqual(response.getStatus(), 302) # OK |
---|
31 | self.failUnlessEqual((NEW_MAP_KEY,), self.map_properties.map_api_keys, |
---|
32 | "prefs_maps_key_set.py script work incorrect") |
---|
33 | |
---|
34 | def testGetMapKey(self): |
---|
35 | """ Test getMapKey.py script """ |
---|
36 | response = self.sendRequest('%s/prefs_mapkeys_set' % self.portal.id, {'map_api_keys':[NEW_MAP_KEY,]}, "POST") |
---|
37 | self.failUnlessEqual(response.getStatus(), 302) # OK |
---|
38 | response = self.sendRequest('%s/getMapKey' % self.portal.id) |
---|
39 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
40 | self.failUnlessEqual(response.getBody(), NEW_MAP_KEY[NEW_MAP_KEY.find('|')+1:]) |
---|
41 | |
---|
42 | def testValidatorGoodInput(self): |
---|
43 | """ Test validate_mapkeys.vpy script with good input """ |
---|
44 | from Products.CMFFormController.ControllerState import ControllerState |
---|
45 | response = self.sendRequest('%s/validate_mapkeys' % self.portal.id, |
---|
46 | {'controller_state':ControllerState(), 'map_api_keys':[NEW_MAP_KEY,]}, |
---|
47 | "POST") |
---|
48 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
49 | self.failIf(response.getBody().find('status = success') == -1, |
---|
50 | "validator didn't return success status with good input") |
---|
51 | |
---|
52 | def testValidatorBadInput(self): |
---|
53 | """ Test validate_mapkeys.vpy script with bad input """ |
---|
54 | from Products.CMFFormController.ControllerState import ControllerState |
---|
55 | response = self.sendRequest('%s/validate_mapkeys' % self.portal.id, |
---|
56 | {'controller_state':ControllerState(), 'map_api_keys':['badinput|',]}, |
---|
57 | "POST") |
---|
58 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
59 | self.failIf(response.getBody().find('status = failure') == -1, |
---|
60 | "validator didn't return success status with bad input") |
---|
61 | |
---|
62 | def test_suite(): |
---|
63 | from unittest import TestSuite, makeSuite |
---|
64 | suite = TestSuite() |
---|
65 | suite.addTest(makeSuite(TestFunctional)) |
---|
66 | return suite |
---|
67 | |
---|
68 | if __name__ == '__main__': |
---|
69 | framework() |
---|