Author: janguenot
Date: Wed Oct  5 17:07:23 2005
New Revision: 27973

Modified:
   z3lab/Zope3Benchs/trunk/test_Zope3.py
Log:
Cleanups

Modified: z3lab/Zope3Benchs/trunk/test_Zope3.py
==============================================================================
--- z3lab/Zope3Benchs/trunk/test_Zope3.py       (original)
+++ z3lab/Zope3Benchs/trunk/test_Zope3.py       Wed Oct  5 17:07:23 2005
@@ -15,16 +15,38 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 # 02111-1307, USA.
 #
-"""Simple funkload zope3 tests
+"""Funkload Zope3 tests
+
+The aims of this test case is to be able to get bench out of this
+tests using Funkload.
+
+Run this against the Zope3 trunk (3.2)
+
+Note, you'll need the buddydemo component
 
 $Id$
 """
+
 import unittest
 import random
 
 from funkload.FunkLoadTestCase import FunkLoadTestCase
 from funkload.Lipsum import Lipsum
 
+DEFAULT_PAGE_DESCRIPTION = "Zope3 default page"
+ROOT_ADD_CONTENT_PAGE = "Zope3 root `add content` form"
+
+BUDDY_FOLDER_VIEW = "View a buddy folder"
+BUBDDY_FOLDER_ADD_CONTENT_PAGE = "Buddy folder `add content` form"
+
+BUDDY_ADD_FORM = "Form to add a buddy"
+BUDDY_ADD = "Add a buddy"
+BUDDY_EDIT_FORM = "Form to edit a buddy"
+BUDDY_EDIT = "Edit a buddy"
+
+BUDDY_FOLDER_PREFIX = 'funk_buddy_folder_'
+BUDDY_PREFIX = 'funk_buddy_folder_'
+
 class Zope3(FunkLoadTestCase):
     """Testing Zope3
 
@@ -46,107 +68,71 @@
         # To generate words
         self._lipsum = Lipsum()
 
-    def _genBuddyFolderId(self):
-        """Generate an id for a buddy folder
-        """
-        return 'funk_buddy_folder_' + self._lipsum.getUniqWord()
-
-    def _genBuddyId(self):
-        """Generate an id for a buddy
-        """
-        return 'funk_buddy_' + self._lipsum.getUniqWord()
-
     #
-    # Default page tests (READ ONLY)
+    # Default Zope3 page tests (READ ONLY)
     #
 
-    def test_EmptyInstance_As_Anonymous(self):
-        """Test an empty instance as anonymous user
-
-        This request the default Zope3 page
+    def test_DefaultZ3Page_As_Anonymous(self):
+        """This requests the default Zope3 page as anonymous
         """
-        server_url = self.zope_url
-        self.get("%s/" % server_url, description="Zope3 default page")
-
-    def test_EmptyInstance_As_Manager(self):
-        """Test an ampty instance as Manager
+        self.get(self.zope_url, description=DEFAULT_PAGE_DESCRIPTION)
 
-        This request the default Zope3 page
+    def test_DefaultZ3Page_As_Manager(self):
+        """This requests the default Zope3 page as a Manager
         """
-        server_url = self.zope_url
         self.setBasicAuth(self.admin_id, self.admin_pwd)
-        self.get("%s/" % server_url, description="Zope3 default page")
+        self.get(self.zope_url, description=DEFAULT_PAGE_DESCRIPTION)
 
     def test_EmptyInstance_As_Member(self):
-        """Test an ampty instance as Member
-
-        This request the default Zope3 page
+        """This requests the default Zope3 page as a Member
         """
-        server_url = self.zope_url
         self.setBasicAuth(self.member_id, self.member_pwd)
-        self.get("%s/" % server_url, description="Zope3 default page")
+        self.get(self.zope_url, description=DEFAULT_PAGE_DESCRIPTION)
 
     #
     # buddydemo app tests. (READ ONLY)
     #
 
-    def _getAllBuddyFolderLinksAtRoot(self):
-        server_url = self.zope_url
-        self.get("%s" %server_url, description="View the buddy folders")
-        return self.listHref(pattern='funk_buddy_folder_')
-
-    def _getOneBuddyFolderURL(self):
-        server_url = self.zope_url
-        links = self._getAllBuddyFolderLinksAtRoot()
-        if links:
-            index = random.randrange(len(links)-1)
-            url = links[index]
-            return server_url + '/' + url
-        return server_url
-
-    def _test_BuddyDemoApp_READ_As(self):
-        server_url = self.zope_url
-        url = self._getOneBuddyFolderURL()
-        self.get(url, description="View a buddy folder")
-
     def test_BuddyDemoApp_READ_As_Manager(self):
-        """Tests read only tests
+        """As Manager, Request randomly the view of one of the buddy
+        folders created
         """
         self.setBasicAuth(self.admin_id, self.admin_pwd)
-        self._test_BuddyDemoApp_READ_As()
+        self._viewOneBuddyFolder()
 
     def test_BuddyDemoApp_READ_As_Member(self):
-        """Tests read only tests
+        """As Member, Request randomly the view of one of the buddy
+        folders created
         """
         self.setBasicAuth(self.member_id, self.member_pwd)
-        self._test_BuddyDemoApp_READ_As()
+        self._viewOneBuddyFolder()
 
     def test_BuddyDemoApp_READ_As_Anonymous(self):
-        """Tests read only tests
+        """As Anonymous user, Request randomly the view of one of the
+        buddy folders created
         """
-        self._test_BuddyDemoApp_READ_As()
+        self._viewOneBuddyFolder()
 
     #
     # buddydemo tests (READ/WRITE)
     #
