<s> from __future__ import absolute_import <EOL> from django . core import serializers <EOL> from django . test import TestCase <EOL> from . fields import Small <EOL> from . models import DataModel , MyModel , OtherModel <EOL> class CustomField ( TestCase ) : <EOL> def test_defer ( self ) : <EOL> d = DataModel . objects . create ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertTrue ( isinstance ( d . data , list ) ) <EOL> d = DataModel . objects . get ( pk = d . pk ) <EOL> self . assertTrue ( isinstance ( d . data , list ) ) <EOL> self . assertEqual ( d . data , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> d = DataModel . objects . defer ( "<STR_LIT:data>" ) . get ( pk = d . pk ) <EOL> d . save ( ) <EOL> d = DataModel . objects . get ( pk = d . pk ) <EOL> self . assertTrue ( isinstance ( d . data , list ) ) <EOL> self . assertEqual ( d . data , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def test_custom_field ( self ) : <EOL> s = Small ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . assertEqual ( str ( s ) , "<STR_LIT>" ) <EOL> m = MyModel . objects . create ( name = "<STR_LIT:m>" , data = s ) <EOL> self . assertEqual ( m . _meta . get_field ( "<STR_LIT:data>" ) . verbose_name , "<STR_LIT>" ) <EOL> self . assertEqual ( ( m . data . first , m . data . second ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> m1 = MyModel . objects . get ( pk = m . pk ) <EOL> self . assertTrue ( isinstance ( m1 . data , Small ) ) <EOL> self . assertEqual ( str ( m1 . data ) , "<STR_LIT>" ) <EOL> s1 = Small ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> s2 = Small ( "<STR_LIT:a>" , "<STR_LIT:b>" ) <EOL> self . assertQuerysetEqual ( <EOL> MyModel . objects . filter ( data__in = [ s , s1 , s2 ] ) , [ <EOL> "<STR_LIT:m>" , <EOL> ] , <EOL> lambda m : m . name , <EOL> ) <EOL> self . assertRaises ( TypeError , lambda : MyModel . objects . filter ( data__lt = s ) ) <EOL> stream = serializers . serialize ( "<STR_LIT>" , MyModel . objects . all ( ) ) <EOL> self . assertEqual ( stream , '<STR_LIT>' % m1 . pk ) <EOL> obj = list ( serializers . deserialize ( "<STR_LIT>" , stream ) ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . object , m ) <EOL> m . delete ( ) <EOL> m1 = MyModel . objects . create ( name = "<STR_LIT:1>" , data = Small ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> m2 = MyModel . objects . create ( name = "<STR_LIT:2>" , data = Small ( <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertQuerysetEqual ( <EOL> MyModel . objects . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> lambda m : str ( m . data ) <EOL> ) <EOL> def test_field_subclassing ( self ) : <EOL> o = OtherModel . objects . create ( data = Small ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) <EOL> o = OtherModel . objects . get ( ) <EOL> self . assertEqual ( o . data . first , "<STR_LIT:a>" ) <EOL> self . assertEqual ( o . data . second , "<STR_LIT:b>" ) </s>
