Author: jvloothuis
Date: Wed Nov 14 23:32:07 2007
New Revision: 48693

Added:
   kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/
   
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/basic_commands.kss
   
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/focus.html
Modified:
   kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/config.py
   
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/corecommands.py
   kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/testing.py
Log:

The HTML template now generates links to the KSS Javascript and KSS
resource for a test.

Implemented the loading of the KSS Javascript. All Javascript include
the extras is concatinatinated into one big file.

Loading of KSS resources works.

Server handlers now work. There is an example of this in the core
plugin config.

Together all this means that we have all the (primitive) ingredients
for testing KSS without depending on a full webframework.


Modified: 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/config.py
==============================================================================
--- 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/config.py    
    (original)
+++ 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/config.py    
    Wed Nov 14 23:32:07 2007
@@ -6,7 +6,9 @@
 
 from kss.base.testing import Section, Test
 
-kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit')
+package_dir = os.path.dirname(os.path.abspath(__file__))
+kukit_dir = os.path.join(package_dir, 'kukit')
+html_dir = os.path.join(package_dir, 'html')
 
 # Define the Javascripts by hand to ensure the order
 core_js = ['utils.js',
@@ -34,6 +36,10 @@
     'sarissa.js',
 ]
 
+def test_div_content(commands, request):
+    commands.core.replaceInnerHTML('#demo', '<blink>KSS ROCKS!!!!!!!</blink>')
+    
+
 class KSSCore(Plugin):
     '''The KSS core plugin has all the standard functionality'''
 
@@ -51,8 +57,8 @@
     selectors = [css, htmlid, samenode, parentnode]
 
     functional_tests = [Test(
-            name='Focus', 
-            html='/tmp/kss_demo.html', 
+            name='Basic commands', 
+            html=os.path.join(html_dir, 'focus.html'),
             css='/tmp/demo.css', 
-            kss='blah.kss', 
-            handler=lambda request: 'ok')]
+            kss=os.path.join(html_dir, 'basic_commands.kss'), 
+            handlers={'getDivContent': test_div_content})]

Modified: 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/corecommands.py
==============================================================================
--- 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/corecommands.py
  (original)
+++ 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/corecommands.py
  Wed Nov 14 23:32:07 2007
@@ -78,6 +78,3 @@
 
     def triggerEvent(self, name, **kwargs):
         self.commands.add('triggerEvent', None, name=name, **kwargs)
-
-
-

Added: 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/basic_commands.kss
==============================================================================
--- (empty file)
+++ 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/basic_commands.kss
  Wed Nov 14 23:32:07 2007
@@ -0,0 +1,20 @@
+button#copyFrom:click {
+    action-server: copyFromDivContent;
+}
+
+button#copyTo:click {
+    action-server: copyToDivContent;
+}
+
+button#moveTo:click {
+    action-server: moveToDivContent;
+}
+
+button#clear:click {
+    action-server: clearDivContent;
+}
+
+button#change:click {
+    action-server: getDivContent;
+}
+

Added: 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/focus.html
==============================================================================
--- (empty file)
+++ 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/html/focus.html
  Wed Nov 14 23:32:07 2007
