Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
a1a3e515
Kaydet (Commit)
a1a3e515
authored
Mar 02, 2018
tarafından
Alex Tomic
Kaydeden (comit)
Tim Graham
Mar 02, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29133 -- Fixed call_command() crash if a required option is passed in options.
üst
40bac28f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
__init__.py
django/core/management/__init__.py
+8
-1
required_option.py
tests/user_commands/management/commands/required_option.py
+11
-0
tests.py
tests/user_commands/tests.py
+12
-0
No files found.
django/core/management/__init__.py
Dosyayı görüntüle @
a1a3e515
...
@@ -117,7 +117,14 @@ def call_command(command_name, *args, **options):
...
@@ -117,7 +117,14 @@ def call_command(command_name, *args, **options):
for
s_opt
in
parser
.
_actions
if
s_opt
.
option_strings
for
s_opt
in
parser
.
_actions
if
s_opt
.
option_strings
}
}
arg_options
=
{
opt_mapping
.
get
(
key
,
key
):
value
for
key
,
value
in
options
.
items
()}
arg_options
=
{
opt_mapping
.
get
(
key
,
key
):
value
for
key
,
value
in
options
.
items
()}
defaults
=
parser
.
parse_args
(
args
=
[
str
(
a
)
for
a
in
args
])
parse_args
=
[
str
(
a
)
for
a
in
args
]
# Any required arguments which are passed in via **options must must be
# passed to parse_args().
parse_args
+=
[
'{}={}'
.
format
(
min
(
opt
.
option_strings
),
arg_options
[
opt
.
dest
])
for
opt
in
parser
.
_actions
if
opt
.
required
and
opt
.
dest
in
options
]
defaults
=
parser
.
parse_args
(
args
=
parse_args
)
defaults
=
dict
(
defaults
.
_get_kwargs
(),
**
arg_options
)
defaults
=
dict
(
defaults
.
_get_kwargs
(),
**
arg_options
)
# Raise an error if any unknown options were passed.
# Raise an error if any unknown options were passed.
stealth_options
=
set
(
command
.
base_stealth_options
+
command
.
stealth_options
)
stealth_options
=
set
(
command
.
base_stealth_options
+
command
.
stealth_options
)
...
...
tests/user_commands/management/commands/required_option.py
0 → 100644
Dosyayı görüntüle @
a1a3e515
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'-n'
,
'--need-me'
,
required
=
True
)
parser
.
add_argument
(
'-t'
,
'--need-me-too'
,
required
=
True
,
dest
=
'needme2'
)
def
handle
(
self
,
*
args
,
**
options
):
self
.
stdout
.
write
(
','
.
join
(
options
))
tests/user_commands/tests.py
Dosyayı görüntüle @
a1a3e515
...
@@ -194,6 +194,18 @@ class CommandTests(SimpleTestCase):
...
@@ -194,6 +194,18 @@ class CommandTests(SimpleTestCase):
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
management
.
call_command
(
'dance'
,
unrecognized
=
1
,
unrecognized2
=
1
)
management
.
call_command
(
'dance'
,
unrecognized
=
1
,
unrecognized2
=
1
)
def
test_call_command_with_required_parameters_in_options
(
self
):
out
=
StringIO
()
management
.
call_command
(
'required_option'
,
need_me
=
'foo'
,
needme2
=
'bar'
,
stdout
=
out
)
self
.
assertIn
(
'need_me'
,
out
.
getvalue
())
self
.
assertIn
(
'needme2'
,
out
.
getvalue
())
def
test_call_command_with_required_parameters_in_mixed_options
(
self
):
out
=
StringIO
()
management
.
call_command
(
'required_option'
,
'--need-me=foo'
,
needme2
=
'bar'
,
stdout
=
out
)
self
.
assertIn
(
'need_me'
,
out
.
getvalue
())
self
.
assertIn
(
'needme2'
,
out
.
getvalue
())
class
CommandRunTests
(
AdminScriptTestCase
):
class
CommandRunTests
(
AdminScriptTestCase
):
"""
"""
...
...
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