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
8394e570
Kaydet (Commit)
8394e570
authored
Nis 17, 2014
tarafından
amatellanes
Kaydeden (comit)
Loic Bistuer
Nis 18, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22465 -- New assertion assertJSONNotEqual
üst
9bc377d7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
0 deletions
+77
-0
testcases.py
django/test/testcases.py
+22
-0
1.8.txt
docs/releases/1.8.txt
+3
-0
tools.txt
docs/topics/testing/tools.txt
+7
-0
tests.py
tests/test_utils/tests.py
+45
-0
No files found.
django/test/testcases.py
Dosyayı görüntüle @
8394e570
...
...
@@ -676,6 +676,11 @@ class SimpleTestCase(unittest.TestCase):
msg_prefix
+
"Couldn't find '
%
s' in response"
%
needle
)
def
assertJSONEqual
(
self
,
raw
,
expected_data
,
msg
=
None
):
"""
Asserts that the JSON fragments raw and expected_data are equal.
Usual JSON non-significant whitespace rules apply as the heavyweight
is delegated to the json library.
"""
try
:
data
=
json
.
loads
(
raw
)
except
ValueError
:
...
...
@@ -687,6 +692,23 @@ class SimpleTestCase(unittest.TestCase):
self
.
fail
(
"Second argument is not valid JSON:
%
r"
%
expected_data
)
self
.
assertEqual
(
data
,
expected_data
,
msg
=
msg
)
def
assertJSONNotEqual
(
self
,
raw
,
expected_data
,
msg
=
None
):
"""
Asserts that the JSON fragments raw and expected_data are not equal.
Usual JSON non-significant whitespace rules apply as the heavyweight
is delegated to the json library.
"""
try
:
data
=
json
.
loads
(
raw
)
except
ValueError
:
self
.
fail
(
"First argument is not valid JSON:
%
r"
%
raw
)
if
isinstance
(
expected_data
,
six
.
string_types
):
try
:
expected_data
=
json
.
loads
(
expected_data
)
except
ValueError
:
self
.
fail
(
"Second argument is not valid JSON:
%
r"
%
expected_data
)
self
.
assertNotEqual
(
data
,
expected_data
,
msg
=
msg
)
def
assertXMLEqual
(
self
,
xml1
,
xml2
,
msg
=
None
):
"""
Asserts that two XML snippets are semantically the same.
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
8394e570
...
...
@@ -155,6 +155,9 @@ Tests
:meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
assert that a template was rendered a specific number of times.
* :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` new assertion allow
you to test that two JSON fragments are not equal.
Validators
^^^^^^^^^^
...
...
docs/topics/testing/tools.txt
Dosyayı görüntüle @
8394e570
...
...
@@ -1458,6 +1458,13 @@ your test suite.
Output in case of error can be customized with the ``msg`` argument.
.. method:: SimpleTestCase.assertJSONNotEqual(raw, expected_data, msg=None)
Asserts that the JSON fragments ``raw`` and ``expected_data`` are *not* equal.
See :meth:`~SimpleTestCase.assertJSONEqual` for further details.
Output in case of error can be customized with the ``msg`` argument.
.. method:: TransactionTestCase.assertQuerysetEqual(qs, values, transform=repr, ordered=True, msg=None)
Asserts that a queryset ``qs`` returns a particular list of values ``values``.
...
...
tests/test_utils/tests.py
Dosyayı görüntüle @
8394e570
...
...
@@ -542,6 +542,51 @@ class HTMLEqualTests(TestCase):
self
.
assertContains
(
response
,
'<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>'
,
html
=
True
)
class
JSONEqualTests
(
TestCase
):
def
test_simple_equal
(
self
):
json1
=
'{"attr1": "foo", "attr2":"baz"}'
json2
=
'{"attr1": "foo", "attr2":"baz"}'
self
.
assertJSONEqual
(
json1
,
json2
)
def
test_simple_equal_unordered
(
self
):
json1
=
'{"attr1": "foo", "attr2":"baz"}'
json2
=
'{"attr2":"baz", "attr1": "foo"}'
self
.
assertJSONEqual
(
json1
,
json2
)
def
test_simple_equal_raise
(
self
):
json1
=
'{"attr1": "foo", "attr2":"baz"}'
json2
=
'{"attr2":"baz"}'
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONEqual
(
json1
,
json2
)
def
test_equal_parsing_errors
(
self
):
invalid_json
=
'{"attr1": "foo, "attr2":"baz"}'
valid_json
=
'{"attr1": "foo", "attr2":"baz"}'
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONEqual
(
invalid_json
,
valid_json
)
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONEqual
(
valid_json
,
invalid_json
)
def
test_simple_not_equal
(
self
):
json1
=
'{"attr1": "foo", "attr2":"baz"}'
json2
=
'{"attr2":"baz"}'
self
.
assertJSONNotEqual
(
json1
,
json2
)
def
test_simple_not_equal_raise
(
self
):
json1
=
'{"attr1": "foo", "attr2":"baz"}'
json2
=
'{"attr1": "foo", "attr2":"baz"}'
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONNotEqual
(
json1
,
json2
)
def
test_not_equal_parsing_errors
(
self
):
invalid_json
=
'{"attr1": "foo, "attr2":"baz"}'
valid_json
=
'{"attr1": "foo", "attr2":"baz"}'
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONNotEqual
(
invalid_json
,
valid_json
)
with
self
.
assertRaises
(
AssertionError
):
self
.
assertJSONNotEqual
(
valid_json
,
invalid_json
)
class
XMLEqualTests
(
TestCase
):
def
test_simple_equal
(
self
):
xml1
=
"<elem attr1='a' attr2='b' />"
...
...
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