source: products/qMemberdataExport/tags/0.0.1/tests/testFunctional.py @ 3664

Last change on this file since 3664 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1
2""" This module contains class that tests python script in portal root """
3
4import os, sys, string
5if __name__ == '__main__':
6    execfile(os.path.join(sys.path[0], 'framework.py'))
7
8from commonTestingStuff import *
9
10class 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.qi = getToolByName(self.portal, 'portal_quickinstaller')
19        self.qi.installProduct(PRODUCT)
20        self.membership = self.portal.portal_membership
21        for m in PORTAL_MEMBERS:
22            addMember(self, m['id'], m['fullname'], m['email'], m['roles'], m['last_login_time'])
23        self.response = self.sendRequest('%s/%s' % (self.portal.id, PYTHON_SCRIPT), {}, "GET")
24
25    def sendRequest(self, path, params={}, method="POST"):
26        """ Utility function """
27
28        return self.publish(path, self.auth, extra=params, request_method=method)
29
30
31    def testExportMemberdataScript(self):
32        """ Test exportMemberData python script """
33
34        forCompare = parseCSV(self, self.response.getBody())
35        self.failUnless(forCompare[0] == forCompare[1], '%s script return bad CSV value' % PYTHON_SCRIPT)
36
37    def testContentDispositionResponseHeader(self):
38        """ Test response for content-disposition header """
39
40        import re
41        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)
42        self.failUnless(pattern.search(self.response.getHeader('content-disposition')),
43                                       'Bad response header \'Content Disposition\'')
44
45    def testContentTypeResponseHeader(self):
46        """ Test response for content-type header """
47
48        self.failUnless(self.response.getHeader('content-type').find('text/csv') != -1,
49                        'Bad response header \'Content Type\'')
50
51    def testScriptSecurity(self):
52        """ Test external script 'View' permission via python script """
53
54        maps_login(self, 'anonym')
55        response = self.publish('%s/%s' % (self.portal.id, PYTHON_SCRIPT))
56
57        self.failUnless(response.getHeader('bobo-exception-type') == 'Unauthorized',
58                        'Anonymous user have access to external method via python script')
59
60def test_suite():
61    from unittest import TestSuite, makeSuite
62    suite = TestSuite()
63    suite.addTest(makeSuite(TestFunctional))
64    return suite
65
66if __name__ == '__main__':
67    framework()
Note: See TracBrowser for help on using the repository browser.