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
71ff9a74
Kaydet (Commit)
71ff9a74
authored
Tem 17, 2017
tarafından
Srinivas Reddy Thatiparthy
Kaydeden (comit)
Tim Graham
Tem 17, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Created a dedicated test directory for FilePathField tests.
üst
776cee97
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
62 additions
and
90 deletions
+62
-90
README
tests/forms_tests/field_tests/filepathfield_test_dir/README
+0
-0
__init__.py
...orms_tests/field_tests/filepathfield_test_dir/__init__.py
+0
-0
a.py
tests/forms_tests/field_tests/filepathfield_test_dir/a.py
+0
-0
ab.py
tests/forms_tests/field_tests/filepathfield_test_dir/ab.py
+0
-0
b.py
tests/forms_tests/field_tests/filepathfield_test_dir/b.py
+0
-0
__init__.py
...ms_tests/field_tests/filepathfield_test_dir/c/__init__.py
+0
-0
d.py
tests/forms_tests/field_tests/filepathfield_test_dir/c/d.py
+0
-0
e.py
tests/forms_tests/field_tests/filepathfield_test_dir/c/e.py
+0
-0
__init__.py
..._tests/field_tests/filepathfield_test_dir/c/f/__init__.py
+0
-0
g.py
...s/forms_tests/field_tests/filepathfield_test_dir/c/f/g.py
+0
-0
test_filepathfield.py
tests/forms_tests/field_tests/test_filepathfield.py
+62
-90
No files found.
tests/forms_tests/field_tests/filepathfield_test_dir/README
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/__init__.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/a.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/ab.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/b.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/c/__init__.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/c/d.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/c/e.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/c/f/__init__.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/filepathfield_test_dir/c/f/g.py
0 → 100644
Dosyayı görüntüle @
71ff9a74
tests/forms_tests/field_tests/test_filepathfield.py
Dosyayı görüntüle @
71ff9a74
import
os.path
from
django.forms
import
FilePathField
,
ValidationError
,
forms
from
django.forms
import
FilePathField
,
ValidationError
from
django.test
import
SimpleTestCase
PATH
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
def
fix_os_paths
(
x
):
if
isinstance
(
x
,
str
):
if
x
.
startswith
(
PATH
):
x
=
x
[
len
(
PATH
):]
return
x
.
replace
(
'
\\
'
,
'/'
)
elif
isinstance
(
x
,
tuple
):
return
tuple
(
fix_os_paths
(
list
(
x
)))
...
...
@@ -16,104 +20,72 @@ def fix_os_paths(x):
class
FilePathFieldTest
(
SimpleTestCase
):
expected_choices
=
[
(
'/filepathfield_test_dir/__init__.py'
,
'__init__.py'
),
(
'/filepathfield_test_dir/a.py'
,
'a.py'
),
(
'/filepathfield_test_dir/ab.py'
,
'ab.py'
),
(
'/filepathfield_test_dir/b.py'
,
'b.py'
),
(
'/filepathfield_test_dir/c/__init__.py'
,
'__init__.py'
),
(
'/filepathfield_test_dir/c/d.py'
,
'd.py'
),
(
'/filepathfield_test_dir/c/e.py'
,
'e.py'
),
(
'/filepathfield_test_dir/c/f/__init__.py'
,
'__init__.py'
),
(
'/filepathfield_test_dir/c/f/g.py'
,
'g.py'
),
]
path
=
os
.
path
.
join
(
PATH
,
'filepathfield_test_dir'
)
+
'/'
def
test_filepathfield_1
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
forms
.
__file__
))
+
'/'
self
.
assertTrue
(
fix_os_paths
(
path
)
.
endswith
(
'/django/forms/'
))
def
assertChoices
(
self
,
field
,
expected_choices
):
self
.
assertEqual
(
fix_os_paths
(
field
.
choices
),
expected_choices
)
def
test_fi
lepathfield_2
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
forms
.
__file__
))
+
'/'
f
=
FilePathField
(
path
=
path
)
f
.
choices
=
[
p
for
p
in
f
.
choices
if
p
[
0
]
.
endswith
(
'.py'
)]
f
.
choices
.
sort
(
)
def
test_fi
x_os_paths
(
self
):
self
.
assertEqual
(
fix_os_paths
(
self
.
path
),
(
'/filepathfield_test_dir/'
))
def
test_no_options
(
self
):
f
=
FilePathField
(
path
=
self
.
path
)
expected
=
[
(
'/django/forms/__init__.py'
,
'__init__.py'
),
(
'/django/forms/boundfield.py'
,
'boundfield.py'
),
(
'/django/forms/fields.py'
,
'fields.py'
),
(
'/django/forms/forms.py'
,
'forms.py'
),
(
'/django/forms/formsets.py'
,
'formsets.py'
),
(
'/django/forms/models.py'
,
'models.py'
),
(
'/django/forms/renderers.py'
,
'renderers.py'
),
(
'/django/forms/utils.py'
,
'utils.py'
),
(
'/django/forms/widgets.py'
,
'widgets.py'
)
]
for
exp
,
got
in
zip
(
expected
,
fix_os_paths
(
f
.
choices
)):
with
self
.
subTest
(
expected
=
exp
):
self
.
assertEqual
(
exp
[
1
],
got
[
1
])
self
.
assertTrue
(
got
[
0
]
.
endswith
(
exp
[
0
]))
msg
=
"'Select a valid choice. fields.py is not one of the available choices.'"
(
'/filepathfield_test_dir/README'
,
'README'
),
]
+
self
.
expected_choices
[:
4
]
self
.
assertChoices
(
f
,
expected
)
def
test_clean
(
self
):
f
=
FilePathField
(
path
=
self
.
path
)
msg
=
"'Select a valid choice. a.py is not one of the available choices.'"
with
self
.
assertRaisesMessage
(
ValidationError
,
msg
):
f
.
clean
(
'
fields
.py'
)
self
.
assert
True
(
fix_os_paths
(
f
.
clean
(
path
+
'fields.py'
))
.
endswith
(
'/django/forms/fields.py'
)
)
f
.
clean
(
'
a
.py'
)
self
.
assert
Equal
(
fix_os_paths
(
f
.
clean
(
self
.
path
+
'a.py'
)),
'/filepathfield_test_dir/a.py'
)
def
test_filepathfield_3
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
forms
.
__file__
))
+
'/'
f
=
FilePathField
(
path
=
path
,
match
=
r'^.*?\.py$'
)
f
.
choices
.
sort
()
expected
=
[
(
'/django/forms/__init__.py'
,
'__init__.py'
),
(
'/django/forms/boundfield.py'
,
'boundfield.py'
),
(
'/django/forms/fields.py'
,
'fields.py'
),
(
'/django/forms/forms.py'
,
'forms.py'
),
(
'/django/forms/formsets.py'
,
'formsets.py'
),
(
'/django/forms/models.py'
,
'models.py'
),
(
'/django/forms/renderers.py'
,
'renderers.py'
),
(
'/django/forms/utils.py'
,
'utils.py'
),
(
'/django/forms/widgets.py'
,
'widgets.py'
)
]
for
exp
,
got
in
zip
(
expected
,
fix_os_paths
(
f
.
choices
)):
with
self
.
subTest
(
expected
=
exp
):
self
.
assertEqual
(
exp
[
1
],
got
[
1
])
self
.
assertTrue
(
got
[
0
]
.
endswith
(
exp
[
0
]))
def
test_match
(
self
):
f
=
FilePathField
(
path
=
self
.
path
,
match
=
r'^.*?\.py$'
)
self
.
assertChoices
(
f
,
self
.
expected_choices
[:
4
])
def
test_filepathfield_4
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
forms
.
__file__
))
+
'/'
f
=
FilePathField
(
path
=
path
,
recursive
=
True
,
match
=
r'^.*?\.py$'
)
def
test_recursive
(
self
):
f
=
FilePathField
(
path
=
self
.
path
,
recursive
=
True
,
match
=
r'^.*?\.py$'
)
f
.
choices
.
sort
()
expected
=
[
(
'/
django/forms
/__init__.py'
,
'__init__.py'
),
(
'/
django/forms/boundfield.py'
,
'boundfield
.py'
),
(
'/
django/forms/fields.py'
,
'fields
.py'
),
(
'/
django/forms/forms.py'
,
'forms
.py'
),
(
'/
django/forms/formsets.py'
,
'formsets
.py'
),
(
'/
django/forms/models.py'
,
'models
.py'
),
(
'/
django/forms/renderers.py'
,
'renderers
.py'
),
(
'/
django/forms/utils.py'
,
'utils
.py'
),
(
'/
django/forms/widgets.py'
,
'widgets.py'
)
(
'/
filepathfield_test_dir
/__init__.py'
,
'__init__.py'
),
(
'/
filepathfield_test_dir/a.py'
,
'a
.py'
),
(
'/
filepathfield_test_dir/ab.py'
,
'ab
.py'
),
(
'/
filepathfield_test_dir/b.py'
,
'b
.py'
),
(
'/
filepathfield_test_dir/c/__init__.py'
,
'c/__init__
.py'
),
(
'/
filepathfield_test_dir/c/d.py'
,
'c/d
.py'
),
(
'/
filepathfield_test_dir/c/e.py'
,
'c/e
.py'
),
(
'/
filepathfield_test_dir/c/f/__init__.py'
,
'c/f/__init__
.py'
),
(
'/
filepathfield_test_dir/c/f/g.py'
,
'c/f/g.py'
),
]
for
exp
,
got
in
zip
(
expected
,
fix_os_paths
(
f
.
choices
)):
with
self
.
subTest
(
expected
=
exp
):
self
.
assertEqual
(
exp
[
1
],
got
[
1
])
self
.
assertTrue
(
got
[
0
]
.
endswith
(
exp
[
0
]))
self
.
assertChoices
(
f
,
expected
)
def
test_filepathfield_folders
(
self
):
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
'..'
,
'..'
))
+
'/tests/filepath_test_files/'
f
=
FilePathField
(
path
=
path
,
allow_folders
=
True
,
allow_files
=
False
)
f
.
choices
.
sort
()
expected
=
[
(
'/forms_tests/tests/filepath_test_files/directory'
,
'directory'
),
]
actual
=
fix_os_paths
(
f
.
choices
)
self
.
assertEqual
(
len
(
expected
),
len
(
actual
))
for
exp
,
got
in
zip
(
expected
,
actual
):
with
self
.
subTest
(
expected
=
exp
):
self
.
assertEqual
(
exp
[
1
],
got
[
1
])
self
.
assertTrue
(
got
[
0
]
.
endswith
(
exp
[
0
]))
def
test_allow_folders
(
self
):
f
=
FilePathField
(
path
=
self
.
path
,
allow_folders
=
True
,
allow_files
=
False
)
self
.
assertChoices
(
f
,
[
(
'/filepathfield_test_dir/c'
,
'c'
)],
)
f
=
FilePathField
(
path
=
path
,
allow_folders
=
True
,
allow_files
=
True
)
f
.
choices
.
sort
()
expected
=
[
(
'/forms_tests/tests/filepath_test_files/.dot-file'
,
'.dot-file'
),
(
'/forms_tests/tests/filepath_test_files/1x1.bmp'
,
'1x1.bmp'
),
(
'/forms_tests/tests/filepath_test_files/1x1.png'
,
'1x1.png'
),
(
'/forms_tests/tests/filepath_test_files/directory'
,
'directory'
),
(
'/forms_tests/tests/filepath_test_files/fake-image.jpg'
,
'fake-image.jpg'
),
(
'/forms_tests/tests/filepath_test_files/real-text-file.txt'
,
'real-text-file.txt'
),
]
def
test_recursive_no_folders_or_files
(
self
):
f
=
FilePathField
(
path
=
self
.
path
,
recursive
=
True
,
allow_folders
=
False
,
allow_files
=
False
)
self
.
assertChoices
(
f
,
[])
actual
=
fix_os_paths
(
f
.
choices
)
self
.
assertEqual
(
len
(
expected
),
len
(
actual
)
)
for
exp
,
got
in
zip
(
expected
,
actual
):
with
self
.
subTest
(
expected
=
exp
):
self
.
assertEqual
(
exp
[
1
],
got
[
1
])
self
.
assertTrue
(
got
[
0
]
.
endswith
(
exp
[
0
])
)
def
test_recursive_folders_without_files
(
self
):
f
=
FilePathField
(
path
=
self
.
path
,
recursive
=
True
,
allow_folders
=
True
,
allow_files
=
False
)
self
.
assertChoices
(
f
,
[
(
'/filepathfield_test_dir/c'
,
'c'
),
(
'/filepathfield_test_dir/c/f'
,
'c/f'
),
]
)
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