Permalink
Browse files

fix 1.8 test for values_list

  • Loading branch information...
igorkramaric committed Dec 30, 2015
1 parent a729014 commit 6e540985328ca8039523f44543a7a31604b46ec3
Showing with 11 additions and 4 deletions.
  1. +2 −1 jsonate/django_ver.py
  2. +9 −3 test_project/test_app/tests.py
View
@@ -1,2 +1,3 @@
import django
-django_19 = (django.VERSION >= (1,9))
+django_19 = (django.VERSION >= (1,9))
+django_18 = (django.VERSION >= (1,8))
@@ -11,9 +11,11 @@
from django.forms import ModelForm
from jsonate import jsonate
+from jsonate.django_ver import django_18
from .models import MyModel, MyModelWithJsonateField, WithJsonateFieldExpectingList
+
def destroy_media_folder(folder):
path = join(settings.MEDIA_ROOT, folder)
[unlink(f) for f in glob(join(path, "*"))]
@@ -101,12 +103,16 @@ def test_jsonate_field_clean_form_with_validation(self):
self.assertJsonateFieldForm(WithJsonateFieldExpectingList, list_to_store)
def test_jsonate_field_in_values_list_gets_deserialized(self):
- # works this way since django 1.8
expected = []
for i in range(0, 5):
- to_create = {"some_name": u"name{}".format(i), "some_json_data":{u"item_{}".format(i): i}}
+
+ to_create = {"some_name": u"name{}".format(i), "some_json_data": {u"item_{}".format(i): i}}
MyModelWithJsonateField.objects.create(**to_create)
- expected.append((to_create["some_name"], to_create["some_json_data"]))
+
+ if django_18:
+ expected.append((to_create["some_name"], to_create["some_json_data"]))
+ else:
+ expected.append((to_create["some_name"], json.dumps(to_create["some_json_data"])))
vl = MyModelWithJsonateField.objects.order_by("id").values_list("some_name", "some_json_data")
for (index, elem) in enumerate(vl):

0 comments on commit 6e54098

Please sign in to comment.