This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dbate
committed
Jul 7, 2014
1 parent
812cb6c
commit 22e0500
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import pickle | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_cookbook.test.settings") | ||
|
||
from django_cookbook.model.fields import IterField | ||
from django.test import TestCase | ||
|
||
|
||
class IterField_GetPrepValue(TestCase): | ||
def test_ValueIsAnEmptyList_StringIsEmptyList(self): | ||
field = IterField() | ||
value = [] | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsAnEmptyDictionary_StringIsEmptyDict(self): | ||
field = IterField() | ||
value = {} | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsATuple_StringIsEmptyDict(self): | ||
field = IterField() | ||
value = (1, 2, 3) | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsListOfElements_StringIsJsonRepresentationOfThatListWithNoSpaces(self): | ||
field = IterField() | ||
value = [1, 2, 3, 4, 5] | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsListOfListsAndDictionaries_StringIsJsonRepresentationOfThatListWithNoSpaces(self): | ||
field = IterField() | ||
value = [[1, 2, 3], {4: 5}] | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsDictionaryOfElements_StringIsJsonRepresentationOfThatListWithNoSpaces(self): | ||
field = IterField() | ||
value = {1: 2, 3: 4, 5: 6} | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsDictionaryOfListsAndDictionaries_StringIsJsonRepresentationOfThatListWithNoSpaces(self): | ||
field = IterField() | ||
value = {1: {2: 3}, 4: [5, 6]} | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) | ||
|
||
def test_ValueIsTupleOfListsAndDictionaries_StringIsJsonRepresentationOfThatListWithNoSpaces(self): | ||
field = IterField() | ||
value = (0, {1: {2: 3}}, [4, 5, 6]) | ||
|
||
self.assertEqual(pickle.dumps(value), field.get_prep_value(value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import pickle | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_cookbook.test.settings") | ||
|
||
from django.test import TestCase | ||
from django_cookbook.model.fields import IterField | ||
|
||
|
||
class IterField_ToPython(TestCase): | ||
def test_ValueIsNone_ReturnedValueIsNone(self): | ||
field = IterField() | ||
|
||
self.assertIsNone(field.to_python(None)) | ||
|
||
def test_StringIsEmpty_ReturnedValueIsEmptyList(self): | ||
field = IterField() | ||
|
||
self.assertEqual([], field.to_python(b"")) | ||
|
||
def test_ValueIsList_ListIsReturned(self): | ||
field = IterField() | ||
|
||
self.assertEqual([1, 2, {3: 4}], field.to_python([1, 2, {3: 4}])) | ||
|
||
def test_ValueIsDictionary_DictionaryIsReturned(self): | ||
field = IterField() | ||
|
||
self.assertEqual({1: 2, 3: [4, 5, 6]}, field.to_python({1: 2, 3: [4, 5, 6]})) | ||
|
||
def test_ValueIsTuple_TupleIsReturned(self): | ||
field = IterField() | ||
|
||
self.assertEqual((1, 2, 3, 4, 5, 6), field.to_python((1, 2, 3, 4, 5, 6))) | ||
|
||
def test_StringIsEmptyList_ReturnedValueIsEmptyList(self): | ||
field = IterField() | ||
|
||
self.assertEqual([], field.to_python(pickle.dumps([]))) | ||
|
||
def test_StringIsListWithOneField_ReturnedValueIsListWithThatField(self): | ||
field = IterField() | ||
|
||
self.assertEqual(["foo"], field.to_python(pickle.dumps(["foo"]))) | ||
|
||
def test_StringIsListWithMultipleField_ReturnedValueIsListWithThoseFields(self): | ||
field = IterField() | ||
|
||
self.assertEqual(["foo", "bar", "boo"], field.to_python(pickle.dumps(["foo", "bar", "boo"]))) | ||
|
||
def test_StringIsListWithMultipleFieldOneOfWhichIsAList_ReturnedValueIsListWithThoseFields(self): | ||
field = IterField() | ||
|
||
self.assertEqual(["foo", ["bar", "boo"], "moo"], field.to_python(pickle.dumps(["foo", ["bar", "boo"], "moo"]))) | ||
|
||
def test_StringIsDictionary_ReturnedValueIsADictionaryWithTheCorrectFields(self): | ||
field = IterField() | ||
|
||
self.assertEqual({"foo": "bar", "boo": ["moo", "maa"]}, field.to_python(pickle.dumps({"foo": "bar", "boo": ["moo", "maa"]}))) |