[doc] note on pytestconf, fixlets stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 08 Apr 2010 12:42:47 +0200
branchstable
changeset 5186 f3c2cb460ad9
parent 5185 92376b009b98
child 5187 5f9a2b32c9e1
child 5188 99cdb9608cc1
child 5196 d14bfd477c44
[doc] note on pytestconf, fixlets
doc/book/en/development/devweb/js.rst
doc/book/en/development/testing.rst
web/_exceptions.py
web/data/cubicweb.ajax.js
web/data/cubicweb.compat.js
web/data/cubicweb.python.js
--- a/doc/book/en/development/devweb/js.rst	Thu Apr 08 12:32:09 2010 +0200
+++ b/doc/book/en/development/devweb/js.rst	Thu Apr 08 12:42:47 2010 +0200
@@ -5,7 +5,7 @@
 
 *CubicWeb* uses quite a bit of javascript in its user interface and
 ships with jquery (1.3.x) and parts of the jquery UI library, plus a
-number of homegrown files and also other thir party libraries.
+number of homegrown files and also other third party libraries.
 
 All javascript files are stored in cubicweb/web/data/. There are
 around thirty js files there. In a cube it goes to data/.
--- a/doc/book/en/development/testing.rst	Thu Apr 08 12:32:09 2010 +0200
+++ b/doc/book/en/development/testing.rst	Thu Apr 08 12:42:47 2010 +0200
@@ -24,6 +24,10 @@
 In most of the cases, you will inherit `EnvBasedTC` to write Unittest or
 functional tests for your entities, views, hooks, etc...
 
+XXX pytestconf.py & options (e.g --source to use a different db
+backend than sqlite)
+
+
 Managing connections or users
 +++++++++++++++++++++++++++++
 
@@ -33,10 +37,12 @@
 
 By default, tests run with a user with admin privileges. This
 user/connection must never be closed.
-qwq
-Before a self.login, one has to release the connection pool in use with a self.commit, self.rollback or self.close.
 
-When one is logged in as a normal user and wants to switch back to the admin user, one has to use self.restore_connection().
+Before a self.login, one has to release the connection pool in use
+with a self.commit, self.rollback or self.close.
+
+When one is logged in as a normal user and wants to switch back to the
+admin user, one has to use self.restore_connection().
 
 Usually it looks like this:
 
--- a/web/_exceptions.py	Thu Apr 08 12:32:09 2010 +0200
+++ b/web/_exceptions.py	Thu Apr 08 12:42:47 2010 +0200
@@ -53,8 +53,7 @@
     """raised when a json remote call fails
     """
     def __init__(self, reason=''):
-        #super(RequestError, self).__init__() # XXX require py >= 2.5
-        RequestError.__init__(self)
+        super(RequestError, self).__init__()
         self.reason = reason
 
     def dumps(self):
--- a/web/data/cubicweb.ajax.js	Thu Apr 08 12:32:09 2010 +0200
+++ b/web/data/cubicweb.ajax.js	Thu Apr 08 12:42:47 2010 +0200
@@ -240,6 +240,7 @@
     setProgressCursor();
     var props = {'fname' : fname, 'pageid' : pageid,
                  'arg': map(jQuery.toJSON, sliceList(arguments, 1))};
+    // XXX we should inline the content of loadRemote here
     var deferred = loadRemote(JSON_BASE_URL, props, 'POST');
     deferred = deferred.addErrback(remoteCallFailed);
     deferred = deferred.addErrback(resetCursor);
--- a/web/data/cubicweb.compat.js	Thu Apr 08 12:32:09 2010 +0200
+++ b/web/data/cubicweb.compat.js	Thu Apr 08 12:42:47 2010 +0200
@@ -6,22 +6,26 @@
     }
 }
 
+// XXX looks completely unused (candidate for removal)
 function getElementsByTagAndClassName(tag, klass, root) {
     root = root || document;
     // FIXME root is not used in this compat implementation
     return jQuery(tag + '.' + klass);
 }
 
