[Checkins] SVN: grokcore.view/trunk/ Fixed utility function 'url' and added a test to fix the behavior

Souheil CHELFOUH souheil at chelfouh.com
Wed Jun 2 15:48:27 EDT 2010


Log message for revision 112932:
  Fixed utility function 'url' and added a test to fix the behavior
  

Changed:
  U   grokcore.view/trunk/CHANGES.txt
  U   grokcore.view/trunk/src/grokcore/view/ftests/url/url_function.py
  U   grokcore.view/trunk/src/grokcore/view/util.py

-=-
Modified: grokcore.view/trunk/CHANGES.txt
===================================================================
--- grokcore.view/trunk/CHANGES.txt	2010-06-02 16:24:37 UTC (rev 112931)
+++ grokcore.view/trunk/CHANGES.txt	2010-06-02 19:48:27 UTC (rev 112932)
@@ -4,6 +4,8 @@
 2.0 (unreleased)
 ----------------
 
+- Fix the url() function to behave properly while passed an empty data dict.
+
 - Fix the url() method to accept the "status" and "trusted" arguments, passed
   on to the redirect method on the response object.
 

Modified: grokcore.view/trunk/src/grokcore/view/ftests/url/url_function.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/ftests/url/url_function.py	2010-06-02 16:24:37 UTC (rev 112931)
+++ grokcore.view/trunk/src/grokcore/view/ftests/url/url_function.py	2010-06-02 19:48:27 UTC (rev 112932)
@@ -78,6 +78,14 @@
   >>> url(request, herd, None, data=dict(name="Peter"))
   'http://127.0.0.1/herd?name=Peter'
 
+Providing an empty dict gives the same result than giving None:
+
+  >>> url(request, herd, data={})
+  'http://127.0.0.1/herd'
+
+  >>> url(request, herd, data=None)
+  'http://127.0.0.1/herd'
+
 Since order in dictionairies is arbitrary we'll test the presence of multiple
 keywords by using find()
 

Modified: grokcore.view/trunk/src/grokcore/view/util.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/util.py	2010-06-02 16:24:37 UTC (rev 112931)
+++ grokcore.view/trunk/src/grokcore/view/util.py	2010-06-02 19:48:27 UTC (rev 112932)
@@ -24,7 +24,7 @@
     if name is not None:
         url += '/' + urllib.quote(name.encode('utf-8'), SAFE_URL_CHARACTERS)
 
-    if data is None:
+    if not data:
         return url
 
     if not isinstance(data, dict):



More information about the checkins mailing list