Commits

Mariano Mara  committed d8e89fa Merge

Pulling webob official repo new code plus adding coverage for new method serialize

  • Participants
  • Parent commits 57b80a8, 5301de8

Comments (0)

Files changed (4)

File tests/test_cookies.py

 # -*- coding: UTF-8 -*-
 from datetime import timedelta
 from webob import cookies
-from nose.tools import ok_, assert_raises
+from nose.tools import ok_, assert_raises, eq_
 
 def test_cookie():
     """Testing several missing features of cookies.Cookie.
     * ignoring a key-value for Cookie when key == $
     """
     c = cookies.Cookie() # empty cookie
-    ok_(c.__repr__()=='<Cookie: []>', 'Wrong repr. Expected: %r, got: %r' %\
-    ('<Cookie: []>', c.__repr__()))
+    eq_(repr(c), '<Cookie: []>')
     # a cookie with one value
     c = cookies.Cookie('dismiss-top=6') 
-    ok_(c.__repr__()=="<Cookie: [<Morsel: dismiss-top='6'>]>", 
-        'Wrong repr. Expected: %r, got: %r' %\
-        ("<Cookie: [<Morsel: dismiss-top='6'>]>", c.__repr__()))
+    eq_(repr(c), "<Cookie: [<Morsel: dismiss-top='6'>]>")
     c = cookies.Cookie('dismiss-top=6;') 
-    ok_(c.__repr__()=="<Cookie: [<Morsel: dismiss-top='6'>]>", 
-        'Wrong repr. Expected: %r, got: %r' %\
-        ("<Cookie: [<Morsel: dismiss-top='6'>]>", c.__repr__()))
+    eq_(repr(c), "<Cookie: [<Morsel: dismiss-top='6'>]>")
     # more complex cookie
     new_c = "<Cookie: [<Morsel: a='42'>, <Morsel: CP='null*'>, "\
     "<Morsel: PHPSESSID='0a539d42abc001cdc762809248d4beed'>, "\
     "<Morsel: dismiss-top='6'>]>"
     c = cookies.Cookie("dismiss-top=6; CP=null*; "\
                        "PHPSESSID=0a539d42abc001cdc762809248d4beed; a=42")
-    ok_(c.__repr__()==new_c, 'Wrong repr. Expected; %r, got: %r' % (new_c, 
-                                                                    c.__repr__()
-                                                                   ))
+    ok_(repr(c), new_c)
+    eq_(c.serialize(), 
+        'CP=null*, PHPSESSID=0a539d42abc001cdc762809248d4beed, a=42, '
+        'dismiss-top=6')
     # data with key==$
     c = cookies.Cookie('dismiss-top=6; CP=null*; $=42'\
                        'PHPSESSID=0a539d42abc001cdc762809248d4beed; a=42')

File tests/test_response.txt

     ['test2=value2-replace; Path=/']
 
 
+    >>> r = Response()
+    >>> r.set_cookie('x', 'x')
+    >>> r.set_cookie('y', 'y')
+    >>> r.set_cookie('z', 'z')
+    >>> r.headers.getall('set-cookie')
+    ['x=x; Path=/', 'y=y; Path=/', 'z=z; Path=/']
+    >>> r.unset_cookie('y')
+    >>> r.headers.getall('set-cookie')
+    ['x=x; Path=/', 'z=z; Path=/']
+
+
 Most headers are available in a parsed getter/setter form through
 properties:
 

File webob/cookies.py

         dict.__setitem__(self, key, Morsel(key, val))
 
     def serialize(self, full=True):
-        return '; '.join(m.serialize(full) for _,m in sorted(self.items()))
+        return ', '.join(m.serialize(full) for m in self.values())
+
+    def values(self):
+        return [m for _,m in sorted(self.items())]
 
     __str__ = serialize
 

File webob/response.py

         if key in cookies:
             del cookies[key]
             del self.headers['Set-Cookie']
-            if cookies:
-                self.headerlist.append(('Set-Cookie', str(cookies)))
+            for m in cookies.values():
+                self.headerlist.append(('Set-Cookie', str(m)))
         elif strict:
             raise KeyError("No cookie has been set with the name %r" % key)