@@ -0,0 +1,104 @@
+<h2>Change tag content</h2>
+<h4>Top div</h4>
+<div id="demo" style="border: 1px solid black;padding: 15px">
+  KSS 
+</div>
+<ul>
+  <li>
+    <button id="change">
+           Change top div content
+    </button>
+    <a tal:attributes="href string:${context/@@absolute_url}/getDivContent">
+      getDivContent RESPONSE
+    </a>
+  </li>
+  <li>
+    <button id="clear">
+           Clear top div content
+    </button>
+    <a tal:attributes="href string:${context/@@absolute_url}/clearDivContent">
+      clearDivContent RESPONSE
+    </a>
+  </li>
+  <li>
+    <button id="copyFrom">
+           Copy top div content to bottom
+    </button>
+    <a tal:attributes="href 
string:${context/@@absolute_url}/copyFromDivContent">
+      copyFromDivContent RESPONSE
+    </a>
+  </li>
+  <li>
+    <button id="copyTo">
+           Copy bottom div content to top
+    </button>
+    <a tal:attributes="href string:${context/@@absolute_url}/copyToDivContent">
+      copyToDivContent RESPONSE
+    </a>
+  </li>
+  <li>
+    <button id="moveTo">
+           Move bottom div content to top
+    </button>
+    <a tal:attributes="href string:${context/@@absolute_url}/moveToDivContent">
+      moveToDivContent RESPONSE
+    </a>
+  </li>
+</ul>
+<h4>Bottom div</h4>
+<div id="copy" style="border: 1px solid black;padding: 15px">
+  copy here
+</div>
+<h3>Javascript Styling</h3>
+<p>This page defines a <code>link</code> in the header which <code>rel</code> 
attribute points
+  to a <code>.kss</code> resource file on the server :
+
+  <a tal:attributes="href 
string:${context/@@absolute_url}/++resource++basic_commands.kss">
+    see the kss file here</a>.</p>
+<p>
+  This <code>.kss</code> file declares CSS selectors associated with events 
and server URLs called when the event occur.
+</p>
+<p>A javascript engine processes the XML content : it inserts javascript
+  events in the DOM.</p>
+<p>
+  For instance, the click event of button with the id <code>change</code> will 
call asynchronously the <code>getDivContent</code> URL.
+
+</p>
+<h3>Server Asynchronous Call</h3>
+<p>
+  The events associated with Javascript just call the server asynchronously.
+</p>
+<p>
+  The response is a XML file.
+  The XML contains CSS selectors associated with commands.
+</p>
+<p>
+  The Javascript engine selects the DOM nodes to which it applies each command.
+</p>
+<p>
+  For instance, let's look at the <a tal:attributes="href 
string:${context/@@absolute_url}/moveToDivContent"><code>moveToDivContent</code>
 response</a>.
+</p>
+<pre>
+  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
+  &lt;html xmlns="http://www.w3.org/1999/xhtml";
+  xmlns:kukit="http://www.kukit.org/commands/1.0"&gt;&lt;body&gt;
+  &lt;kukit:commands&gt;
+  &lt;kukit:command selector="div#copy" name="copyChildNodesTo"
+  selectorType=""&gt;
+  &lt;kukit:param name="html_id"&gt;demo&lt;/kukit:param&gt;
+  &lt;/kukit:command&gt;
+  &lt;kukit:command selector="div#copy" name="clearChildNodes"
+  selectorType=""&gt;
+  &lt;/kukit:command&gt;
+  &lt;/kukit:commands&gt;
+  &lt;/body&gt;&lt;/html&gt;
+</pre>
+<p>
+  The XML specifies two commands to apply to the <code>div#copy</code> node :
+</p>
+<p>
+  <code>copyChildNodesTo</code> copies the children of the DOM node to the 
node with id <code>demo</code>.
+</p>
+<p>
+  <code>clearChildNodes</code> removes the children of the DOM node.
+</p>

Modified: 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/testing.py
==============================================================================
--- 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/testing.py   
    (original)
+++ 
kukit/kss.base/branches/basehttpserver-functional-testing/kss/base/testing.py   
    Wed Nov 14 23:32:07 2007
@@ -1,7 +1,12 @@
 import string
-from kss.base.plugin import activated_plugins
+import os
 from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
 
+from kss.base.plugin import activated_plugins
+from kss.base.javascript import packed
+from kss.base.javascript import extra_scripts
+from kss.base import KSSCommands
+
 front_page = '''
 <html>
 <body>
@@ -27,25 +32,52 @@
 test_page_html = '''
 <html>
   <head>
+    <base href="$server$base_url"/>
+    <script type="text/javascript" src="$server/kss.js"></script>
     <link rel="stylesheet" type="text/css" href="$css_url"/>
-    <link rel="kinetic-stylesheet" type="text/css" href="$kss_url" />
+    <link rel="kinetic-stylesheet" type="text/kss" href="$kss_url" />
    </head>
    <body>
