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
71a20897
Kaydet (Commit)
71a20897
authored
Eki 29, 2006
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Completely convert test_httplib to unittest.
üst
e1844336
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
103 deletions
+63
-103
test_httplib
Lib/test/output/test_httplib
+0
-13
test_httplib.py
Lib/test/test_httplib.py
+63
-90
No files found.
Lib/test/output/test_httplib
deleted
100644 → 0
Dosyayı görüntüle @
e1844336
test_httplib
reply: 'HTTP/1.1 200 Ok\r\n'
Text
reply: 'HTTP/1.1 400.100 Not Ok\r\n'
BadStatusLine raised as expected
InvalidURL raised as expected
InvalidURL raised as expected
reply: 'HTTP/1.1 200 OK\r\n'
header: Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
header: Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"
reply: 'HTTP/1.1 200 OK\r\n'
header: Content-Length: 14432
Lib/test/test_httplib.py
Dosyayı görüntüle @
71a20897
...
...
@@ -70,95 +70,68 @@ class HeaderTests(TestCase):
conn
.
request
(
'POST'
,
'/'
,
body
,
headers
)
self
.
assertEqual
(
conn
.
_buffer
.
count
[
header
.
lower
()],
1
)
# Collect output to a buffer so that we don't have to cope with line-ending
# issues across platforms. Specifically, the headers will have \r\n pairs
# and some platforms will strip them from the output file.
def
test
():
buf
=
StringIO
.
StringIO
()
_stdout
=
sys
.
stdout
try
:
sys
.
stdout
=
buf
_test
()
finally
:
sys
.
stdout
=
_stdout
# print individual lines with endings stripped
s
=
buf
.
getvalue
()
for
line
in
s
.
split
(
"
\n
"
):
print
line
.
strip
()
def
_test
():
# Test HTTP status lines
body
=
"HTTP/1.1 200 Ok
\r\n\r\n
Text"
sock
=
FakeSocket
(
body
)
resp
=
httplib
.
HTTPResponse
(
sock
,
1
)
resp
.
begin
()
print
resp
.
read
()
resp
.
close
()
body
=
"HTTP/1.1 400.100 Not Ok
\r\n\r\n
Text"
sock
=
FakeSocket
(
body
)
resp
=
httplib
.
HTTPResponse
(
sock
,
1
)
try
:
class
BasicTest
(
TestCase
):
def
test_status_lines
(
self
):
# Test HTTP status lines
body
=
"HTTP/1.1 200 Ok
\r\n\r\n
Text"
sock
=
FakeSocket
(
body
)
resp
=
httplib
.
HTTPResponse
(
sock
)
resp
.
begin
()
except
httplib
.
BadStatusLine
:
print
"BadStatusLine raised as expected"
else
:
print
"Expect BadStatusLine"
# Check invalid host_port
for
hp
in
(
"www.python.org:abc"
,
"www.python.org:"
):
try
:
h
=
httplib
.
HTTP
(
hp
)
except
httplib
.
InvalidURL
:
print
"InvalidURL raised as expected"
else
:
print
"Expect InvalidURL"
for
hp
,
h
,
p
in
((
"[fe80::207:e9ff:fe9b]:8000"
,
"fe80::207:e9ff:fe9b"
,
8000
),
(
"www.python.org:80"
,
"www.python.org"
,
80
),
(
"www.python.org"
,
"www.python.org"
,
80
),
(
"[fe80::207:e9ff:fe9b]"
,
"fe80::207:e9ff:fe9b"
,
80
)):
try
:
self
.
assertEqual
(
resp
.
read
(),
'Text'
)
resp
.
close
()
body
=
"HTTP/1.1 400.100 Not Ok
\r\n\r\n
Text"
sock
=
FakeSocket
(
body
)
resp
=
httplib
.
HTTPResponse
(
sock
)
self
.
assertRaises
(
httplib
.
BadStatusLine
,
resp
.
begin
)
def
test_host_port
(
self
):
# Check invalid host_port
for
hp
in
(
"www.python.org:abc"
,
"www.python.org:"
):
self
.
assertRaises
(
httplib
.
InvalidURL
,
httplib
.
HTTP
,
hp
)
for
hp
,
h
,
p
in
((
"[fe80::207:e9ff:fe9b]:8000"
,
"fe80::207:e9ff:fe9b"
,
8000
),
(
"www.python.org:80"
,
"www.python.org"
,
80
),
(
"www.python.org"
,
"www.python.org"
,
80
),
(
"[fe80::207:e9ff:fe9b]"
,
"fe80::207:e9ff:fe9b"
,
80
)):
http
=
httplib
.
HTTP
(
hp
)
except
httplib
.
InvalidURL
:
print
"InvalidURL raised erroneously"
c
=
http
.
_conn
if
h
!=
c
.
host
:
raise
AssertionError
,
(
"Host incorrectly parsed"
,
h
,
c
.
host
)
if
p
!=
c
.
port
:
raise
AssertionError
,
(
"Port incorrectly parsed"
,
p
,
c
.
host
)
# test response with multiple message headers with the same field name.
text
=
(
'HTTP/1.1 200 OK
\r\n
'
'Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
\r\n
'
'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
'
' Path="/acme"
\r\n
'
'
\r\n
'
'No body
\r\n
'
)
hdr
=
(
'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
'
', '
'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"'
)
s
=
FakeSocket
(
text
)
r
=
httplib
.
HTTPResponse
(
s
,
1
)
r
.
begin
(
)
cookies
=
r
.
getheader
(
"Set-Cookie"
)
if
cookies
!=
hdr
:
raise
AssertionError
,
"multiple headers not combined properly"
# Test that the library doesn't attempt to read any data
# from a HEAD request. (Tickles SF bug #622042.)
sock
=
FakeSocket
(
'HTTP/1.1 200 OK
\r\n
'
'Content-Length: 14432
\r\n
'
'
\r\n
'
,
NoEOFStringIO
)
resp
=
httplib
.
HTTPResponse
(
sock
,
1
,
method
=
"HEAD"
)
resp
.
begin
()
if
resp
.
read
()
!=
""
:
raise
AssertionError
,
"Did not expect response from HEAD request"
resp
.
close
()
c
=
http
.
_conn
if
h
!=
c
.
host
:
self
.
fail
(
"Host incorrectly parsed:
%
s !=
%
s"
%
(
h
,
c
.
host
))
if
p
!=
c
.
port
:
self
.
fail
(
"Port incorrectly parsed:
%
s !=
%
s"
%
(
p
,
c
.
host
))
def
test_response_headers
(
self
):
# test response with multiple message headers with the same field name.
text
=
(
'HTTP/1.1 200 OK
\r\n
'
'Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"
\r\n
'
'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";
'
' Path="/acme"
\r\n
'
'
\r\n
'
'No body
\r\n
'
)
hdr
=
(
'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
',
'
'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"'
)
s
=
FakeSocket
(
text
)
r
=
httplib
.
HTTPResponse
(
s
)
r
.
begin
(
)
cookies
=
r
.
getheader
(
"Set-Cookie"
)
if
cookies
!=
hdr
:
self
.
fail
(
"multiple headers not combined properly"
)
def
test_read_head
(
self
):
# Test that the library doesn't attempt to read any data
# from a HEAD request. (Tickles SF bug #622042.)
sock
=
FakeSocket
(
'HTTP/1.1 200 OK
\r\n
'
'Content-Length: 14432
\r\n
'
'
\r\n
'
,
NoEOFStringIO
)
resp
=
httplib
.
HTTPResponse
(
sock
,
method
=
"HEAD"
)
resp
.
begin
()
if
resp
.
read
()
!=
""
:
self
.
fail
(
"Did not expect response from HEAD request"
)
resp
.
close
()
class
OfflineTest
(
TestCase
):
...
...
@@ -166,7 +139,7 @@ class OfflineTest(TestCase):
self
.
assertEquals
(
httplib
.
responses
[
httplib
.
NOT_FOUND
],
"Not Found"
)
def
test_main
(
verbose
=
None
):
tests
=
[
HeaderTests
,
OfflineTest
]
test_support
.
run_unittest
(
*
tests
)
test_support
.
run_unittest
(
HeaderTests
,
OfflineTest
,
BasicTest
)
test
()
if
__name__
==
'__main__'
:
test_main
()
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