+    # The buddy demo application is a simple application involving
+    # containers and objects within the container
+    #
 
     def test_00_BuddyDemoApp_RW(self):
-        """Test the buddy demo application.
-
-        The buddy demo application is a simple application involving
-        containers and objects within the container
+        """As Manager, create buddy folders
         """
+
+        self.setBasicAuth(self.admin_id, self.admin_pwd)
+
         server_url = self.zope_url
 
         nb_buddies_folder = self.conf_get(
             'test_00_BuddyDemoApp_RW', 'nb_buddies_folder')
 
-        self.setBasicAuth(self.admin_id, self.admin_pwd)
-
-        self.get("%s/" % server_url, description="Zope3 default page")
-        self.get("%s/@@+" % server_url,
-                 description="Zope3 `add content page` "
-                             "at the root of the instance")
+        self.get("%s/" % server_url, description=DEFAULT_PAGE_DESCRIPTION)
+        self.get("%s/@@+" % server_url, description=ROOT_ADD_CONTENT_PAGE)
 
         j = 0
         while j < int(nb_buddies_folder):
@@ -159,11 +145,10 @@
                 ['add', 'Add'],
                 ]
             self.post("%s/@@+/action.html" % server_url,
-                      params=params, description="Add a buddy")
+                      params=params, description=BUDDY_ADD_FORM)
 
             self.get("%s/@@contents.html" % server_url,
-                     description="View the contents at the root of the Zope3 "
-                                 "instance")
+                     description=DEFAULT_PAGE_DESCRIPTION)
 
             # Add this idea to the list of folders to delete
             self._buddies_folder_ids.append(buddies_folder_id)
@@ -171,10 +156,8 @@
             j += 1
 
     def test_01_BuddyDemoApp_RW(self):
-        """Test the buddy demo application.
-
-        The buddy demo application is a simple application involving
-        containers and objects within the container
+        """As Manager, create buddies within a randomly created buddy
+        folder
         """
 
         self.setBasicAuth(self.admin_id, self.admin_pwd)
@@ -184,12 +167,12 @@
 
         # Get randomly one of the buddy folders created
         buddies_folder_url = self._getOneBuddyFolderURL()
-        self.get(buddies_folder_url, description="View a buddy folder")
+        self.get(buddies_folder_url, description=BUDDY_FOLDER_VIEW)
 
         i = 0
         while i < int(nb_buddies_per_folder):
             self.get("%s/@@+" %(buddies_folder_url),
-                     description="Buddy folder `add content`page")
+                     description=BUBDDY_FOLDER_ADD_CONTENT_PAGE)
 
             # Create the buddies folder
             # Step1 : Ask for the creation given an id
@@ -200,7 +183,7 @@
                 ['add', ' Add '],
                 ]
             self.post("%s/@@+/action.html" % buddies_folder_url, params,
-                      description="Request to add a buddy")
+                      description=BUDDY_ADD_FORM)
 
             # Give informations and create the buddy
             params = [
@@ -213,14 +196,13 @@
                 ['UPDATE_SUBMIT', 'Add'],
                 ]
             self.post("%s/+/AddBuddy.html=%s" %(buddies_folder_url, buddy_id),
-                      params=params,
-                      description="Add a buddy")
+                      params=params, description=BUDDY_ADD)
 
             # View the buddy
             self.get("%s/@@contents.html" % buddies_folder_url,
-                     description="View the buddies")
+                     description=BUDDY_FOLDER_VIEW)
             self.get("%s/%s/@@edit.html" % (buddies_folder_url, buddy_id),
-                     description="Edit a buddy form")
+                     description=BUDDY_EDIT_FORM)
 
             # Edit back the buddy
 
@@ -234,8 +216,7 @@
                 ]
 
             self.post("%s/%s/@@edit.html" % (buddies_folder_url, buddy_id),
-                      params=params,
-                      description="Edit a buddy")
+                      params=params, description=BUDDY_EDIT)
             i += 1
 
     def test_ZZZ_RemoveBuddyFolders(self):
@@ -255,10 +236,45 @@
 
     def tearDown(self):
         """Setting down test.
-
-        Remove the buddy folders created during the test
         """
         self.logd("tearDown.")
 
+    #
+    # PRIVATE
+    #
+
+    def _genBuddyFolderId(self):
+        """Generate an id for a buddy folder
+        """
+        return BUDDY_FOLDER_PREFIX + self._lipsum.getUniqWord()
+
+    def _genBuddyId(self):
+        """Generate an id for a buddy
+        """
+        return BUDDY_PREFIX + self._lipsum.getUniqWord()
+
+    def _getAllBuddyFolderLinksAtRoot(self):
+        """Returns all the buddy folder ids at the Zope3 root
+        """
+        self.get(self.zope_url, description=DEFAULT_PAGE_DESCRIPTION)
+        return self.listHref(pattern=BUDDY_FOLDER_PREFIX)
+
+    def _getOneBuddyFolderURL(self):
+        """Returns randomly one buddy folder url at the root of Zope3
+        """
+        server_url = self.zope_url
+        links = self._getAllBuddyFolderLinksAtRoot()
+        if links:
+            index = random.randrange(len(links)-1)
+            url = links[index]
+            return server_url + '/' + url
+        return server_url
+
+    def _viewOneBuddyFolder(self):
+        """Request randomly a buddy folder page view
+        """
+        url = self._getOneBuddyFolderURL()
+        self.get(url, description=BUDDY_FOLDER_VIEW)
+
 if __name__ in ('main', '__main__'):
     unittest.main()
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to