-   $html
+     <h1>$name</h1>
+     $html
    </body>
 </html>
 '''
 
+import re
+
 class PluginTestsuiteRequestHandler(BaseHTTPRequestHandler):
 
     def do_GET(self):
         path = self.path
         if path == '/':
             return self.do_index()
+        elif path == '/kss.js':
+            return self.do_kss_js()
         elif path.endswith('.html'):
             return self.do_test_html()
-        else:
-            return self.do_test_css()
+        elif path.endswith('.kss'):
+            return self.do_test_kss()
+
+    def do_POST(self):
+        plugin_id, test_id, handler_id = re.findall(
+            '^/([\w-]+)/([\w-]+)/([\w-]+)', self.path)[0]
+
+        id, plugin, test = self.load_test(plugin_id, test_id)
+        
+        
+        handler = test.handlers[handler_id]
+        
+        commands = KSSCommands()
+        handler(commands, 'some request obj')
+
+        self.send_response(200)
+        self.send_header('Content-type', 'text/xml')
+        self.end_headers()
+
+        self.wfile.write(commands.render())
+        self.wfile.close()
+        
 
     def send_html_headers(self):
         self.send_response(200)
@@ -68,23 +100,53 @@
         return '/%s/%s' % (self.name_to_url_safe(plugin_id), 
                            self.name_to_url_safe(test.name))
 
-    def load_from_path(self, extension):
-        parts = self.path[:-len(extension)].split('/')
-        print parts
+    def load_from_path(self, extension=None):
+        if extension is None:
+            parts = self.path.split('/')
+        else:
+            parts = self.path[:-len(extension)].split('/')
+        return self.load_test(parts[1], parts[2])
+
+    def load_test(self, plugin_id, test_id):
         for id, plugin in activated_plugins():
-            if parts[1] == id:
+            if plugin_id == id:
                 for test in plugin.functional_tests:
-                    if self.name_to_url_safe(test.name) == parts[2]:
+                    if self.name_to_url_safe(test.name) == test_id:
                         return (id, plugin, test)
 
-    def do_test_css(self):
+
+    def do_kss_js(self):
+        self.send_response(200)
+        self.send_header('Content-Type', 'text/javascript')
+        self.end_headers()
+
+        data = list(extra_scripts().values())
+        data.append(packed())
+        self.wfile.write('\n'.join(data))
+        self.wfile.close()
+
+
+    def do_test_kss(self):
+        self.send_response(200)
+        self.send_header('Content-Type', 'text/kss')
+        self.end_headers()
+
+        id, plugin, test = self.load_from_path('.kss')
+        self.wfile.write(open(test.kss).read())
+        self.wfile.close()
+        
+
+    def do_test_static(self):
+        filename = self.path.split('/')[-1]
+        extension = filename.split('.')[-1]
+
         self.send_response(200)
-        self.send_header('Content-Type', 'text/css')
+        self.send_header('Content-Type', 'text/' + extension)
         self.end_headers()
 
-        id, plugin, test = self.load_from_path('.css')
+        id, plugin, test = self.load_from_path()
 
-        self.wfile.write(open(test.css).read())
+        self.wfile.write(open(os.path.join(test.static_dir, filename)).read())
         self.wfile.close()
 
     def do_test_html(self):
@@ -93,8 +155,11 @@
         html = string.Template(test_page_html)
         id, plugin, test = self.load_from_path('.html')
         self.wfile.write(html.substitute(
+                base_url=self.test_base_url(id, test),
+                server='http://localhost:8000',
                 css_url=self.css_url(id, test),
                 kss_url=self.kss_url(id, test),
+                name=test.name,
                 html=open(test.html).read()))
         self.wfile.close()
 
@@ -133,12 +198,12 @@
         self.tests = tests
 
 class Test(object):
-    def __init__(self, name, html, css, kss, handler):
+    def __init__(self, name, html, css, kss, handlers):
         self.name = name
         self.html = html
         self.css = css
         self.kss = kss
-        self.handler = handler
+        self.handlers = handlers
 
 
 if __name__ == '__main__':
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to