Skip to content

Commit 97589cf

Browse files
Fix stringified test
1 parent 2d12e18 commit 97589cf

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

testproj/tests.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import unicode_literals
66

7+
import json
78
import unittest
89

910
from django.test import TestCase
@@ -23,7 +24,6 @@
2324

2425

2526
class CountryTranslatedSerializerTestCase(TestCase):
26-
2727
# Disable cache as due to automatic db rollback the instance pk
2828
# is the same for all tests and with the cache we'd mistakenly
2929
# skips saves after the first test.
@@ -99,22 +99,26 @@ def test_translations_validation(self):
9999
six.assertCountEqual(self, serializer.validated_data['translations'], data['translations'])
100100

101101
def test_stringified_translations_validation(self):
102-
data = '''{
103-
'country_code': 'FR',
104-
'translations': {
105-
'en': {
106-
'name': "France",
107-
'url': "http://en.wikipedia.org/wiki/France"
108-
},
109-
'es': {
110-
'name': "Francia",
111-
'url': "http://es.wikipedia.org/wiki/Francia"
112-
},
102+
translations = {
103+
'en': {
104+
'name': "France",
105+
'url': "http://en.wikipedia.org/wiki/France"
106+
},
107+
'es': {
108+
'name': "Francia",
109+
'url': "http://es.wikipedia.org/wiki/Francia"
113110
}
114-
}'''
111+
}
112+
data = {
113+
'country_code': 'FR',
114+
'translations': json.dumps(translations)
115+
}
115116
serializer = CountryTranslatedSerializer(data=data)
116117
self.assertTrue(serializer.is_valid(), serializer.errors)
117-
six.assertCountEqual(self, serializer.validated_data['translations'], json.loads(data)['translations'])
118+
six.assertCountEqual(self, serializer.validated_data['translations'], {
119+
'country_code': 'FR',
120+
'translations': translations
121+
})
118122

119123
def test_translated_fields_validation(self):
120124
data = {
@@ -137,7 +141,7 @@ def test_translated_fields_validation(self):
137141
self.assertIn('url', serializer.errors['translations']['es'])
138142

139143
def test_translations_validation_empty(self):
140-
for empty_value in (None, {}, '', ):
144+
for empty_value in (None, {}, '',):
141145
data = {
142146
'country_code': 'FR',
143147
'translations': empty_value
@@ -261,7 +265,6 @@ def test_nested_translated_serializer(self):
261265

262266

263267
class ParlerRestUtilsTestCase(unittest.TestCase):
264-
265268
def test_automatic_translation_serializer_creation(self):
266269
serializer = create_translated_fields_serializer(Country)()
267270
assert serializer.fields["name"]

0 commit comments

Comments
 (0)