[1] | 1 | |
---|
| 2 | """ This module contains class that tests python script in portal root """ |
---|
| 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 | |
---|
| 16 | self.auth = 'admin:secret' |
---|
| 17 | self.loginAsPortalOwner() |
---|
| 18 | self.membership = self.portal.portal_membership |
---|
| 19 | self.path = '%s/%s' % (self.portal.id, EXTERNAL_METHOD) |
---|
| 20 | for m in PORTAL_MEMBERS: |
---|
| 21 | addMember(self, m['id'], m['fullname'], m['email'], m['roles'], m['last_login_time']) |
---|
| 22 | |
---|
| 23 | def testExternalMethod(self): |
---|
| 24 | """ Test external method script for publishing """ |
---|
| 25 | |
---|
| 26 | if cmfmember_installed: |
---|
| 27 | getToolByName(self.portal, 'cmfmember_control').upgrade(swallow_errors=0) |
---|
| 28 | response = self.publish(self.path, self.auth, extra={'exclude_props':[], 'include_props':INCLUDE_PROPS}) |
---|
| 29 | forCompare = parseCSV(self, response.getBody()) |
---|
| 30 | self.failUnless(forCompare[0] == forCompare[1], '%s external method return bad CSV value' % EXTERNAL_METHOD) |
---|
| 31 | |
---|
| 32 | def testContentDispositionResponseHeader(self): |
---|
| 33 | """ Test response for content-disposition header """ |
---|
| 34 | |
---|
| 35 | import re |
---|
| 36 | pattern = re.compile(r'\s*attachment\;\s*filename=\s*memberdata\-\d{4}\-\d{2}\-\d{2}\-\d{2}\-\d{2}\-\d{2}\.csv\s*', re.I) |
---|
| 37 | response = self.publish(self.path, self.auth, extra={'exclude_props':[], 'include_props':INCLUDE_PROPS}) |
---|
| 38 | self.failUnless(pattern.search(response.getHeader('content-disposition')), |
---|
| 39 | 'Bad response header \'Content Disposition\'') |
---|
| 40 | |
---|
| 41 | def testContentTypeResponseHeader(self): |
---|
| 42 | """ Test response for content-type header """ |
---|
| 43 | |
---|
| 44 | response = self.publish(self.path, self.auth, extra={'exclude_props':[], 'include_props':INCLUDE_PROPS}) |
---|
| 45 | self.failUnless(response.getHeader('content-type').find('text/csv') != -1, |
---|
| 46 | 'Bad response header \'Content Type\'') |
---|
| 47 | |
---|
| 48 | def testExternalMethodSecurity(self): |
---|
| 49 | """ Test external method for 'View' permission """ |
---|
| 50 | |
---|
| 51 | response = self.publish(self.path, 'barney:secret') |
---|
| 52 | type_header = response.getHeader('bobo-exception-type') |
---|
| 53 | location_header = response.getHeader('location') or '' |
---|
| 54 | self.failUnless(type_header == 'Unauthorized' or location_header.find('login_form') != -1, |
---|
| 55 | 'Anonymous user have access to external method') |
---|
| 56 | |
---|
| 57 | def test_suite(): |
---|
| 58 | from unittest import TestSuite, makeSuite |
---|
| 59 | suite = TestSuite() |
---|
| 60 | suite.addTest(makeSuite(TestFunctional)) |
---|
| 61 | return suite |
---|
| 62 | |
---|
| 63 | if __name__ == '__main__': |
---|
| 64 | framework() |
---|