Author: janguenot
Date: Wed Oct  5 16:26:46 2005
New Revision: 27970

Modified:
   z3lab/Zope3Benchs/trunk/test_Zope3.py
Log:
test_00_BuddyDemoApp_RW was too big 

 Split it in 2 tests:

  - one that creates the buddy folders at the root of Zope3
  - one that find randomly a container and create the buddies
  
This way you will have a readable report (not with 165 pages) and you
can run a bench faster as you can use a short cycle duration



Modified: z3lab/Zope3Benchs/trunk/test_Zope3.py
==============================================================================
--- z3lab/Zope3Benchs/trunk/test_Zope3.py       (original)
+++ z3lab/Zope3Benchs/trunk/test_Zope3.py       Wed Oct  5 16:26:46 2005
@@ -31,6 +31,8 @@
     This test use a configuration file Zope3.conf.
     """
 
+    _buddies_folder_ids = []
+
     def setUp(self):
         """Setting up test.
         """
@@ -44,8 +46,19 @@
         # To generate words
         self._lipsum = Lipsum()
 
-        # For cleaning up at the end
-        self._buddies_folder_ids = []
+    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)
+    #
 
     def test_EmptyInstance_As_Anonymous(self):
         """Test an empty instance as anonymous user
@@ -73,10 +86,49 @@
         self.setBasicAuth(self.member_id, self.member_pwd)
         self.get("%s/" % server_url, description="Zope3 default page")
 
-    def _genBuddyFolderId(self):
-        """Generate an id for a buddy folder
+    #
+    # 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
+        """
+        self.setBasicAuth(self.admin_id, self.admin_pwd)
+        self._test_BuddyDemoApp_READ_As()
+
+    def test_BuddyDemoApp_READ_As_Member(self):
+        """Tests read only tests
+        """
+        self.setBasicAuth(self.member_id, self.member_pwd)
+        self._test_BuddyDemoApp_READ_As()
+
+    def test_BuddyDemoApp_READ_As_Anonymous(self):
+        """Tests read only tests
         """
-        return 'buddy_folder_' + self._lipsum.getUniqWord()
+        self._test_BuddyDemoApp_READ_As()
+
+    #
+    # buddydemo tests (READ/WRITE)
+    #
 
     def test_00_BuddyDemoApp_RW(self):
         """Test the buddy demo application.
@@ -88,10 +140,9 @@
 
         nb_buddies_folder = self.conf_get(
             'test_00_BuddyDemoApp_RW', 'nb_buddies_folder')
-        nb_buddies_per_folder = self.conf_get(
-            'test_00_BuddyDemoApp_RW', 'nb_buddies_per_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` "
@@ -110,120 +161,97 @@
             self.post("%s/@@+/action.html" % server_url,
                       params=params, description="Add a buddy")
 
-            # Create 500 buddies
-
-            self.get("%s/%s/@@contents.html" %(server_url, buddies_folder_id),
-                     description="View the Zope3 root content items")
-
-            i = 0
-            while i < int(nb_buddies_per_folder):
-                self.get("%s/%s/@@+" %(server_url, buddies_folder_id),
-                         description="Buddy folder `add content`page")
-
-                # Create the buddies folder
-                # Step1 : Ask for the creation given an id
-                buddy_id = self._lipsum.getUniqWord()
-                params = [
-                    ['type_name', 'AddBuddy.html'],
-                    ['id', buddy_id],
-                    ['add', ' Add '],
-                    ]
-                self.post("%s/@@+/action.html" % server_url, params,
-                          description="Request to add a buddy")
-
-                # Give informations and create the buddy
-                params = [
-                    ['type_name', 'AddBuddy.html'],
-                    ['field.first', self._lipsum.getWord()],
-                    ['field.last', self._lipsum.getWord()],
-                    ['field.email', '[EMAIL PROTECTED]'],
-                    ['field.address', self._lipsum.getAddress(lang="fr")],
-                    ['field.postal_code','75015'],
-                    ['UPDATE_SUBMIT', 'Add'],
-                    ]
-                self.post("%s/%s/+/AddBuddy.html=%s" %(server_url,
-                                                       buddies_folder_id,
-                                                       buddy_id),
-                          params=params,
-                          description="Add a buddy")
-
-                # View the buddy
-                self.get("%s/%s/@@contents.html" % (server_url,
-                                                    buddies_folder_id),
-                         description="View the buddies")
-                self.get("%s/%s/%s/@@edit.html" %(server_url,
-                                                  buddies_folder_id,
-                                                  buddy_id),
-                         description="Edit a buddy form")
-
-                # Edit back the buddy
-
-                params = [
-                    ['field.first', self._lipsum.getWord()],
-                    ['field.last', self._lipsum.getWord()],
-                    ['field.email', '[EMAIL PROTECTED]'],
-                    ['field.address', self._lipsum.getAddress()],
-                    ['field.postal_code','33000'],
-                    ['UPDATE_SUBMIT', 'Change'],
-                    ]
-
-                self.post("%s/%s/%s/@@edit.html" %(server_url,
-                                                   buddies_folder_id,
-                                                   buddy_id),
-                          params=params,
-                          description="Edit a buddy")
-                i += 1
-
-            # Delete the buddy folder
             self.get("%s/@@contents.html" % server_url,
                      description="View the contents at the root of the Zope3 "
                                  "instance")
+
             # Add this idea to the list of folders to delete
             self._buddies_folder_ids.append(buddies_folder_id)
 
             j += 1
 
-    def _test_BuddyDemoApp_READ_As(self):
-
-        server_url = self.zope_url
-
-        # Request the @@contents.html at the root of Zope3
-        self.get("%s" %(server_url),
-                 description="View the buddy folders")
-
-        # Find randomly one of the buddy folders created and try to
-        # view it
-        links = self.listHref(pattern='buddy_folder_')
-        if links:
-            index = random.randrange(len(links)-1)
-            url = links[index]
-            self.get("%s/%s" %(server_url, url),
-                     description="View a buddy folder")
+    def test_01_BuddyDemoApp_RW(self):
+        """Test the buddy demo application.
 
