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
ca2b8d28
Kaydet (Commit)
ca2b8d28
authored
Mar 31, 2009
tarafından
Tarek Ziadé
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
more tests for the register command
üst
02386289
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
42 deletions
+89
-42
register.py
Lib/distutils/command/register.py
+14
-9
test_register.py
Lib/distutils/tests/test_register.py
+75
-33
No files found.
Lib/distutils/command/register.py
Dosyayı görüntüle @
ca2b8d28
...
...
@@ -90,14 +90,14 @@ class register(PyPIRCCommand):
''' Fetch the list of classifiers from the server.
'''
response
=
urllib2
.
urlopen
(
self
.
repository
+
'?:action=list_classifiers'
)
print
response
.
read
(
)
log
.
info
(
response
.
read
()
)
def
verify_metadata
(
self
):
''' Send the metadata to the package index server to be checked.
'''
# send the info to the server and report the result
(
code
,
result
)
=
self
.
post_to_server
(
self
.
build_post_data
(
'verify'
))
print
'Server response (
%
s):
%
s'
%
(
code
,
result
)
log
.
info
(
'Server response (
%
s):
%
s'
%
(
code
,
result
)
)
def
send_metadata
(
self
):
...
...
@@ -210,17 +210,18 @@ Your selection [default 1]: ''', log.INFO)
data
[
'email'
]
=
raw_input
(
' EMail: '
)
code
,
result
=
self
.
post_to_server
(
data
)
if
code
!=
200
:
print
'Server response (
%
s):
%
s'
%
(
code
,
result
)
log
.
info
(
'Server response (
%
s):
%
s'
%
(
code
,
result
)
)
else
:
print
'You will receive an email shortly.'
print
'Follow the instructions in it to complete registration.'
log
.
info
(
'You will receive an email shortly.'
)
log
.
info
((
'Follow the instructions in it to '
'complete registration.'
))
elif
choice
==
'3'
:
data
=
{
':action'
:
'password_reset'
}
data
[
'email'
]
=
''
while
not
data
[
'email'
]:
data
[
'email'
]
=
raw_input
(
'Your email address: '
)
code
,
result
=
self
.
post_to_server
(
data
)
print
'Server response (
%
s):
%
s'
%
(
code
,
result
)
log
.
info
(
'Server response (
%
s):
%
s'
%
(
code
,
result
)
)
def
build_post_data
(
self
,
action
):
# figure the data to send - the metadata plus some additional
...
...
@@ -253,8 +254,10 @@ Your selection [default 1]: ''', log.INFO)
def
post_to_server
(
self
,
data
,
auth
=
None
):
''' Post a query to the server, and return a string response.
'''
self
.
announce
(
'Registering
%
s to
%
s'
%
(
data
[
'name'
],
self
.
repository
),
log
.
INFO
)
if
'name'
in
data
:
self
.
announce
(
'Registering
%
s to
%
s'
%
(
data
[
'name'
],
self
.
repository
),
log
.
INFO
)
# Build up the MIME payload for the urllib2 POST data
boundary
=
'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
sep_boundary
=
'
\n
--'
+
boundary
...
...
@@ -301,5 +304,7 @@ Your selection [default 1]: ''', log.INFO)
data
=
result
.
read
()
result
=
200
,
'OK'
if
self
.
show_response
:
print
'-'
*
75
,
data
,
'-'
*
75
dashes
=
'-'
*
75
self
.
announce
(
'
%
s
%
s
%
s'
%
(
dashes
,
data
,
dashes
))
return
result
Lib/distutils/tests/test_register.py
Dosyayı görüntüle @
ca2b8d28
...
...
@@ -3,7 +3,9 @@ import sys
import
os
import
unittest
import
getpass
import
urllib2
from
distutils.command
import
register
as
register_module
from
distutils.command.register
import
register
from
distutils.core
import
Distribution
...
...
@@ -42,18 +44,20 @@ class RawInputs(object):
finally
:
self
.
index
+=
1
class
Fake
Serv
er
(
object
):
class
Fake
Open
er
(
object
):
"""Fakes a PyPI server"""
def
__init__
(
self
):
self
.
call
s
=
[]
self
.
req
s
=
[]
def
__call__
(
self
,
*
args
):
# we want to compare them, so let's store
# something comparable
els
=
args
[
0
]
.
items
()
els
.
sort
()
self
.
calls
.
append
(
tuple
(
els
))
return
200
,
'OK'
return
self
def
open
(
self
,
req
):
self
.
reqs
.
append
(
req
)
return
self
def
read
(
self
):
return
'xxx'
class
registerTestCase
(
PyPIRCCommandTestCase
):
...
...
@@ -64,24 +68,27 @@ class registerTestCase(PyPIRCCommandTestCase):
def
_getpass
(
prompt
):
return
'password'
getpass
.
getpass
=
_getpass
self
.
old_opener
=
urllib2
.
build_opener
self
.
conn
=
urllib2
.
build_opener
=
FakeOpener
()
def
tearDown
(
self
):
getpass
.
getpass
=
self
.
_old_getpass
urllib2
.
build_opener
=
self
.
old_opener
PyPIRCCommandTestCase
.
tearDown
(
self
)
def
_get_cmd
(
self
):
metadata
=
{
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
,
'name'
:
'xxx'
,
'version'
:
'xxx'
}
pkg_info
,
dist
=
self
.
create_dist
(
**
metadata
)
return
register
(
dist
)
def
test_create_pypirc
(
self
):
# this test makes sure a .pypirc file
# is created when requested.
# let's create a fake distribution
# and a register instance
dist
=
Distribution
()
dist
.
metadata
.
url
=
'xxx'
dist
.
metadata
.
author
=
'xxx'
dist
.
metadata
.
author_email
=
'xxx'
dist
.
metadata
.
name
=
'xxx'
dist
.
metadata
.
version
=
'xxx'
cmd
=
register
(
dist
)
# let's create a register instance
cmd
=
self
.
_get_cmd
()
# we shouldn't have a .pypirc file yet
self
.
assert_
(
not
os
.
path
.
exists
(
self
.
rc
))
...
...
@@ -95,13 +102,12 @@ class registerTestCase(PyPIRCCommandTestCase):
# Password : 'password'
# Save your login (y/N)? : 'y'
inputs
=
RawInputs
(
'1'
,
'tarek'
,
'y'
)
from
distutils.command
import
register
as
register_module
register_module
.
raw_input
=
inputs
.
__call__
cmd
.
post_to_server
=
pypi_server
=
FakeServer
()
# let's run the command
cmd
.
run
()
try
:
cmd
.
run
()
finally
:
del
register_module
.
raw_input
# we should have a brand new .pypirc file
self
.
assert_
(
os
.
path
.
exists
(
self
.
rc
))
...
...
@@ -117,30 +123,66 @@ class registerTestCase(PyPIRCCommandTestCase):
raise
AssertionError
(
prompt
)
register_module
.
raw_input
=
_no_way
cmd
.
show_response
=
1
cmd
.
run
()
# let's see what the server received : we should
# have 2 similar requests
self
.
assert_
(
len
(
pypi_server
.
calls
),
2
)
self
.
assert_
(
pypi_server
.
calls
[
0
],
pypi_server
.
calls
[
1
])
def
test_password_not_in_file
(
self
):
self
.
assert_
(
self
.
conn
.
reqs
,
2
)
req1
=
dict
(
self
.
conn
.
reqs
[
0
]
.
headers
)
req2
=
dict
(
self
.
conn
.
reqs
[
1
]
.
headers
)
f
=
open
(
self
.
rc
,
'w
'
)
f
.
write
(
PYPIRC_NOPASSWORD
)
f
.
close
(
)
self
.
assertEquals
(
req1
[
'Content-length'
],
'1374
'
)
self
.
assertEquals
(
req2
[
'Content-length'
],
'1374'
)
self
.
assert_
(
'xxx'
in
self
.
conn
.
reqs
[
1
]
.
data
)
dist
=
Distribution
()
cmd
=
register
(
dist
)
cmd
.
post_to_server
=
FakeServer
()
def
test_password_not_in_file
(
self
):
self
.
write_file
(
self
.
rc
,
PYPIRC_NOPASSWORD
)
cmd
=
self
.
_get_cmd
()
cmd
.
_set_config
()
cmd
.
finalize_options
()
cmd
.
send_metadata
()
# dist.password should be set
# therefore used afterwards by other commands
self
.
assertEquals
(
dist
.
password
,
'password'
)
self
.
assertEquals
(
cmd
.
distribution
.
password
,
'password'
)
def
test_registering
(
self
):
# this test runs choice 2
cmd
=
self
.
_get_cmd
()
inputs
=
RawInputs
(
'2'
,
'tarek'
,
'tarek@ziade.org'
)
register_module
.
raw_input
=
inputs
.
__call__
try
:
# let's run the command
cmd
.
run
()
finally
:
del
register_module
.
raw_input
# we should have send a request
self
.
assert_
(
self
.
conn
.
reqs
,
1
)
req
=
self
.
conn
.
reqs
[
0
]
headers
=
dict
(
req
.
headers
)
self
.
assertEquals
(
headers
[
'Content-length'
],
'608'
)
self
.
assert_
(
'tarek'
in
req
.
data
)
def
test_password_reset
(
self
):
# this test runs choice 3
cmd
=
self
.
_get_cmd
()
inputs
=
RawInputs
(
'3'
,
'tarek@ziade.org'
)
register_module
.
raw_input
=
inputs
.
__call__
try
:
# let's run the command
cmd
.
run
()
finally
:
del
register_module
.
raw_input
# we should have send a request
self
.
assert_
(
self
.
conn
.
reqs
,
1
)
req
=
self
.
conn
.
reqs
[
0
]
headers
=
dict
(
req
.
headers
)
self
.
assertEquals
(
headers
[
'Content-length'
],
'290'
)
self
.
assert_
(
'tarek'
in
req
.
data
)
def
test_suite
():
return
unittest
.
makeSuite
(
registerTestCase
)
...
...
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