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
007d4e03
Kaydet (Commit)
007d4e03
authored
Şub 23, 2017
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Şub 23, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Completed test coverage for django.utils.encoding.
üst
098f181e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
test_encoding.py
tests/utils_tests/test_encoding.py
+30
-7
No files found.
tests/utils_tests/test_encoding.py
Dosyayı görüntüle @
007d4e03
import
datetime
import
unittest
from
unittest
import
mock
from
urllib.parse
import
quote_plus
from
django.test
import
SimpleTestCase
from
django.utils.encoding
import
(
DjangoUnicodeDecodeError
,
escape_uri_path
,
filepath_to_uri
,
force_bytes
,
force_text
,
iri_to_uri
,
smart_text
,
uri_to_iri
,
force_text
,
get_system_encoding
,
iri_to_uri
,
smart_bytes
,
smart_text
,
uri_to_iri
,
)
from
django.utils.functional
import
SimpleLazyObject
from
django.utils.translation
import
gettext_lazy
class
TestEncodingUtils
(
SimpleTestCase
):
...
...
@@ -49,27 +52,45 @@ class TestEncodingUtils(SimpleTestCase):
today
=
datetime
.
date
.
today
()
self
.
assertEqual
(
force_bytes
(
today
,
strings_only
=
True
),
today
)
def
test_smart_text
(
self
):
def
test_force_bytes_encoding
(
self
):
error_msg
=
'This is an exception, voilà'
.
encode
()
result
=
force_bytes
(
error_msg
,
encoding
=
'ascii'
,
errors
=
'ignore'
)
self
.
assertEqual
(
result
,
b
'This is an exception, voil'
)
def
test_force_bytes_memory_view
(
self
):
self
.
assertEqual
(
force_bytes
(
memoryview
(
b
'abc'
)),
b
'abc'
)
def
test_smart_bytes
(
self
):
class
Test
:
def
__str__
(
self
):
return
'ŠĐĆŽćžšđ'
class
TestU
:
lazy_func
=
gettext_lazy
(
'x'
)
self
.
assertIs
(
smart_bytes
(
lazy_func
),
lazy_func
)
self
.
assertEqual
(
smart_bytes
(
Test
()),
b
'
\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91
'
)
self
.
assertEqual
(
smart_bytes
(
1
),
b
'1'
)
self
.
assertEqual
(
smart_bytes
(
'foo'
),
b
'foo'
)
def
test_smart_text
(
self
):
class
Test
:
def
__str__
(
self
):
return
'ŠĐĆŽćžšđ'
def
__bytes__
(
self
):
return
b
'Foo'
lazy_func
=
gettext_lazy
(
'x'
)
self
.
assertIs
(
smart_text
(
lazy_func
),
lazy_func
)
self
.
assertEqual
(
smart_text
(
Test
()),
'
\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111
'
)
self
.
assertEqual
(
smart_text
(
TestU
()),
'
\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111
'
)
self
.
assertEqual
(
smart_text
(
1
),
'1'
)
self
.
assertEqual
(
smart_text
(
'foo'
),
'foo'
)
def
test_get_default_encoding
(
self
):
with
mock
.
patch
(
'locale.getdefaultlocale'
,
side_effect
=
Exception
):
self
.
assertEqual
(
get_system_encoding
(),
'ascii'
)
class
TestRFC3987IEncodingUtils
(
unittest
.
TestCase
):
def
test_filepath_to_uri
(
self
):
self
.
assertEqual
(
filepath_to_uri
(
None
),
None
)
self
.
assertEqual
(
filepath_to_uri
(
'upload
\\
чубака.mp4'
),
'upload/
%
D1
%87%
D1
%83%
D0
%
B1
%
D0
%
B0
%
D0
%
BA
%
D0
%
B0.mp4'
)
def
test_iri_to_uri
(
self
):
...
...
@@ -82,6 +103,7 @@ class TestRFC3987IEncodingUtils(unittest.TestCase):
# Reserved chars remain unescaped.
(
'
%
&'
,
'
%
&'
),
(
'red&♥ros
%#
red'
,
'red&
%
E2
%99%
A5ros
%#
red'
),
(
gettext_lazy
(
'red&♥ros
%#
red'
),
'red&
%
E2
%99%
A5ros
%#
red'
),
]
for
iri
,
uri
in
cases
:
...
...
@@ -92,6 +114,7 @@ class TestRFC3987IEncodingUtils(unittest.TestCase):
def
test_uri_to_iri
(
self
):
cases
=
[
(
None
,
None
),
# Valid UTF-8 sequences are decoded.
(
'/
%
e2
%89%
Ab
%
E2
%99%
a5
%
E2
%89%
aB/'
,
'/≫♥≫/'
),
(
'/
%
E2
%99%
A5
%
E2
%99%
A5/?utf8=
%
E2
%9
C
%93
'
,
'/♥♥/?utf8=✓'
),
...
...
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