def test_parse_set_cookie_header():
    def set_cookie_equal(obs, exp):
        assert obs[0] == exp[0]
        assert obs[1] == exp[1]
        assert obs[2].items(multi=True) == exp[2]

    vals = [
        ["", []],
        [";", []],
        ["=uno", [("", "uno", ())]],
        ["one=uno", [("one", "uno", ())]],
        ["one=uno; foo=bar", [("one", "uno", (("foo", "bar"), ))]],
        [
            "one=uno; foo=bar; foo=baz",
            [("one", "uno", (("foo", "bar"), ("foo", "baz")))]
        ],
        # Comma Separated Variant of Set-Cookie Headers
        ["foo=bar, doo=dar", [
            ("foo", "bar", ()),
            ("doo", "dar", ()),
        ]],
        [
            "foo=bar; path=/, doo=dar; roo=rar; zoo=zar",
            [
                ("foo", "bar", (("path", "/"), )),
                ("doo", "dar", (("roo", "rar"), ("zoo", "zar"))),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037"), )),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037 00:00:00 GMT, doo=dar",
            [
                ("foo", "bar", (("expires",
                                 "Mon, 24 Aug 2037 00:00:00 GMT"), )),
                ("doo", "dar", ()),
            ]
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            for i in range(len(expected)):
                set_cookie_equal(ret[i], expected[i])

            s2 = cookies.format_set_cookie_header(ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            for i in range(len(expected)):
                set_cookie_equal(ret2[i], expected[i])
        else:
            assert not ret
Exemplo n.º 2
0
 def _set_cookies(self, value):
     cookie_headers = []
     for k, v in value:
         header = cookies.format_set_cookie_header([(k, v[0], v[1])])
         cookie_headers.append(header)
     self.headers.set_all("set-cookie", cookie_headers)
Exemplo n.º 3
0
def test_parse_set_cookie_header():
    def set_cookie_equal(obs, exp):
        assert obs[0] == exp[0]
        assert obs[1] == exp[1]
        assert obs[2].items(multi=True) == exp[2]

    vals = [
        [
            "", []
        ],
        [
            ";", []
        ],
        [
            "one=uno",
            [
                ("one", "uno", ())
            ]
        ],
        [
            "one=uno; foo=bar",
            [
                ("one", "uno", (("foo", "bar"),))
            ]
        ],
        [
            "one=uno; foo=bar; foo=baz",
            [
                ("one", "uno", (("foo", "bar"), ("foo", "baz")))
            ]
        ],
        # Comma Separated Variant of Set-Cookie Headers
        [
            "foo=bar, doo=dar",
            [
                ("foo", "bar", ()),
                ("doo", "dar", ()),
            ]
        ],
        [
            "foo=bar; path=/, doo=dar; roo=rar; zoo=zar",
            [
                ("foo", "bar", (("path", "/"),)),
                ("doo", "dar", (("roo", "rar"), ("zoo", "zar"))),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037"),)),
            ]
        ],
        [
            "foo=bar; expires=Mon, 24 Aug 2037 00:00:00 GMT, doo=dar",
            [
                ("foo", "bar", (("expires", "Mon, 24 Aug 2037 00:00:00 GMT"),)),
                ("doo", "dar", ()),
            ]
        ],
    ]
    for s, expected in vals:
        ret = cookies.parse_set_cookie_header(s)
        if expected:
            for i in range(len(expected)):
                set_cookie_equal(ret[i], expected[i])

            s2 = cookies.format_set_cookie_header(ret)
            ret2 = cookies.parse_set_cookie_header(s2)
            for i in range(len(expected)):
                set_cookie_equal(ret2[i], expected[i])
        else:
            assert not ret
Exemplo n.º 4
0
 def _set_cookies(self, value):
     cookie_headers = []
     for k, v in value:
         header = cookies.format_set_cookie_header([(k, v[0], v[1])])
         cookie_headers.append(header)
     self.headers.set_all("set-cookie", cookie_headers)