[1] | 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 | self.auth = 'portal_owner:secret' |
---|
| 19 | self.folder.invokeFactory('Document', 'test_page') |
---|
| 20 | self.page = self.folder.test_page |
---|
| 21 | |
---|
| 22 | def sendRequest(self, path, params={}, method="POST"): |
---|
| 23 | """ Utility function """ |
---|
| 24 | return self.publish(path, self.auth, extra=params, request_method=method) |
---|
| 25 | |
---|
| 26 | def testSaveLocation(self): |
---|
| 27 | """ Test save_location.cpy script """ |
---|
| 28 | response = self.sendRequest('%s/save_location' % self.page.absolute_url_path(), |
---|
| 29 | {'latitude' : LATITUDE, |
---|
| 30 | 'longitude' : LONGITUDE, |
---|
| 31 | 'maplatitude' : MAP_CENTER[0], |
---|
| 32 | 'maplongitude' : MAP_CENTER[1], |
---|
| 33 | 'mapzoom' : MAP_ZOOM, |
---|
| 34 | 'maptype' : MAP_TYPE}, "POST") |
---|
| 35 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
| 36 | self.failUnlessEqual(IGEOLocated(self.page).getLatitude(), LATITUDE, |
---|
| 37 | "save_location.cpy script work incorrectly") |
---|
| 38 | self.failUnlessEqual(IGEOMap(self.page).getMapCenter(), MAP_CENTER, |
---|
| 39 | "save_location.cpy script work incorrectly") |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | def testLocationValidatorGoodInput(self): |
---|
| 43 | """ Test validate_location.vpy script with good input """ |
---|
| 44 | from Products.CMFFormController.ControllerState import ControllerState |
---|
| 45 | response = self.sendRequest('%s/validate_location' % self.portal.id, |
---|
| 46 | {'controller_state' : ControllerState(), |
---|
| 47 | 'latitude' : LATITUDE, |
---|
| 48 | 'longitude' : LONGITUDE}, "POST") |
---|
| 49 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
| 50 | self.failIf(response.getBody().find('status = success') == -1, |
---|
| 51 | "location validator didn't return success status with good input") |
---|
| 52 | |
---|
| 53 | def testLocationValidatorBadInput(self): |
---|
| 54 | """ Test validate_location.vpy script with bad input """ |
---|
| 55 | from Products.CMFFormController.ControllerState import ControllerState |
---|
| 56 | response = self.sendRequest('%s/validate_location' % self.portal.id, |
---|
| 57 | {'controller_state' : ControllerState(), |
---|
| 58 | 'latitude' : 90.1, |
---|
| 59 | 'longitude' : LONGITUDE}, "POST") |
---|
| 60 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
| 61 | self.failIf(response.getBody().find('status = failure') == -1, |
---|
| 62 | "location validator didn't return failure status with bad input") |
---|
| 63 | |
---|
| 64 | def testMapValidatorGoodInput(self): |
---|
| 65 | """ Test validate_map.vpy script with good input """ |
---|
| 66 | from Products.CMFFormController.ControllerState import ControllerState |
---|
| 67 | response = self.sendRequest('%s/validate_map' % self.portal.id, |
---|
| 68 | {'controller_state' : ControllerState(), |
---|
| 69 | 'maplatitude' : LATITUDE, |
---|
| 70 | 'maplongitude' : LONGITUDE, |
---|
| 71 | 'mapzoom' : MAP_ZOOM, |
---|
| 72 | 'maptype' : MAP_TYPE}, "POST") |
---|
| 73 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
| 74 | self.failIf(response.getBody().find('status = success') == -1, |
---|
| 75 | "map validator didn't return success status with good input") |
---|
| 76 | |
---|
| 77 | def testMapValidatorBadInput(self): |
---|
| 78 | """ Test validate_map.vpy script with bad input """ |
---|
| 79 | from Products.CMFFormController.ControllerState import ControllerState |
---|
| 80 | response = self.sendRequest('%s/validate_map' % self.portal.id, |
---|
| 81 | {'controller_state' : ControllerState(), |
---|
| 82 | 'maplatitude' : LATITUDE, |
---|
| 83 | 'maplongitude' : -180.05, |
---|
| 84 | 'mapzoom' : MAP_ZOOM, |
---|
| 85 | 'maptype' : MAP_TYPE}, "POST") |
---|
| 86 | self.failUnlessEqual(response.getStatus(), 200) # OK |
---|
| 87 | self.failIf(response.getBody().find('status = failure') == -1, |
---|
| 88 | "map validator didn't return failure status with bad input") |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | def test_suite(): |
---|
| 92 | from unittest import TestSuite, makeSuite |
---|
| 93 | suite = TestSuite() |
---|
| 94 | suite.addTest(makeSuite(TestFunctional)) |
---|
| 95 | return suite |
---|
| 96 | |
---|
| 97 | if __name__ == '__main__': |
---|
| 98 | framework() |
---|