+/* jQUery flattens arrays returned by the mapping function:
+   >>> y = ['a:b:c', 'd:e']
+   >>> jQuery.map(y, function(y) { return y.split(':');})
+   ["a", "b", "c", "d", "e"]
+   // where one would expect:
+   [ ["a", "b", "c"], ["d", "e"] ]
+   XXX why not the same argument order as $.map and forEach ?
+*/
 function map(func, array) {
-    // XXX jQUery tends to simplify lists with only one element :
-    // >>> y = ['a:b:c']
-    // >>> jQuery.map(y, function(y) { return y.split(':');})
-    // ["a", "b", "c"]
-    // where I would expect :
-    // [ ["a", "b", "c"] ]
-    // return jQuery.map(array, func);
     var result = [];
-    for (var i=0,length=array.length;i<length;i++) {
+    for (var i=0, length=array.length;
+         i<length;
+         i++) {
 	result.push(func(array[i]));
     }
     return result;
@@ -41,6 +45,7 @@
     jQuery(node).addClass(klass);
 }
 
+// XXX looks completely unused (candidate for removal)
 function toggleElementClass(node, klass) {
     jQuery(node).toggleClass(klass);
 }
@@ -281,26 +286,35 @@
 
 jQuery.extend(Deferred.prototype, {
     __init__: function() {
-	this.onSuccess = [];
-	this.onFailure = [];
-	this.req = null;
+	this._onSuccess = [];
+	this._onFailure = [];
+	this._req = null;
+        this._result = null;
+        this._error = null;
     },
 
     addCallback: function(callback) {
-	this.onSuccess.push([callback, sliceList(arguments, 1)]);
+        if (this._req.readyState == 4) {
+            if (this._result) { callback.apply(null, this._result, this._req); }
+        }
+        else { this._onSuccess.push([callback, sliceList(arguments, 1)]); }
 	return this;
     },
 
     addErrback: function(callback) {
-	this.onFailure.push([callback, sliceList(arguments, 1)]);
+        if (this._req.readyState == 4) {
+            if (this._error) { callback.apply(null, this._error, this._req); }
+        }
+        else { this._onFailure.push([callback, sliceList(arguments, 1)]); }
 	return this;
     },
 
     success: function(result) {
+        this._result = result;
 	try {
-	    for (var i=0; i<this.onSuccess.length; i++) {
-		var callback = this.onSuccess[i][0];
-		var args = merge([result, this.req], this.onSuccess[i][1]);
+	    for (var i=0; i<this._onSuccess.length; i++) {
+		var callback = this._onSuccess[i][0];
+		var args = merge([result, this._req], this._onSuccess[i][1]);
 		callback.apply(null, args);
 	    }
 	} catch (error) {
@@ -309,9 +323,10 @@
     },
 
     error: function(xhr, status, error) {
-	for (var i=0; i<this.onFailure.length; i++) {
-	    var callback = this.onFailure[i][0];
-	    var args = merge([error, this.req], this.onFailure[i][1]);
+        this._error = error;
+	for (var i=0; i<this._onFailure.length; i++) {
+	    var callback = this._onFailure[i][0];
+	    var args = merge([error, this._req], this._onFailure[i][1]);
 	    callback.apply(null, args);
 	}
     }
@@ -319,6 +334,46 @@
 });
 
 
+/*
+ * Asynchronously load an url and return a deferred
+ * whose callbacks args are decoded according to
+ * the Content-Type response header
+ */
+function loadRemote(url, data, reqtype) {
+    var d = new Deferred();
+    jQuery.ajax({
+	url: url,
+	type: reqtype,
+	data: data,
+
+	beforeSend: function(xhr) {
+	    d._req = xhr;
+	},
+
+	success: function(data, status) {
+            if (d._req.getResponseHeader("content-type") == 'application/json') {
+              data = evalJSON(data);
+            }
+	    d.success(data);
+	},
+
+	error: function(xhr, status, error) {
+          try {
+            if (xhr.status == 500) {
+                var reason_dict = evalJSON(xhr.responseText);
+                d.error(xhr, status, reason_dict['reason']);
+                return;
+            }
+          } catch(exc) {
+            log('error with server side error report:' + exc);
+          }
+          d.error(xhr, status, null);
+	}
+    });
+    return d;
+}
+
+
 /** @id MochiKit.DateTime.toISOTime */
 toISOTime = function (date, realISO/* = false */) {
     if (typeof(date) == "undefined" || date === null) {
@@ -366,36 +421,6 @@
 };
 
 
-/*
- * Asynchronously load an url and return a deferred
- * whose callbacks args are decoded according to
- * the Content-Type response header
- */
-function loadRemote(url, data, reqtype) {
-    var d = new Deferred();
-    jQuery.ajax({
-	url: url,
-	type: reqtype,
-	data: data,
-
-	beforeSend: function(xhr) {
-	    d.req = xhr;
-	},
-
-	success: function(data, status) {
-            if (d.req.getResponseHeader("content-type") == 'application/json') {
-              data = evalJSON(data);
-            }
-	    d.success(data);
-	},
-
-	error: function(xhr, status, error) {
-	    error = evalJSON(xhr.responseText);
-	    d.error(xhr, status, error['reason']);
-	}
-    });
-    return d;
-}
 
 /* depth-first implementation of the nodeWalk function found
  * in MochiKit.Base
--- a/web/data/cubicweb.python.js	Thu Apr 08 12:32:09 2010 +0200
+++ b/web/data/cubicweb.python.js	Thu Apr 08 12:42:47 2010 +0200
@@ -237,9 +237,9 @@
  * ['d', 'e', 'f']
  */
 function sliceList(lst, start, stop, step) {
-    var start = start || 0;
-    var stop = stop || lst.length;
-    var step = step || 1;
+    start = start || 0;
+    stop = stop || lst.length;
+    step = step || 1;
     if (stop < 0) {
 	stop = max(lst.length+stop, 0);
     }
@@ -256,6 +256,7 @@
 /* returns a partial func that calls a mehod on its argument
  * py-equiv: return lambda obj: getattr(obj, methname)(*args)
  */
+// XXX looks completely unused (candidate for removal)
 function methodcaller(methname) {
     var args = sliceList(arguments, 1);
     return function(obj) {
@@ -398,6 +399,7 @@
     jQuery(CubicWeb).trigger('server-response', [false, document]);
 });
 
+// XXX as of 2010-04-07, no known cube uses this
 jQuery(CubicWeb).bind('ajax-loaded', function() {
     log('[3.7] "ajax-loaded" event is deprecated, use "server-response" instead');
     jQuery(CubicWeb).trigger('server-response', [false, document]);