-    def test_BuddyDemoApp_READ_As_Manager(self):
-        """Tests read only tests 
+        The buddy demo application is a simple application involving
+        containers and objects within the container
         """
+
         self.setBasicAuth(self.admin_id, self.admin_pwd)
-        self._test_BuddyDemoApp_READ_As()
 
-    def test_BuddyDemoApp_READ_As_Member(self):
-        """Tests read only tests 
-        """
-        self.setBasicAuth(self.member_id, self.member_pwd)
-        self._test_BuddyDemoApp_READ_As()
+        nb_buddies_per_folder = self.conf_get(
+            'test_00_BuddyDemoApp_RW', 'nb_buddies_per_folder')
+
+        # Get randomly one of the buddy folders created
+        buddies_folder_url = self._getOneBuddyFolderURL()
+        self.get(buddies_folder_url, description="View a buddy folder")
+
+        i = 0
+        while i < int(nb_buddies_per_folder):
+            self.get("%s/@@+" %(buddies_folder_url),
+                     description="Buddy folder `add content`page")
+
+            # Create the buddies folder
+            # Step1 : Ask for the creation given an id
+            buddy_id = self._genBuddyId()
+            params = [
+                ['type_name', 'AddBuddy.html'],
+                ['id', buddy_id],
+                ['add', ' Add '],
+                ]
+            self.post("%s/@@+/action.html" % buddies_folder_url, params,
+                      description="Request to add a buddy")
+
+            # Give informations and create the buddy
+            params = [
+                ['type_name', 'AddBuddy.html'],
+                ['field.first', self._lipsum.getWord()],
+                ['field.last', self._lipsum.getWord()],
+                ['field.email', '[EMAIL PROTECTED]'],
+                ['field.address', self._lipsum.getAddress(lang="fr")],
+                ['field.postal_code','75015'],
+                ['UPDATE_SUBMIT', 'Add'],
+                ]
+            self.post("%s/+/AddBuddy.html=%s" %(buddies_folder_url, buddy_id),
+                      params=params,
+                      description="Add a buddy")
+
+            # View the buddy
+            self.get("%s/@@contents.html" % buddies_folder_url,
+                     description="View the buddies")
+            self.get("%s/%s/@@edit.html" % (buddies_folder_url, buddy_id),
+                     description="Edit a buddy form")
+
+            # Edit back the buddy
+
+            params = [
+                ['field.first', self._lipsum.getWord()],
+                ['field.last', self._lipsum.getWord()],
+                ['field.email', '[EMAIL PROTECTED]'],
+                ['field.address', self._lipsum.getAddress()],
+                ['field.postal_code','33000'],
+                ['UPDATE_SUBMIT', 'Change'],
+                ]
+
+            self.post("%s/%s/@@edit.html" % (buddies_folder_url, buddy_id),
+                      params=params,
+                      description="Edit a buddy")
+            i += 1
 
     def test_ZZZ_RemoveBuddyFolders(self):
         """Remove all the created buddy folders
         """
         server_url = self.zope_url
         self.setBasicAuth(self.admin_id, self.admin_pwd)
+        ids = self._buddies_folder_ids
         params = [
             ['container_delete_button', 'Delete'],
-            ['ids:list', self._buddies_folder_ids],
-                ]
+            ['ids:list', ids]
+            ]
         self.post("%s/@@contents.html" % server_url,
                   params=params,
                   description="Delete several buddy folders")
+        self._buddies_folder_ids = []
 
     def tearDown(self):
         """Setting down test.
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to