Commits

Branko Vukelic committed 6e94a4b Merge

Merged in trojjer/django-url-tools (pull request #3)

update_query_data fix thanks to Marc Kirkwood

Comments (0)

Files changed (3)

 import sys
 from os.path import dirname, abspath
 
-from django.conf import settings, global_settings
+from django.conf import settings
 
 from nose.plugins.plugintest import run_buffered as run
 
 
 if __name__ == '__main__':
     runtests()
-

tests/test_url_helper.py

     def test_update_query_data(self):
         u = UrlHelper('/foo?foo=1&bar=2')
         u.update_query_data(foo=2)
-        self.assertEqual(u.get_query_data()['foo'], '2')
+        self.assertEqual(u.get_query_data()['foo'], 2)
 
     def test_update_query_data_with_multiple_values(self):
         u = UrlHelper('/foo?foo=1&bar=2')
-        u.update_query_data(foo=[1,2,3])
-        self.assertEqual(u.get_query_data()['foo'], '3')
-        self.assertEqual(u.get_query_data().getlist('foo'), ['1', '2', '3'])
+        u.update_query_data(foo=[1, 2, 3])
+        self.assertEqual(u.get_query_data()['foo'], 3)
+        self.assertEqual(u.get_query_data().getlist('foo'), [1, 2, 3])
+
+    def test_update_query_data_with_correct_escaping(self):
+        u = UrlHelper('/foo?foo=1&bar=2')
+        u.update_query_data(foo='space here!')
+        self.assertEqual(u.query_string, u'foo=space+here%21&bar=2')
 
     def test_get_query_string_after_modification(self):
         u = UrlHelper('/foo?foo=1&bar=2')
     def test_query_setter(self):
         u = UrlHelper('/foo')
         u.query = dict(foo=1)
-        self.assertEqual(u.query['foo'], '1')
+        self.assertEqual(u.query['foo'], 1)
 
     def test_query_setter_with_string(self):
         u = UrlHelper('/foo')

url_tools/helper.py

 
 try:
     from django.http.request import QueryDict
-except ImportError: # django 1.4.2
+except ImportError:  # django 1.4.2
     from django.http import QueryDict
 
 from django.utils.encoding import iri_to_uri
         return self.query_dict
 
     def update_query_data(self, **kwargs):
-        for key in kwargs:
-            val = kwargs[key]
+        for key, val in kwargs.iteritems():
             if hasattr(val, '__iter__'):
-                self.query_dict.setlist(key, [iri_to_uri(v) for v in val])
+                self.query_dict.setlist(key, val)
             else:
-                self.query_dict[key] = iri_to_uri(val)
+                self.query_dict[key] = val
 
     def get_path(self):
         return self.path