[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Added functional
tests for many common content-space views.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Jul 13 13:31:56 EDT 2004
Log message for revision 26499:
Added functional tests for many common content-space views.
Changed:
A Zope3/trunk/src/zope/app/dtmlpage/ftests.py
A Zope3/trunk/src/zope/app/file/browser/ftests.py
A Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py
A Zope3/trunk/src/zope/app/site/browser/ftests/test_tasks.py
A Zope3/trunk/src/zope/app/sqlscript/browser/ftests.py
A Zope3/trunk/src/zope/app/zptpage/browser/ftests.py
-=-
Added: Zope3/trunk/src/zope/app/dtmlpage/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/dtmlpage/ftests.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/dtmlpage/ftests.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,120 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for DTML Page.
+
+$Id: ftests.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+from zope.app.tests.functional import BrowserTestCase
+from zope.app.dtmlpage.dtmlpage import DTMLPage
+from xml.sax.saxutils import escape
+
+class DTMLPageTest(BrowserTestCase):
+
+ content = u'<html><body><dtml-var "REQUEST.URL[1]"></body></html>'
+
+ def addDTMLPage(self):
+ dtmlpage = DTMLPage(self.content)
+ root = self.getRootFolder()
+ root['dtmlpage'] = dtmlpage
+ self.commit()
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.dtmlpage.DTMLPage=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a DTML Page' in body)
+ self.assert_('Source' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.dtmlpage.DTMLPage=',
+ 'mgr:mgrpw')
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.dtmlpage.DTMLPage=',
+ form={'type_name': u'zope.app.dtmlpage.DTMLPage',
+ 'field.source': u'<h1>A DTML Page</h1>',
+ 'add_input_name': u'dtmlpage',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('dtmlpage' in root)
+ dtmlpage = root['dtmlpage']
+ self.assertEqual(dtmlpage.source, '<h1>A DTML Page</h1>')
+
+ def testEditForm(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@edit.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a DTML page' in body)
+ self.assert_('Source' in body)
+ self.assert_(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/dtmlpage/@@edit.html', 'mgr:mgrpw')
+
+ def testEdit(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@edit.html',
+ form={'field.source': u'<h1>A DTML Page</h1>',
+ 'UPDATE_SUBMIT': u'Edit'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a DTML page' in body)
+ self.assert_('Source' in body)
+ self.assert_(escape(u'<h1>A DTML Page</h1>') in body)
+ root = self.getRootFolder()
+ dtmlpage = root['dtmlpage']
+ self.assertEqual(dtmlpage.source, '<h1>A DTML Page</h1>')
+
+ def testIndex(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(
+ body,
+ '<html><body>http://localhost/dtmlpage</body></html>')
+ self.checkForBrokenLinks(body, '/dtmlpage/@@index.html', 'mgr:mgrpw')
+
+ def testPreview(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@preview.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_(
+ '<iframe src="." height="98%" width="98%"></iframe>' in body)
+ self.checkForBrokenLinks(body, '/dtmlpage/@@preview.html', 'mgr:mgrpw')
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(DTMLPageTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/file/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/ftests.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/file/browser/ftests.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,253 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for File and Image.
+
+$Id: ftests.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+from xml.sax.saxutils import escape
+from StringIO import StringIO
+
+from zope.app.tests.functional import BrowserTestCase
+from zope.app.file.file import File
+from zope.app.file.image import Image
+from zope.app.file.tests.test_image import zptlogo
+
+class FileTest(BrowserTestCase):
+
+ content = u'File <Data>'
+
+ def addFile(self):
+ file = File(self.content)
+ root = self.getRootFolder()
+ root['file'] = file
+ self.commit()
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.file.File=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a File' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.file.File=',
+ 'mgr:mgrpw')
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.file.File=',
+ form={'type_name': u'zope.app.file.File',
+ 'field.data': StringIO('A file'),
+ 'add_input_name': u'file',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('file' in root)
+ file = root['file']
+ self.assertEqual(file.data, 'A file')
+
+ def testEditForm(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@edit.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Change a file' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/file/@@edit.html', 'mgr:mgrpw')
+
+ def testEdit(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@edit.html',
+ form={'field.data': u'<h1>A File</h1>',
+ 'field.contentType': u'text/plain',
+ 'UPDATE_SUBMIT': u'Edit'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Change a file' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_(escape(u'<h1>A File</h1>') in body)
+ root = self.getRootFolder()
+ file = root['file']
+ self.assertEqual(file.data, '<h1>A File</h1>')
+ self.assertEqual(file.contentType, 'text/plain')
+
+ def testUploadForm(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@upload.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Upload a file' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.failIf(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/file/@@upload.html', 'mgr:mgrpw')
+
+ def testUpload(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@upload.html',
+ form={'field.data': StringIO('<h1>A file</h1>'),
+ 'field.contentType': u'text/plain',
+ 'UPDATE_SUBMIT': u'Change'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Upload a file' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.failIf(escape(u'<h1>A File</h1>') in body)
+ root = self.getRootFolder()
+ file = root['file']
+ self.assertEqual(file.data, '<h1>A file</h1>')
+ self.assertEqual(file.contentType, 'text/plain')
+
+ def testIndex(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(body, self.content)
+ self.checkForBrokenLinks(body, '/file/@@index.html', 'mgr:mgrpw')
+
+ def testPreview(self):
+ self.addFile()
+ response = self.publish(
+ '/file/@@preview.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_(
+ '<iframe src="." height="98%" width="98%"></iframe>' in body)
+ self.checkForBrokenLinks(body, '/file/@@preview.html', 'mgr:mgrpw')
+
+
+class ImageTest(BrowserTestCase):
+
+ content = zptlogo
+
+ def addImage(self):
+ image = Image(self.content)
+ root = self.getRootFolder()
+ root['image'] = image
+ self.commit()
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.file.Image=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a Image' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.file.Image=',
+ 'mgr:mgrpw')
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.file.Image=',
+ form={'type_name': u'zope.app.image.Image',
+ 'field.data': StringIO(self.content),
+ 'add_input_name': u'image',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('image' in root)
+ image = root['image']
+ self.assertEqual(image.data, self.content)
+
+ def testUploadForm(self):
+ self.addImage()
+ response = self.publish(
+ '/image/@@upload.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Upload an image' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_('1 KB 16x16' in body)
+ self.checkForBrokenLinks(body, '/image/@@upload.html', 'mgr:mgrpw')
+
+ def testUpload(self):
+ self.addImage()
+ response = self.publish(
+ '/image/@@upload.html',
+ form={'field.data': StringIO(''),
+ 'UPDATE_SUBMIT': u'Change'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Upload an image' in body)
+ self.assert_('Content Type' in body)
+ self.assert_('Data' in body)
+ self.assert_('0 KB ?x?' in body)
+ root = self.getRootFolder()
+ image = root['image']
+ self.assertEqual(image.data, '')
+ self.assertEqual(image.contentType, 'image/gif')
+
+ def testIndex(self):
+ self.addImage()
+ response = self.publish(
+ '/image/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(body, self.content)
+ self.checkForBrokenLinks(body, '/image/@@index.html', 'mgr:mgrpw')
+
+ def testPreview(self):
+ self.addImage()
+ response = self.publish(
+ '/image/@@preview.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_(
+ '<iframe src="." height="98%" width="98%"></iframe>' in body)
+ self.checkForBrokenLinks(body, '/image/@@preview.html', 'mgr:mgrpw')
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(FileTest),
+ unittest.makeSuite(ImageTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/ftests.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,153 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for Security Policy's Grant screens.
+
+$Id: ftests.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+from zope.app.tests.functional import BrowserTestCase
+
+class GrantTest(BrowserTestCase):
+
+ def testGrant(self):
+ response = self.publish(
+ '/@@grant.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Grant permissions to roles' in body)
+ self.assert_('Grant roles to principals' in body)
+ self.checkForBrokenLinks(body, '/@@grant.html', 'mgr:mgrpw')
+
+
+class RolePermissionsTest(BrowserTestCase):
+
+ def testAllRolePermissionsForm(self):
+ response = self.publish(
+ '/@@AllRolePermissions.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Permissions' in body)
+ self.assert_('Manage Content' in body)
+ self.assert_('Manage Services' in body)
+ self.assert_('Roles' in body)
+ self.assert_('Site Manager' in body)
+ self.assert_('Site Member' in body)
+ self.failIf(_result in body)
+ self.checkForBrokenLinks(body, '/@@AllRolePermissions.html',
+ 'mgr:mgrpw')
+
+ def testAllRolePermissions(self):
+ response = self.publish(
+ '/@@AllRolePermissions.html',
+ form={'p0r0': 'Allow',
+ 'p0': 'zope.ManageContent',
+ 'r0': 'zope.Manager',
+ 'SUBMIT': 'Save Changes'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('<p>Settings changed' in body)
+ self.assert_(_result in body)
+
+ def testRolesWithPermissionsForm(self):
+ response = self.publish(
+ '/@@RolesWithPermissions.html?permission_to_manage=zope.View',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Roles assigned to the permission' in body)
+ self.assert_('Role' in body)
+ self.assert_('Setting' in body)
+ self.assert_('"Save Changes"' in body)
+ self.checkForBrokenLinks(body, '/@@RolesWithPermissions.html',
+ 'mgr:mgrpw')
+
+ def testRolesWithPermissionsForm(self):
+ response = self.publish(
+ '/@@RolePermissions.html?role_to_manage=zope.Manager',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Permissions assigned to the role' in body)
+ self.assert_('Allow' in body)
+ self.assert_('Deny' in body)
+ self.checkForBrokenLinks(body, '/@@RolesPermissions.html',
+ 'mgr:mgrpw')
+
+_result = '''\
+ <option value="Unset"> </option>
+ <option value="Allow" selected="selected">+</option>
+ <option value="Deny">-</option>
+'''
+
+class PrincipalRolesTest(BrowserTestCase):
+
+ def testPrincipalRolesForm(self):
+ response = self.publish(
+ '/@@PrincipalRoles.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Apply filter' in body)
+ self.assert_('Principal(s)' in body)
+ self.assert_('Role(s)' in body)
+ self.assert_('"Filter"' in body)
+ self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
+ 'mgr:mgrpw')
+
+ def testPrincipalRoles(self):
+ response = self.publish(
+ '/@@PrincipalRoles.html',
+ form={'principals': ['zope.mgr'],
+ 'roles': ['zope.Member', 'zope.Manager'],
+ 'Filter': 'Filter'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('zope.mgr' in body)
+ self.assert_('zope.Member' in body)
+ self.assert_('"APPLY"' in body)
+ self.failIf(_result in body)
+ self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
+ 'mgr:mgrpw')
+
+ def testPrincipalRolesApply(self):
+ response = self.publish(
+ '/@@PrincipalRoles.html',
+ form={'principals': ['zope.mgr'],
+ 'roles': ['zope.Member', 'zope.Manager'],
+ 'grid.zope.Member.zope.mgr': 'Allow',
+ 'APPLY': 'Apply'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Apply filter' in body)
+ self.assert_('Principal(s)' in body)
+ self.assert_('Role(s)' in body)
+ self.assert_('"Filter"' in body)
+ self.checkForBrokenLinks(body, '/@@PrincipalRoles.html',
+ 'mgr:mgrpw')
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(GrantTest),
+ unittest.makeSuite(RolePermissionsTest),
+ unittest.makeSuite(PrincipalRolesTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/site/browser/ftests/test_tasks.py
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/ftests/test_tasks.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/site/browser/ftests/test_tasks.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Site Tasks functional tests
+
+$Id: test_services.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+
+from zope.app.tests.functional import BrowserTestCase
+
+
+class TasksTest(BrowserTestCase):
+
+ def testTasks(self):
+ path = '/++etc++site/@@tasks.html'
+ response = self.publish(path, basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+
+ body = response.getBody()
+ self.assert_('Common Site Management' in body)
+ self.checkForBrokenLinks(body, path, basic='mgr:mgrpw')
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TasksTest))
+ return suite
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/sqlscript/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/sqlscript/browser/ftests.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/sqlscript/browser/ftests.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,144 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for SQL Script.
+
+$Id: ftests.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+from zope.app.tests.functional import BrowserTestCase
+from zope.app.sqlscript.sqlscript import SQLScript
+from xml.sax.saxutils import escape
+
+class SQLScriptTest(BrowserTestCase):
+
+ content = u'SELECT * FROM foo'
+
+ def addSQLScript(self):
+ sqlscript = SQLScript()
+ sqlscript.source = self.content
+ root = self.getRootFolder()
+ root['sqlscript'] = sqlscript
+ self.commit()
+
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.sqlscript.SQLScript=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a SQL Script' in body)
+ self.assert_('Connection Name' in body)
+ self.assert_('(no value)' in body)
+ self.assert_('Arguments' in body)
+ self.assert_('Source' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.assert_('"Add and Test"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.sqlscript.SQLScript=',
+ 'mgr:mgrpw')
+
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.sqlscript.SQLScript=',
+ form={'type_name': u'zope.app.sqlscript.SQLScript',
+ 'field.source': u'SELECT * FROM foo',
+ 'field.connectionName.used': u'',
+ 'field.connectionName': u'',
+ 'add_input_name': u'sqlscript',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('sqlscript' in root)
+ sqlscript = root['sqlscript']
+ self.assertEqual(sqlscript.source, self.content)
+ self.assertEqual(sqlscript.arguments, '')
+ self.assertEqual(sqlscript.connectionName, None)
+
+ response = self.publish(
+ '/+/zope.app.sqlscript.SQLScript=',
+ form={'type_name': u'zope.app.sqlscript.SQLScript',
+ 'field.source': u'SELECT * FROM foo',
+ 'field.arguments': u'table',
+ 'field.connectionName.used': u'',
+ 'field.connectionName': u'',
+ 'add_input_name': u'sqlscript1',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ root = self.getRootFolder()
+ sqlscript = root['sqlscript1']
+ self.assertEqual(sqlscript.source, 'SELECT * FROM foo')
+ self.assertEqual(sqlscript.arguments, 'table')
+ self.assertEqual(sqlscript.connectionName, None)
+
+
+ def testEditForm(self):
+ self.addSQLScript()
+ response = self.publish(
+ '/sqlscript/@@edit.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Connection Name' in body)
+ self.assert_('(no value)' in body)
+ self.assert_('Arguments' in body)
+ self.assert_('Source' in body)
+ self.assert_('Connection Name' in body)
+ self.assert_('"Change"' in body)
+ self.assert_('"Change and Test"' in body)
+ self.assert_(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/sqlscript/@@edit.html', 'mgr:mgrpw')
+
+
+ def testEdit(self):
+ self.addSQLScript()
+ response = self.publish(
+ '/sqlscript/@@edit.html',
+ form={'field.source': u'SELECT * FROM bar',
+ 'field.connectionName.used': u'',
+ 'field.connectionName': u'',
+ 'UPDATE_SUBMIT': u'Change'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit an SQL script' in body)
+ self.assert_(escape(u'SELECT * FROM bar') in body)
+ root = self.getRootFolder()
+ sqlscript = root['sqlscript']
+ self.assertEqual(sqlscript.source, 'SELECT * FROM bar')
+
+ def testTestForm(self):
+ self.addSQLScript()
+ response = self.publish(
+ '/sqlscript/@@test.html',
+ basic='mgr:mgrpw')
+ body = response.getBody()
+ self.assert_('"Test"' in body)
+ self.assert_(escape(self.content) in body)
+ self.assertEqual(response.getStatus(), 200)
+ self.checkForBrokenLinks(body, '/sqlscript/@@test.html', 'mgr:mgrpw')
+
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(SQLScriptTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: Zope3/trunk/src/zope/app/zptpage/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/browser/ftests.py 2004-07-13 17:26:37 UTC (rev 26498)
+++ Zope3/trunk/src/zope/app/zptpage/browser/ftests.py 2004-07-13 17:31:56 UTC (rev 26499)
@@ -0,0 +1,183 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for ZPT Page.
+
+$Id: ftests.py 25177 2004-06-02 13:17:31Z jim $
+"""
+import unittest
+from zope.app.tests.functional import BrowserTestCase
+from zope.app.zptpage.zptpage import ZPTPage
+from xml.sax.saxutils import escape
+
+class ZPTPageTest(BrowserTestCase):
+
+ content = u'<html><body><h1 tal:content="request/URL/1" /></body></html>'
+
+ def addZPTPage(self):
+ zptpage = ZPTPage()
+ zptpage.source = self.content
+ root = self.getRootFolder()
+ root['zptpage'] = zptpage
+ self.commit()
+
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.zptpage.ZPTPage=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a ZPT Page' in body)
+ self.assert_('Source' in body)
+ self.assert_('Expand macros' in body)
+ self.assert_('Evaluate Inline Code' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.zptpage.ZPTPage=',
+ 'mgr:mgrpw')
+
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.zptpage.ZPTPage=',
+ form={'type_name': u'zope.app.zptpage.ZPTPage',
+ 'field.source': u'<h1>A ZPT Page</h1>',
+ 'field.expand.used': u'',
+ 'field.evaluateInlineCode.used': u'',
+ 'add_input_name': u'zptpage',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('zptpage' in root)
+ zptpage = root['zptpage']
+ self.assertEqual(zptpage.source, '<h1>A ZPT Page</h1>')
+ self.assertEqual(zptpage.expand, False)
+ self.assertEqual(zptpage.evaluateInlineCode, False)
+
+ response = self.publish(
+ '/+/zope.app.zptpage.ZPTPage=',
+ form={'type_name': u'zope.app.zptpage.ZPTPage',
+ 'field.source': u'<h1>A ZPT Page</h1>\n',
+ 'field.expand.used': u'',
+ 'field.expand': u'on',
+ 'field.evaluateInlineCode.used': u'',
+ 'field.evaluateInlineCode': u'on',
+ 'add_input_name': u'zptpage1',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ root = self.getRootFolder()
+ zptpage = root['zptpage1']
+ self.assertEqual(zptpage.source, '<h1>A ZPT Page</h1>\n')
+ self.assertEqual(zptpage.expand, True)
+ self.assertEqual(zptpage.evaluateInlineCode, True)
+
+
+ def testEditForm(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@edit.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a ZPT page' in body)
+ self.assert_('Source' in body)
+ self.assert_('Expand macros' in body)
+ self.assert_(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/zptpage/@@edit.html', 'mgr:mgrpw')
+
+
+ def testEdit(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@edit.html',
+ form={'field.source': u'<h1>A ZPT Page</h1>\n',
+ 'field.expand.used': u'',
+ 'field.expand': u'on',
+ 'UPDATE_SUBMIT': u'Edit'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a ZPT page' in body)
+ self.assert_('Source' in body)
+ self.assert_(escape(u'<h1>A ZPT Page</h1>') in body)
+ root = self.getRootFolder()
+ zptpage = root['zptpage']
+ self.assertEqual(zptpage.source, '<h1>A ZPT Page</h1>\n')
+ self.assertEqual(zptpage.expand, True)
+
+ def testIndex(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(
+ body,
+ '<html><body><h1>http://localhost/zptpage</h1></body></html>\n')
+ self.checkForBrokenLinks(body, '/zptpage/@@index.html', 'mgr:mgrpw')
+
+ def testPreview(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@preview.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_(
+ '<iframe src="." height="98%" width="98%"></iframe>' in body)
+ self.checkForBrokenLinks(body, '/zptpage/@@preview.html', 'mgr:mgrpw')
+
+ def testSource(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@source.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(body, self.content)
+
+ def testInlineCode(self):
+ self.addZPTPage()
+ response = self.publish(
+ '/zptpage/@@inlineCode.html',
+ form={'field.evaluateInlineCode.used': u'',
+ 'field.evaluateInlineCode': u'on',
+ 'UPDATE_SUBMIT': u'Edit'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Inline Code' in body)
+ self.assert_('Evaluate Inline Code' in body)
+ self.checkForBrokenLinks(body, '/zptpage/@@edit.html', 'mgr:mgrpw')
+
+ response = self.publish(
+ '/zptpage/@@inlineCode.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ root = self.getRootFolder()
+ zptpage = root['zptpage']
+ self.assertEqual(zptpage.evaluateInlineCode, True)
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(ZPTPageTest),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
More information about the Zope3-Checkins
mailing list