Author: reebalazs
Date: Sat Mar 29 00:00:20 2008
New Revision: 53069

Added:
   
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-test.pt
   (contents, props changed)
   
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-ui.pt
   (contents, props changed)
   kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/setupbase.py   
(contents, props changed)
Modified:
   kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/configure.zcml
   kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py
Log:
Continue demo extension with porting over the templates we put into 
plone.app.kss

Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/configure.zcml
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/configure.zcml  
(original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/configure.zcml  Sat Mar 
29 00:00:20 2008
@@ -114,5 +114,23 @@
       />
 
 
+  <!-- Resources needed for the special testcase
+       that can be used for site creation
+  -->
+
+  <page
+      for="kss.demo.interfaces.ISimpleContent"
+      template="kss-selenium-create-sandbox-test.pt"
+      name="kss-selenium-create-sandbox-test.html"
+      permission="zope.View"
+      />
+
+  <page
+      for="kss.demo.interfaces.ISimpleContent"
+      template="kss-selenium-create-sandbox-ui.pt"
+      name="kss-selenium-create-sandbox-ui.html"
+      permission="zope.View"
+      />
+
 </configure>
 

Added: 
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-test.pt
==============================================================================
--- (empty file)
+++ 
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-test.pt
     Sat Mar 29 00:00:20 2008
@@ -0,0 +1,43 @@
+
+<html xmlns="http://www.w3.org/1999/xhtml";
+      xmlns:tal="http://xml.zope.org/namespaces/tal";
+      xmlns:metal="http://xml.zope.org/namespaces/metal";>
+
+<head profile="http://selenium-ide.openqa.org/profiles/test-case";>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>test-create-site-suite</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">test-create-site-suite</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td tal:define="method_name request/method_name | nothing;
+                    admin_username request/admin_username | nothing;
+                    admin_password request/admin_password | nothing"
+        tal:content="string: 
${context/@@absolute_url}/demo/@@kss-selenium-create-sandbox-ui.html?method_name=${method_name}&amp;admin_username=${admin_username}&amp;admin_password=${admin_password}">
+    </td>
+       <td></td>
+</tr>
+<tr>
+       <td>setTimeout</td>
+       <td>120000</td>
+       <td></td>
+</tr>
+<tr>
+       <td>clickAndWait</td>
+       <td>create</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertTextPresent</td>
+       <td>OK</td>
+       <td>id=ok</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>

Added: 
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-ui.pt
==============================================================================
--- (empty file)
+++ 
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/kss-selenium-create-sandbox-ui.pt
       Sat Mar 29 00:00:20 2008
@@ -0,0 +1,79 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml";
+      xmlns:kukit="http://www.kukit.org/commands/1.0";
+      xmlns:tal="http://xml.zope.org/namespaces/tal";
+      xmlns:metal="http://xml.zope.org/namespaces/metal";
+      xmlns:i18n="http://xml.zope.org/namespaces/i18n";>
+  <head>
+
+       <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+
+    <!-- To achieve an uniform look, we apply the same css as the 
kss_devel_mode ui. -->
+    <link rel="stylesheet" type="text/css"
+          tal:attributes="href 
string:${context/@@absolute_url}/@@kss_devel_mode/ui_css"/>
+
+</head>
+  <body tal:define="method_name request/method_name | nothing;
+                    admin_username request/admin_username | nothing;
+                    admin_password request/admin_password |nothing;
+                    has_credentials python: admin_username and admin_password">
+
+    <h2>Creation of Plone test site (SETUP)</h2>
+    
+    <tal:condition condition="has_credentials">
+
+      <p>
+        By clicking of the following button, the <code>ksstestportal</code> 
will be
+        created in the Zope root. If there is an existing site (or object) 
with this id,
+        it will be removed first, without any further question.
+      </p>
+
+      <p class="help">
+        The site recreation will happen with full Manager rights. You do not 
need
+        to log in or otherwise supply a password for this, because this page 
+        already holds the necessary credentials for becoming Manager, when the 
button is clicked.
+      </p>
+
+      
+      <form name="create" method="post"
+          tal:attributes="action 
string:${context/@@absolute_url}/${method_name}">
+        <fieldset>
+          <h3>
+            Create Plone test site
+          </h3>
+
+          <p class="help">
+              If the site creation succeeds, you will receive an OK message as 
a response.
+              If there was an error, the script will tell you details about 
the error happened.
+              Otherwise, you need consult the event logs of your server.
+          </p>
+
+          <div>
+            <input type="hidden" name="admin_username" 
+                   tal:attributes="value admin_username" />
+            <input type="hidden" name="admin_password" 
+                   tal:attributes="value admin_password" />
+            <input type="submit" id="create" name="create" class="clickable"
+                 value="Create"  />
+          </div>
+
+        </fieldset>
+      </form>
+      
+    </tal:condition>
+
+    <tal:condition condition="not: has_credentials">
+
+      <p>
+        The page does not contain the credentials needed to become a Manager, 
required
+        to achieve the site creation. There is chance that you have arrived to 
this page
+        by mistake. This page is normally run from a selenium testsuite, where 
this
+        imformation is provided through the <code>admin_username</code> 
+        and <code>admin_password</code> parameters, together with 
+        providing a valid <code>method_name</code> parameter as well.
+      </p>
+
+    </tal:condition>
+
+  </body>
+</html>

Added: kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/setupbase.py
==============================================================================
--- (empty file)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/setupbase.py    Sat Mar 
29 00:00:20 2008
@@ -0,0 +1,58 @@
+try:
+    from Products.Five import BrowserView
+    BrowserView = BrowserView   # satisfy pyflakes
+except ImportError:
+    from zope.publisher.browser import BrowserView
+
+from Acquisition import aq_parent
+from OFS.interfaces import IApplication
+from AccessControl import getSecurityManager
+from AccessControl.SecurityManagement import setSecurityManager, 
newSecurityManager
+
+class SetupBase(BrowserView):
+    """This class provides the basic bootstrap set for every
+    test suite bootstrapping. You must inherit from this class
+    and override just the run method"""
+
+    _required_role = 'Manager'
+
+    def __init__(self, context, request):
+        super(SetupBase, self).__init__(context, request)
+        #go up to the root
+        parent = aq_parent(self.context.aq_inner)
+        while not IApplication.providedBy(parent):
+            try:
+                parent = parent.aq_parent
+            except AttributeError:
+                break
+        self.zoperoot = [parent]
+
+    def checkPermission(self, zoperoot):
+        # The form must be submitted by POST, and authenticate correctly.
+        method = self.request.get("REQUEST_METHOD", "GET").upper()
+        username = self.request.get("admin_username", None)
+        password = self.request.get("admin_password", None)
+        if method == "POST" and username is not None and password is not None:
+            admin = zoperoot.acl_users.authenticate(username, password, None)
+            if self._required_role in admin.getRoles():
+                return admin
+        return None
+    
+    def run(self, zoperoot):
+        """Just override me"""
+        raise Exception("Functionality not implemented")
+
+    def start(self):
+        zoperoot = self.zoperoot[0]
+        user = self.checkPermission(zoperoot)
+        if user is not None:
+            old_sm = getSecurityManager()
+            wrapped_user = user.__of__(zoperoot.acl_users)
+            newSecurityManager(self.request, wrapped_user)
+            result = self.run(zoperoot)
+            setSecurityManager(old_sm)
+            return result
+        else:
+            raise Exception("You are trying to run potentially disruptive code 
without providing a good auth")
+
+    __call__ = start

Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py     (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py     Sat Mar 29 
00:00:20 2008
@@ -124,6 +124,37 @@
     def get_relative_urls(self):
         return ()
 
+
+class KSSSandboxCreationTestCase(KSSSeleniumTestCaseCollectionBase):
+    """A method that can be used for sandbox creation.
+    
+    It is a factory-generated test. It visits a page with a button
+    that submits to the server side method that carries out the site
+    creation. After this method is run, the test also checks if it 
+    has completed without an error.
+
+    This method handles the admin credentials needed for the site creation
+    in a special way, because we cannot log in the admin user on the
+    HTTP authentication (Zope) level. Therefore the credentials must
+    be passed to the script as parameters, and it checks those.
+    It also requires that a POST method is used, to avoid an accidental
+    triggering.
+    """
+    implements(IKSSSeleniumTestCaseCollection)
+
+    def __init__(self, method_name):
+        self.method_name = method_name
+
+    def get_testcase_paths(self):
+        return ()
+
+    def get_relative_urls(self):
+        relative_url = 
"@@kss-selenium-create-sandbox-suite.html?method_name=%s&admin_username=%s&admin_password=%s"
 % (
+                        self.method_name,
+                        self.request.get('admin_username', ''),
+                        self.request.get('admin_password', ''))
+        return (relative_url, )
+
 # --
 # The Suite itself is a collection, but provides a way to use layers with 
setup and
 # tesrdown from the registry.
@@ -133,6 +164,9 @@
     setup = KSSSeleniumEmptyTestCase()
     teardown = KSSSeleniumEmptyTestCase()
 
+# XXX TODO Currently the test suite handles the setup and teardown
+# of the layer. The suites with the same layer should have a common
+# setup. Very easy to implement.
 class KSSSeleniumTestSuite(object):
     """Represents a single selenium test case,
     specified by its filename.
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to