Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
80b2aa0a
Kaydet (Commit)
80b2aa0a
authored
Kas 17, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #19606: Use specific asserts in http.cookiejar tests.
üst
c1fc5b50
9d282f6b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
84 deletions
+73
-84
test_http_cookiejar.py
Lib/test/test_http_cookiejar.py
+73
-84
No files found.
Lib/test/test_http_cookiejar.py
Dosyayı görüntüle @
80b2aa0a
...
@@ -28,8 +28,8 @@ class DateTimeTests(unittest.TestCase):
...
@@ -28,8 +28,8 @@ class DateTimeTests(unittest.TestCase):
az
=
time2isoz
()
az
=
time2isoz
()
bz
=
time2isoz
(
500000
)
bz
=
time2isoz
(
500000
)
for
text
in
(
az
,
bz
):
for
text
in
(
az
,
bz
):
self
.
assert
True
(
re
.
search
(
r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$"
,
text
)
,
self
.
assert
Regex
(
text
,
r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$"
,
"bad time2isoz format:
%
s
%
s"
%
(
az
,
bz
))
"bad time2isoz format:
%
s
%
s"
%
(
az
,
bz
))
def
test_http2time
(
self
):
def
test_http2time
(
self
):
def
parse_date
(
text
):
def
parse_date
(
text
):
...
@@ -75,12 +75,9 @@ class DateTimeTests(unittest.TestCase):
...
@@ -75,12 +75,9 @@ class DateTimeTests(unittest.TestCase):
"
%
s => '
%
s' (
%
s)"
%
(
test_t
,
result
,
expected
))
"
%
s => '
%
s' (
%
s)"
%
(
test_t
,
result
,
expected
))
for
s
in
tests
:
for
s
in
tests
:
t
=
http2time
(
s
)
self
.
assertEqual
(
http2time
(
s
),
test_t
,
s
)
t2
=
http2time
(
s
.
lower
())
self
.
assertEqual
(
http2time
(
s
.
lower
()),
test_t
,
s
.
lower
())
t3
=
http2time
(
s
.
upper
())
self
.
assertEqual
(
http2time
(
s
.
upper
()),
test_t
,
s
.
upper
())
self
.
assertTrue
(
t
==
t2
==
t3
==
test_t
,
"'
%
s' =>
%
s,
%
s,
%
s (
%
s)"
%
(
s
,
t
,
t2
,
t3
,
test_t
))
def
test_http2time_garbage
(
self
):
def
test_http2time_garbage
(
self
):
for
test
in
[
for
test
in
[
...
@@ -134,12 +131,9 @@ class DateTimeTests(unittest.TestCase):
...
@@ -134,12 +131,9 @@ class DateTimeTests(unittest.TestCase):
test_t
=
760233600
# assume broken POSIX counting of seconds
test_t
=
760233600
# assume broken POSIX counting of seconds
for
s
in
tests
:
for
s
in
tests
:
t
=
iso2time
(
s
)
self
.
assertEqual
(
iso2time
(
s
),
test_t
,
s
)
t2
=
iso2time
(
s
.
lower
())
self
.
assertEqual
(
iso2time
(
s
.
lower
()),
test_t
,
s
.
lower
())
t3
=
iso2time
(
s
.
upper
())
self
.
assertEqual
(
iso2time
(
s
.
upper
()),
test_t
,
s
.
upper
())
self
.
assertTrue
(
t
==
t2
==
t3
==
test_t
,
"'
%
s' =>
%
s,
%
s,
%
s (
%
s)"
%
(
s
,
t
,
t2
,
t3
,
test_t
))
def
test_iso2time_garbage
(
self
):
def
test_iso2time_garbage
(
self
):
for
test
in
[
for
test
in
[
...
@@ -411,7 +405,7 @@ class CookieTests(unittest.TestCase):
...
@@ -411,7 +405,7 @@ class CookieTests(unittest.TestCase):
request
=
urllib
.
request
.
Request
(
url
)
request
=
urllib
.
request
.
Request
(
url
)
r
=
pol
.
domain_return_ok
(
domain
,
request
)
r
=
pol
.
domain_return_ok
(
domain
,
request
)
if
ok
:
self
.
assertTrue
(
r
)
if
ok
:
self
.
assertTrue
(
r
)
else
:
self
.
assert
True
(
not
r
)
else
:
self
.
assert
False
(
r
)
def
test_missing_value
(
self
):
def
test_missing_value
(
self
):
# missing = sign in Cookie: header is regarded by Mozilla as a missing
# missing = sign in Cookie: header is regarded by Mozilla as a missing
...
@@ -421,10 +415,10 @@ class CookieTests(unittest.TestCase):
...
@@ -421,10 +415,10 @@ class CookieTests(unittest.TestCase):
interact_netscape
(
c
,
"http://www.acme.com/"
,
'eggs'
)
interact_netscape
(
c
,
"http://www.acme.com/"
,
'eggs'
)
interact_netscape
(
c
,
"http://www.acme.com/"
,
'"spam"; path=/foo/'
)
interact_netscape
(
c
,
"http://www.acme.com/"
,
'"spam"; path=/foo/'
)
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"eggs"
]
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"eggs"
]
self
.
assert
True
(
cookie
.
value
is
Non
e
)
self
.
assert
IsNone
(
cookie
.
valu
e
)
self
.
assertEqual
(
cookie
.
name
,
"eggs"
)
self
.
assertEqual
(
cookie
.
name
,
"eggs"
)
cookie
=
c
.
_cookies
[
"www.acme.com"
][
'/foo/'
][
'"spam"'
]
cookie
=
c
.
_cookies
[
"www.acme.com"
][
'/foo/'
][
'"spam"'
]
self
.
assert
True
(
cookie
.
value
is
Non
e
)
self
.
assert
IsNone
(
cookie
.
valu
e
)
self
.
assertEqual
(
cookie
.
name
,
'"spam"'
)
self
.
assertEqual
(
cookie
.
name
,
'"spam"'
)
self
.
assertEqual
(
lwp_cookie_str
(
cookie
),
(
self
.
assertEqual
(
lwp_cookie_str
(
cookie
),
(
r'"spam"; path="/foo/"; domain="www.acme.com"; '
r'"spam"; path="/foo/"; domain="www.acme.com"; '
...
@@ -466,7 +460,7 @@ class CookieTests(unittest.TestCase):
...
@@ -466,7 +460,7 @@ class CookieTests(unittest.TestCase):
try
:
try
:
cookie
=
c
.
_cookies
[
"www.example.com"
][
"/"
][
"ni"
]
cookie
=
c
.
_cookies
[
"www.example.com"
][
"/"
][
"ni"
]
except
KeyError
:
except
KeyError
:
self
.
assert
True
(
version
is
None
)
# didn't expect a stored cookie
self
.
assert
IsNone
(
version
)
# didn't expect a stored cookie
else
:
else
:
self
.
assertEqual
(
cookie
.
version
,
version
)
self
.
assertEqual
(
cookie
.
version
,
version
)
# 2965 cookies are unaffected
# 2965 cookies are unaffected
...
@@ -490,26 +484,26 @@ class CookieTests(unittest.TestCase):
...
@@ -490,26 +484,26 @@ class CookieTests(unittest.TestCase):
self
.
assertEqual
(
cookie
.
domain
,
".acme.com"
)
self
.
assertEqual
(
cookie
.
domain
,
".acme.com"
)
self
.
assertTrue
(
cookie
.
domain_specified
)
self
.
assertTrue
(
cookie
.
domain_specified
)
self
.
assertEqual
(
cookie
.
port
,
DEFAULT_HTTP_PORT
)
self
.
assertEqual
(
cookie
.
port
,
DEFAULT_HTTP_PORT
)
self
.
assert
True
(
not
cookie
.
port_specified
)
self
.
assert
False
(
cookie
.
port_specified
)
# case is preserved
# case is preserved
self
.
assertTrue
(
cookie
.
has_nonstandard_attr
(
"blArgh"
)
and
self
.
assertTrue
(
cookie
.
has_nonstandard_attr
(
"blArgh"
)
)
not
cookie
.
has_nonstandard_attr
(
"blargh"
))
self
.
assertFalse
(
cookie
.
has_nonstandard_attr
(
"blargh"
))
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"ni"
]
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"ni"
]
self
.
assertEqual
(
cookie
.
domain
,
"www.acme.com"
)
self
.
assertEqual
(
cookie
.
domain
,
"www.acme.com"
)
self
.
assert
True
(
not
cookie
.
domain_specified
)
self
.
assert
False
(
cookie
.
domain_specified
)
self
.
assertEqual
(
cookie
.
port
,
"80,8080"
)
self
.
assertEqual
(
cookie
.
port
,
"80,8080"
)
self
.
assertTrue
(
cookie
.
port_specified
)
self
.
assertTrue
(
cookie
.
port_specified
)
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"nini"
]
cookie
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"nini"
]
self
.
assert
True
(
cookie
.
port
is
None
)
self
.
assert
IsNone
(
cookie
.
port
)
self
.
assert
True
(
not
cookie
.
port_specified
)
self
.
assert
False
(
cookie
.
port_specified
)
# invalid expires should not cause cookie to be dropped
# invalid expires should not cause cookie to be dropped
foo
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo"
]
foo
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo"
]
spam
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo"
]
spam
=
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo"
]
self
.
assert
True
(
foo
.
expires
is
None
)
self
.
assert
IsNone
(
foo
.
expires
)
self
.
assert
True
(
spam
.
expires
is
None
)
self
.
assert
IsNone
(
spam
.
expires
)
def
test_ns_parser_special_names
(
self
):
def
test_ns_parser_special_names
(
self
):
# names such as 'expires' are not special in first name=value pair
# names such as 'expires' are not special in first name=value pair
...
@@ -679,12 +673,12 @@ class CookieTests(unittest.TestCase):
...
@@ -679,12 +673,12 @@ class CookieTests(unittest.TestCase):
def
test_is_HDN
(
self
):
def
test_is_HDN
(
self
):
self
.
assertTrue
(
is_HDN
(
"foo.bar.com"
))
self
.
assertTrue
(
is_HDN
(
"foo.bar.com"
))
self
.
assertTrue
(
is_HDN
(
"1foo2.3bar4.5com"
))
self
.
assertTrue
(
is_HDN
(
"1foo2.3bar4.5com"
))
self
.
assert
True
(
not
is_HDN
(
"192.168.1.1"
))
self
.
assert
False
(
is_HDN
(
"192.168.1.1"
))
self
.
assert
True
(
not
is_HDN
(
""
))
self
.
assert
False
(
is_HDN
(
""
))
self
.
assert
True
(
not
is_HDN
(
"."
))
self
.
assert
False
(
is_HDN
(
"."
))
self
.
assert
True
(
not
is_HDN
(
".foo.bar.com"
))
self
.
assert
False
(
is_HDN
(
".foo.bar.com"
))
self
.
assert
True
(
not
is_HDN
(
"..foo"
))
self
.
assert
False
(
is_HDN
(
"..foo"
))
self
.
assert
True
(
not
is_HDN
(
"foo."
))
self
.
assert
False
(
is_HDN
(
"foo."
))
def
test_reach
(
self
):
def
test_reach
(
self
):
self
.
assertEqual
(
reach
(
"www.acme.com"
),
".acme.com"
)
self
.
assertEqual
(
reach
(
"www.acme.com"
),
".acme.com"
)
...
@@ -698,39 +692,39 @@ class CookieTests(unittest.TestCase):
...
@@ -698,39 +692,39 @@ class CookieTests(unittest.TestCase):
def
test_domain_match
(
self
):
def
test_domain_match
(
self
):
self
.
assertTrue
(
domain_match
(
"192.168.1.1"
,
"192.168.1.1"
))
self
.
assertTrue
(
domain_match
(
"192.168.1.1"
,
"192.168.1.1"
))
self
.
assert
True
(
not
domain_match
(
"192.168.1.1"
,
".168.1.1"
))
self
.
assert
False
(
domain_match
(
"192.168.1.1"
,
".168.1.1"
))
self
.
assertTrue
(
domain_match
(
"x.y.com"
,
"x.Y.com"
))
self
.
assertTrue
(
domain_match
(
"x.y.com"
,
"x.Y.com"
))
self
.
assertTrue
(
domain_match
(
"x.y.com"
,
".Y.com"
))
self
.
assertTrue
(
domain_match
(
"x.y.com"
,
".Y.com"
))
self
.
assert
True
(
not
domain_match
(
"x.y.com"
,
"Y.com"
))
self
.
assert
False
(
domain_match
(
"x.y.com"
,
"Y.com"
))
self
.
assertTrue
(
domain_match
(
"a.b.c.com"
,
".c.com"
))
self
.
assertTrue
(
domain_match
(
"a.b.c.com"
,
".c.com"
))
self
.
assert
True
(
not
domain_match
(
".c.com"
,
"a.b.c.com"
))
self
.
assert
False
(
domain_match
(
".c.com"
,
"a.b.c.com"
))
self
.
assertTrue
(
domain_match
(
"example.local"
,
".local"
))
self
.
assertTrue
(
domain_match
(
"example.local"
,
".local"
))
self
.
assert
True
(
not
domain_match
(
"blah.blah"
,
""
))
self
.
assert
False
(
domain_match
(
"blah.blah"
,
""
))
self
.
assert
True
(
not
domain_match
(
""
,
".rhubarb.rhubarb"
))
self
.
assert
False
(
domain_match
(
""
,
".rhubarb.rhubarb"
))
self
.
assertTrue
(
domain_match
(
""
,
""
))
self
.
assertTrue
(
domain_match
(
""
,
""
))
self
.
assertTrue
(
user_domain_match
(
"acme.com"
,
"acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"acme.com"
,
"acme.com"
))
self
.
assert
True
(
not
user_domain_match
(
"acme.com"
,
".acme.com"
))
self
.
assert
False
(
user_domain_match
(
"acme.com"
,
".acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"rhubarb.acme.com"
,
".acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"rhubarb.acme.com"
,
".acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"www.rhubarb.acme.com"
,
".acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"www.rhubarb.acme.com"
,
".acme.com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
"x.Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
"x.Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
".Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
".Y.com"
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
"Y.com"
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
"Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"y.com"
,
"Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"y.com"
,
"Y.com"
))
self
.
assert
True
(
not
user_domain_match
(
".y.com"
,
"Y.com"
))
self
.
assert
False
(
user_domain_match
(
".y.com"
,
"Y.com"
))
self
.
assertTrue
(
user_domain_match
(
".y.com"
,
".Y.com"
))
self
.
assertTrue
(
user_domain_match
(
".y.com"
,
".Y.com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
".com"
))
self
.
assertTrue
(
user_domain_match
(
"x.y.com"
,
".com"
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
"com"
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
"com"
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
"m"
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
"m"
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
".m"
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
".m"
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
""
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
""
))
self
.
assert
True
(
not
user_domain_match
(
"x.y.com"
,
"."
))
self
.
assert
False
(
user_domain_match
(
"x.y.com"
,
"."
))
self
.
assertTrue
(
user_domain_match
(
"192.168.1.1"
,
"192.168.1.1"
))
self
.
assertTrue
(
user_domain_match
(
"192.168.1.1"
,
"192.168.1.1"
))
# not both HDNs, so must string-compare equal to match
# not both HDNs, so must string-compare equal to match
self
.
assert
True
(
not
user_domain_match
(
"192.168.1.1"
,
".168.1.1"
))
self
.
assert
False
(
user_domain_match
(
"192.168.1.1"
,
".168.1.1"
))
self
.
assert
True
(
not
user_domain_match
(
"192.168.1.1"
,
"."
))
self
.
assert
False
(
user_domain_match
(
"192.168.1.1"
,
"."
))
# empty string is a special case
# empty string is a special case
self
.
assert
True
(
not
user_domain_match
(
"192.168.1.1"
,
""
))
self
.
assert
False
(
user_domain_match
(
"192.168.1.1"
,
""
))
def
test_wrong_domain
(
self
):
def
test_wrong_domain
(
self
):
# Cookies whose effective request-host name does not domain-match the
# Cookies whose effective request-host name does not domain-match the
...
@@ -877,7 +871,7 @@ class CookieTests(unittest.TestCase):
...
@@ -877,7 +871,7 @@ class CookieTests(unittest.TestCase):
self
.
assertEqual
(
len
(
c
),
2
)
self
.
assertEqual
(
len
(
c
),
2
)
# ... and check is doesn't get returned
# ... and check is doesn't get returned
c
.
add_cookie_header
(
req
)
c
.
add_cookie_header
(
req
)
self
.
assert
True
(
not
req
.
has_header
(
"Cookie"
))
self
.
assert
False
(
req
.
has_header
(
"Cookie"
))
def
test_domain_block
(
self
):
def
test_domain_block
(
self
):
pol
=
DefaultCookiePolicy
(
pol
=
DefaultCookiePolicy
(
...
@@ -901,8 +895,8 @@ class CookieTests(unittest.TestCase):
...
@@ -901,8 +895,8 @@ class CookieTests(unittest.TestCase):
self
.
assertEqual
(
len
(
c
),
1
)
self
.
assertEqual
(
len
(
c
),
1
)
req
=
urllib
.
request
.
Request
(
"http://www.roadrunner.net/"
)
req
=
urllib
.
request
.
Request
(
"http://www.roadrunner.net/"
)
c
.
add_cookie_header
(
req
)
c
.
add_cookie_header
(
req
)
self
.
assertTrue
(
(
req
.
has_header
(
"Cookie"
)
and
self
.
assertTrue
(
req
.
has_header
(
"Cookie"
))
req
.
has_header
(
"Cookie2"
)
))
self
.
assertTrue
(
req
.
has_header
(
"Cookie2"
))
c
.
clear
()
c
.
clear
()
pol
.
set_blocked_domains
([
".acme.com"
])
pol
.
set_blocked_domains
([
".acme.com"
])
...
@@ -917,7 +911,7 @@ class CookieTests(unittest.TestCase):
...
@@ -917,7 +911,7 @@ class CookieTests(unittest.TestCase):
self
.
assertEqual
(
len
(
c
),
2
)
self
.
assertEqual
(
len
(
c
),
2
)
# ... and check is doesn't get returned
# ... and check is doesn't get returned
c
.
add_cookie_header
(
req
)
c
.
add_cookie_header
(
req
)
self
.
assert
True
(
not
req
.
has_header
(
"Cookie"
))
self
.
assert
False
(
req
.
has_header
(
"Cookie"
))
def
test_secure
(
self
):
def
test_secure
(
self
):
for
ns
in
True
,
False
:
for
ns
in
True
,
False
:
...
@@ -935,8 +929,8 @@ class CookieTests(unittest.TestCase):
...
@@ -935,8 +929,8 @@ class CookieTests(unittest.TestCase):
url
=
"http://www.acme.com/"
url
=
"http://www.acme.com/"
int
(
c
,
url
,
"foo1=bar
%
s
%
s"
%
(
vs
,
whitespace
))
int
(
c
,
url
,
"foo1=bar
%
s
%
s"
%
(
vs
,
whitespace
))
int
(
c
,
url
,
"foo2=bar
%
s; secure
%
s"
%
(
vs
,
whitespace
))
int
(
c
,
url
,
"foo2=bar
%
s; secure
%
s"
%
(
vs
,
whitespace
))
self
.
assert
Tru
e
(
self
.
assert
Fals
e
(
not
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo1"
]
.
secure
,
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo1"
]
.
secure
,
"non-secure cookie registered secure"
)
"non-secure cookie registered secure"
)
self
.
assertTrue
(
self
.
assertTrue
(
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo2"
]
.
secure
,
c
.
_cookies
[
"www.acme.com"
][
"/"
][
"foo2"
]
.
secure
,
...
@@ -1009,8 +1003,8 @@ class CookieTests(unittest.TestCase):
...
@@ -1009,8 +1003,8 @@ class CookieTests(unittest.TestCase):
url
=
"http://foo.bar.com/"
url
=
"http://foo.bar.com/"
interact_2965
(
c
,
url
,
"spam=eggs; Version=1; Port"
)
interact_2965
(
c
,
url
,
"spam=eggs; Version=1; Port"
)
h
=
interact_2965
(
c
,
url
)
h
=
interact_2965
(
c
,
url
)
self
.
assert
True
(
re
.
search
(
"
\
$Port([^=]|$)"
,
h
)
,
self
.
assert
Regex
(
h
,
"
\
$Port([^=]|$)"
,
"port with no value not returned with no value"
)
"port with no value not returned with no value"
)
c
=
CookieJar
(
pol
)
c
=
CookieJar
(
pol
)
url
=
"http://foo.bar.com/"
url
=
"http://foo.bar.com/"
...
@@ -1034,8 +1028,7 @@ class CookieTests(unittest.TestCase):
...
@@ -1034,8 +1028,7 @@ class CookieTests(unittest.TestCase):
'Comment="does anybody read these?"; '
'Comment="does anybody read these?"; '
'CommentURL="http://foo.bar.net/comment.html"'
)
'CommentURL="http://foo.bar.net/comment.html"'
)
h
=
interact_2965
(
c
,
url
)
h
=
interact_2965
(
c
,
url
)
self
.
assertTrue
(
self
.
assertNotIn
(
"Comment"
,
h
,
"Comment"
not
in
h
,
"Comment or CommentURL cookie-attributes returned to server"
)
"Comment or CommentURL cookie-attributes returned to server"
)
def
test_Cookie_iterator
(
self
):
def
test_Cookie_iterator
(
self
):
...
@@ -1063,7 +1056,7 @@ class CookieTests(unittest.TestCase):
...
@@ -1063,7 +1056,7 @@ class CookieTests(unittest.TestCase):
for
i
in
range
(
4
):
for
i
in
range
(
4
):
i
=
0
i
=
0
for
c
in
cs
:
for
c
in
cs
:
self
.
assert
True
(
isinstance
(
c
,
Cookie
)
)
self
.
assert
IsInstance
(
c
,
Cookie
)
self
.
assertEqual
(
c
.
version
,
versions
[
i
])
self
.
assertEqual
(
c
.
version
,
versions
[
i
])
self
.
assertEqual
(
c
.
name
,
names
[
i
])
self
.
assertEqual
(
c
.
name
,
names
[
i
])
self
.
assertEqual
(
c
.
domain
,
domains
[
i
])
self
.
assertEqual
(
c
.
domain
,
domains
[
i
])
...
@@ -1118,7 +1111,7 @@ class CookieTests(unittest.TestCase):
...
@@ -1118,7 +1111,7 @@ class CookieTests(unittest.TestCase):
headers
=
[
"Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000"
]
headers
=
[
"Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000"
]
c
=
cookiejar_from_cookie_headers
(
headers
)
c
=
cookiejar_from_cookie_headers
(
headers
)
cookie
=
c
.
_cookies
[
"www.example.com"
][
"/"
][
"c"
]
cookie
=
c
.
_cookies
[
"www.example.com"
][
"/"
][
"c"
]
self
.
assert
True
(
cookie
.
expires
is
None
)
self
.
assert
IsNone
(
cookie
.
expires
)
class
LWPCookieTests
(
unittest
.
TestCase
):
class
LWPCookieTests
(
unittest
.
TestCase
):
...
@@ -1262,9 +1255,9 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1262,9 +1255,9 @@ class LWPCookieTests(unittest.TestCase):
req
=
urllib
.
request
.
Request
(
"http://www.acme.com/ammo"
)
req
=
urllib
.
request
.
Request
(
"http://www.acme.com/ammo"
)
c
.
add_cookie_header
(
req
)
c
.
add_cookie_header
(
req
)
self
.
assert
True
(
re
.
search
(
r"PART_NUMBER=RIDING_ROCKET_0023;\s*"
self
.
assert
Regex
(
req
.
get_header
(
"Cookie"
),
"PART_NUMBER=ROCKET_LAUNCHER_0001"
,
r"PART_NUMBER=RIDING_ROCKET_0023;\s*"
req
.
get_header
(
"Cookie"
))
)
"PART_NUMBER=ROCKET_LAUNCHER_0001"
)
def
test_ietf_example_1
(
self
):
def
test_ietf_example_1
(
self
):
#-------------------------------------------------------------------
#-------------------------------------------------------------------
...
@@ -1297,7 +1290,7 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1297,7 +1290,7 @@ class LWPCookieTests(unittest.TestCase):
cookie
=
interact_2965
(
cookie
=
interact_2965
(
c
,
'http://www.acme.com/acme/login'
,
c
,
'http://www.acme.com/acme/login'
,
'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
)
'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
)
self
.
assert
True
(
not
cookie
)
self
.
assert
False
(
cookie
)
#
#
# 3. User Agent -> Server
# 3. User Agent -> Server
...
@@ -1319,9 +1312,8 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1319,9 +1312,8 @@ class LWPCookieTests(unittest.TestCase):
cookie
=
interact_2965
(
c
,
'http://www.acme.com/acme/pickitem'
,
cookie
=
interact_2965
(
c
,
'http://www.acme.com/acme/pickitem'
,
'Part_Number="Rocket_Launcher_0001"; '
'Part_Number="Rocket_Launcher_0001"; '
'Version="1"; Path="/acme"'
);
'Version="1"; Path="/acme"'
);
self
.
assertTrue
(
re
.
search
(
self
.
assertRegex
(
cookie
,
r'^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$'
,
r'^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$'
)
cookie
))
#
#
# 5. User Agent -> Server
# 5. User Agent -> Server
...
@@ -1344,11 +1336,11 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1344,11 +1336,11 @@ class LWPCookieTests(unittest.TestCase):
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/shipping"
,
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/shipping"
,
'Shipping="FedEx"; Version="1"; Path="/acme"'
)
'Shipping="FedEx"; Version="1"; Path="/acme"'
)
self
.
assert
True
(
re
.
search
(
r'^\$Version="?1"?;'
,
cookie
)
)
self
.
assert
Regex
(
cookie
,
r'^\$Version="?1"?;'
)
self
.
assert
True
(
re
.
search
(
r'Part_Number="?Rocket_Launcher_0001"?;'
self
.
assert
Regex
(
cookie
,
r'Part_Number="?Rocket_Launcher_0001"?;'
'
\
s*
\
$Path="
\
/acme"'
,
cookie
)
)
'
\
s*
\
$Path="
\
/acme"'
)
self
.
assert
True
(
re
.
search
(
r'Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"'
,
self
.
assert
Regex
(
cookie
,
r'Customer="?WILE_E_COYOTE"?;'
cookie
)
)
'
\
s*
\
$Path="
\
/acme"'
)
#
#
# 7. User Agent -> Server
# 7. User Agent -> Server
...
@@ -1369,9 +1361,8 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1369,9 +1361,8 @@ class LWPCookieTests(unittest.TestCase):
# Transaction is complete.
# Transaction is complete.
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/process"
)
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/process"
)
self
.
assertTrue
(
self
.
assertRegex
(
cookie
,
r'Shipping="?FedEx"?;\s*\$Path="\/acme"'
)
re
.
search
(
r'Shipping="?FedEx"?;\s*\$Path="\/acme"'
,
cookie
)
and
self
.
assertIn
(
"WILE_E_COYOTE"
,
cookie
)
"WILE_E_COYOTE"
in
cookie
)
#
#
# The user agent makes a series of requests on the origin server, after
# The user agent makes a series of requests on the origin server, after
...
@@ -1418,8 +1409,7 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1418,8 +1409,7 @@ class LWPCookieTests(unittest.TestCase):
# than once.
# than once.
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/ammo/..."
)
cookie
=
interact_2965
(
c
,
"http://www.acme.com/acme/ammo/..."
)
self
.
assertTrue
(
self
.
assertRegex
(
cookie
,
r"Riding_Rocket_0023.*Rocket_Launcher_0001"
)
re
.
search
(
r"Riding_Rocket_0023.*Rocket_Launcher_0001"
,
cookie
))
# A subsequent request by the user agent to the (same) server for a URL of
# A subsequent request by the user agent to the (same) server for a URL of
# the form /acme/parts/ would include the following request header:
# the form /acme/parts/ would include the following request header:
...
@@ -1445,7 +1435,7 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1445,7 +1435,7 @@ class LWPCookieTests(unittest.TestCase):
# illegal domain (no embedded dots)
# illegal domain (no embedded dots)
cookie
=
interact_2965
(
c
,
"http://www.acme.com"
,
cookie
=
interact_2965
(
c
,
"http://www.acme.com"
,
'foo=bar; domain=".com"; version=1'
)
'foo=bar; domain=".com"; version=1'
)
self
.
assert
True
(
not
c
)
self
.
assert
False
(
c
)
# legal domain
# legal domain
cookie
=
interact_2965
(
c
,
"http://www.acme.com"
,
cookie
=
interact_2965
(
c
,
"http://www.acme.com"
,
...
@@ -1538,11 +1528,11 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1538,11 +1528,11 @@ class LWPCookieTests(unittest.TestCase):
'bar=baz; path="/foo/"; version=1'
);
'bar=baz; path="/foo/"; version=1'
);
version_re
=
re
.
compile
(
r'^\$version=\"?1\"?'
,
re
.
I
)
version_re
=
re
.
compile
(
r'^\$version=\"?1\"?'
,
re
.
I
)
self
.
assertIn
(
"foo=bar"
,
cookie
)
self
.
assertIn
(
"foo=bar"
,
cookie
)
self
.
assert
True
(
version_re
.
search
(
cookie
)
)
self
.
assert
Regex
(
cookie
,
version_re
)
cookie
=
interact_2965
(
cookie
=
interact_2965
(
c
,
"http://www.acme.com/foo/
%25
/<<
%0
anew
\345
/
\346\370\345
"
)
c
,
"http://www.acme.com/foo/
%25
/<<
%0
anew
\345
/
\346\370\345
"
)
self
.
assert
True
(
not
cookie
)
self
.
assert
False
(
cookie
)
# unicode URL doesn't raise exception
# unicode URL doesn't raise exception
cookie
=
interact_2965
(
c
,
"http://www.acme.com/
\xfc
"
)
cookie
=
interact_2965
(
c
,
"http://www.acme.com/
\xfc
"
)
...
@@ -1703,13 +1693,12 @@ class LWPCookieTests(unittest.TestCase):
...
@@ -1703,13 +1693,12 @@ class LWPCookieTests(unittest.TestCase):
key
=
"
%
s_after"
%
cookie
.
value
key
=
"
%
s_after"
%
cookie
.
value
counter
[
key
]
=
counter
[
key
]
+
1
counter
[
key
]
=
counter
[
key
]
+
1
self
.
assertTrue
(
not
(
# a permanent cookie got lost accidently
# a permanent cookie got lost accidently
counter
[
"perm_after"
]
!=
counter
[
"perm_before"
]
or
self
.
assertEqual
(
counter
[
"perm_after"
],
counter
[
"perm_before"
])
# a session cookie hasn't been cleared
# a session cookie hasn't been cleared
counter
[
"session_after"
]
!=
0
or
self
.
assertEqual
(
counter
[
"session_after"
],
0
)
# we didn't have session cookies in the first place
# we didn't have session cookies in the first place
counter
[
"session_before"
]
==
0
)
)
self
.
assertNotEqual
(
counter
[
"session_before"
],
0
)
def
test_main
(
verbose
=
None
):
def
test_main
(
verbose
=
None
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment