~ubuntu-branches/ubuntu/karmic/linkchecker/karmic

« back to all changes in this revision

Viewing changes to linkcheck/tests/test_cookies.py

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-04-26 08:29:53 UTC
  • mfrom: (1.3.1 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080426082953-3zqaicgg6lp4fuj0
Tags: 4.9-1ubuntu1
* Merge from Debian unstable. (LP: #225630) Remaining Ubuntu changes:
  - Drop dependency on versioned python package.
  - Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: iso-8859-1 -*-
2
 
# Copyright (C) 2005-2007 Bastian Kleineidam
 
2
# Copyright (C) 2005-2008 Bastian Kleineidam
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
86
86
        host = "localhost"
87
87
        path = "/"
88
88
        cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path)
 
89
        self.assert_(cookie.is_valid_for("http", host, 100, "/"))
89
90
 
90
91
    def test_netscape_cookie5 (self):
91
92
        data = (
92
93
            ("Foo", "Bar"),
93
 
            ("Domain", "imadoofus.org"),
 
94
            ("Domain", "example.org"),
94
95
            ("Expires", "Wed, 12-Dec-2001 19:27:57 GMT"),
95
96
            ("Path", "/"),
96
97
        )
98
99
        parts = ['%s=%s' % (key, value) for key, value in data]
99
100
        value = "; ".join(parts)
100
101
        scheme = "http"
101
 
        host = "imadoofus.org"
 
102
        host = "example.org"
102
103
        path = "/"
103
104
        cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path)
104
105
        self.assert_(cookie.is_expired())
161
162
        host = "localhost"
162
163
        path = "/"
163
164
        cookie = linkcheck.cookies.Rfc2965Cookie(value, scheme, host, path)
 
165
        self.assert_(cookie.is_valid_for("http", host, 100, "/"))
164
166
 
165
167
    def test_cookie_parse1 (self):
166
168
        lines = [
167
 
            'Host: imadoofus.org',
 
169
            'Host: example.org',
168
170
            'Path: /hello',
169
171
            'Set-cookie: ID="smee"',
170
172
            'Set-cookie: spam="egg"',
171
173
        ]
172
174
        from_headers = linkcheck.cookies.from_headers
173
175
        headers, scheme, host, path = from_headers("\r\n".join(lines))
 
176
        self.assertEqual(scheme, "http")
 
177
        self.assertEqual(host, "example.org")
 
178
        self.assertEqual(path, "/hello")
 
179
        self.assertEqual(len(headers.headers), 4)
174
180
 
175
181
    def test_cookie_parse2 (self):
176
182
        lines = [
177
183
            'Scheme: https',
178
 
            'Host: imaweevil.org',
 
184
            'Host: example.org',
179
185
            'Set-cookie: baggage="elitist"; comment="hologram"',
180
186
        ]
181
187
        from_headers = linkcheck.cookies.from_headers
182
188
        headers, scheme, host, path = from_headers("\r\n".join(lines))
 
189
        self.assertEqual(scheme, "https")
 
190
        self.assertEqual(host, "example.org")
 
191
        self.assertEqual(path, "/")
 
192
        self.assertEqual(len(headers.headers), 3)
183
193
 
184
194
    def test_cookie_parse3 (self):
185
195
        lines = [