Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Removed superfluos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbate committed Jul 4, 2014
1 parent 10ba5bb commit 812cb6c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 98 deletions.
15 changes: 6 additions & 9 deletions django_cookbook/model/fields.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import json

import pickle
from django.core.exceptions import ValidationError
from django.db.models import TextField, SubfieldBase
from six import with_metaclass


class IterField(with_metaclass(SubfieldBase, TextField)):
"""
Stores the an iterable object in the the database. The data is stored as JSON and so all the values given to the
field must be serializable by the "json" module. This includes dict, list, tuple, str, int, float, True, False and
None
Stores an iterable object in the the database. All the values given to the field must be serializable by the "pickle" package.
"""

def to_python(self, value):
if isinstance(value, list) or isinstance(value, dict) or value is None:
return value

if not isinstance(value, str):
if not isinstance(value, bytes):
raise ValidationError("Invalid input for a IterField instance")

if not value:
return []

# We could store the data as a string representation of the iterable which we then "eval" but this would allow
# for malicious data to be stores in the field so we need to do some sanity checking on the string. We let the
# json library handle this.
return json.loads(value)
# pickle library handle this.
return pickle.loads(value)

def get_prep_value(self, value):
return json.dumps(value, separators=(',', ':'))
return pickle.dumps(value)


37 changes: 0 additions & 37 deletions django_cookbook/test/unit/test_IterField_GetPrepValue.py

This file was deleted.

3 changes: 3 additions & 0 deletions django_cookbook/test/unit/test_IterField_PrepToPython.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_cookbook.test.settings")

from django.test import TestCase
from django_cookbook.model.fields import IterField

Expand Down
52 changes: 0 additions & 52 deletions django_cookbook/test/unit/test_IterField_ToPython.py

This file was deleted.

0 comments on commit 812cb6c

Please sign in to comment.