From ec0bae35c538d8b4fde1c5b46b162c19783ca1a7 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Mon, 15 Aug 2016 10:39:38 +0530 Subject: Assert cookie groups explicitly rather than just the length --- test/netlib/http/test_cookies.py | 56 ++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py index 828029c6..56e0b21b 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/netlib/http/test_cookies.py @@ -289,20 +289,44 @@ def test_is_expired(): def test_group_cookies(): - def group(cookie): - return cookies.group_cookies(cookies.parse_cookie_header(c)) - - c = "one=uno; foo=bar; foo=baz" - assert len(group(c)) == 3 - - c = "one=uno; Path=/; foo=bar; Max-Age=0; foo=baz; expires=24-08-1993" - assert len(group(c)) == 3 - - c = "one=uno;" - assert len(group(c)) == 1 - - c = "one=uno; Path=/; Max-Age=0; Expires=24-08-1993" - assert len(group(c)) == 1 + CA = cookies.CookieAttrs + groups = [ + [ + "one=uno; foo=bar; foo=baz", + [ + ('one', 'uno', CA([])), + ('foo', 'bar', CA([])), + ('foo', 'baz', CA([])) + ] + ], + [ + "one=uno; Path=/; foo=bar; Max-Age=0; foo=baz; expires=24-08-1993", + [ + ('one', 'uno', CA([('Path', '/')])), + ('foo', 'bar', CA([('Max-Age', '0')])), + ('foo', 'baz', CA([('expires', '24-08-1993')])) + ] + ], + [ + "one=uno;", + [ + ('one', 'uno', CA([])) + ] + ], + [ + "one=uno; Path=/; Max-Age=0; Expires=24-08-1993", + [ + ('one', 'uno', CA([('Path', '/'), ('Max-Age', '0'), ('Expires', '24-08-1993')])) + ] + ], + [ + "path=val; Path=/", + [ + ('path', 'val', CA([('Path', '/')])) + ] + ] + ] - c = "path=val; Path=/" - assert group(c) == [("path", "val", cookies.CookieAttrs([("Path", "/")]))] + for c, expected in groups: + observed = cookies.group_cookies(cookies.parse_cookie_header(c)) + assert observed == expected -- cgit v1.2.3