<s> import datetime <EOL> from dateutil . tz import tzoffset <EOL> from decimal import Decimal <EOL> from django . db import models <EOL> from django . contrib . auth . models import User <EOL> from django . test import TestCase <EOL> from django . http import HttpRequest <EOL> from tastypie . bundle import Bundle <EOL> from tastypie . exceptions import ApiFieldError , NotFound <EOL> from tastypie . fields import NOT_PROVIDED , ApiField , BooleanField , CharField , DateField , DateTimeField , DecimalField , DictField , FileField , FloatField , IntegerField , ListField , TimeField , ToOneField , ToManyField <EOL> from tastypie . resources import ALL , ModelResource <EOL> from tastypie . utils import aware_datetime <EOL> from core . models import Note , Subject , MediaBit <EOL> from core . tests . mocks import MockRequest <EOL> class ApiFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( field_1 . instance_name , None ) <EOL> self . assertEqual ( field_1 . attribute , None ) <EOL> self . assertEqual ( field_1 . _default , NOT_PROVIDED ) <EOL> self . assertEqual ( field_1 . null , False ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . use_in , '<STR_LIT:all>' ) <EOL> field_2 = ApiField ( attribute = '<STR_LIT:foo>' , default = True , null = True , readonly = True , help_text = '<STR_LIT>' , use_in = "<STR_LIT:foo>" ) <EOL> self . assertEqual ( field_2 . instance_name , None ) <EOL> self . assertEqual ( field_2 . attribute , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( field_2 . _default , True ) <EOL> self . assertEqual ( field_2 . null , True ) <EOL> self . assertEqual ( field_2 . readonly , True ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . use_in , '<STR_LIT:all>' ) <EOL> field_3 = ApiField ( use_in = "<STR_LIT:list>" ) <EOL> self . assertEqual ( field_3 . use_in , '<STR_LIT:list>' ) <EOL> field_4 = ApiField ( use_in = "<STR_LIT>" ) <EOL> self . assertEqual ( field_4 . use_in , '<STR_LIT>' ) <EOL> def use_in_callable ( x ) : <EOL> return True <EOL> field_5 = ApiField ( use_in = use_in_callable ) <EOL> self . assertTrue ( field_5 . use_in is use_in_callable ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:string>' ) <EOL> def test_has_default ( self ) : <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( field_1 . has_default ( ) , False ) <EOL> field_2 = ApiField ( default = True ) <EOL> self . assertEqual ( field_2 . has_default ( ) , True ) <EOL> def test_default ( self ) : <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( isinstance ( field_1 . default , NOT_PROVIDED ) , True ) <EOL> field_2 = ApiField ( default = True ) <EOL> self . assertEqual ( field_2 . default , True ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , None ) <EOL> field_2 = ApiField ( default = True ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , True ) <EOL> field_3 = ApiField ( attribute = '<STR_LIT:foo>' , default = True ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , True ) <EOL> field_4 = ApiField ( attribute = '<STR_LIT:foo>' , null = True ) <EOL> self . assertEqual ( field_4 . dehydrate ( bundle ) , None ) <EOL> field_5 = ApiField ( attribute = '<STR_LIT:title>' , default = True ) <EOL> self . assertEqual ( field_5 . dehydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_6 = ApiField ( attribute = '<STR_LIT>' , default = True ) <EOL> self . assertEqual ( field_6 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> def test_convert ( self ) : <EOL> field_1 = ApiField ( ) <EOL> self . assertEqual ( field_1 . convert ( '<STR_LIT:foo>' ) , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( field_1 . convert ( True ) , True ) <EOL> def test_hydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ApiField ( ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_1 . hydrate , bundle ) <EOL> field_2 = ApiField ( default = '<STR_LIT:foo>' ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_2 . hydrate ( bundle ) , '<STR_LIT:foo>' ) <EOL> def foo ( ) : <EOL> return '<STR_LIT:bar>' <EOL> field_3 = ApiField ( default = foo ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_3 . hydrate ( bundle ) , '<STR_LIT:bar>' ) <EOL> field_4 = ApiField ( null = True ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_4 . hydrate ( bundle ) , None ) <EOL> field_5 = ApiField ( readonly = True ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( field_5 . hydrate ( bundle ) , None ) <EOL> field_6 = ApiField ( attribute = '<STR_LIT:title>' ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = note . title <EOL> self . assertEqual ( field_6 . hydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_7 = ApiField ( attribute = '<STR_LIT:title>' ) <EOL> field_7 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_7 . hydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_8 = ApiField ( ) <EOL> field_8 . instance_name = '<STR_LIT:title>' <EOL> self . assertEqual ( field_8 . hydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_9 = ApiField ( attribute = '<STR_LIT>' , null = True ) <EOL> field_9 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_9 . hydrate ( bundle ) , None ) <EOL> field_10 = ApiField ( attribute = '<STR_LIT:title>' , null = True ) <EOL> field_10 . instance_name = '<STR_LIT:title>' <EOL> self . assertEqual ( field_10 . hydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_11 = ApiField ( attribute = '<STR_LIT>' , blank = True ) <EOL> field_11 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_11 . hydrate ( bundle ) , None ) <EOL> bundle . data [ '<STR_LIT:title>' ] = note . title <EOL> field_12 = ApiField ( attribute = '<STR_LIT:title>' , blank = True ) <EOL> field_12 . instance_name = '<STR_LIT:title>' <EOL> self . assertEqual ( field_12 . hydrate ( bundle ) , u'<STR_LIT>' ) <EOL> class CharFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = CharField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = CharField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = CharField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:string>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = CharField ( attribute = '<STR_LIT:title>' , default = True ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_2 = CharField ( default = <NUM_LIT:20> ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , u'<STR_LIT>' ) <EOL> class FileFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = FileField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = FileField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = FileField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:string>' ) <EOL> def test_dehydrate ( self ) : <EOL> bit = MediaBit . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = bit ) <EOL> field_1 = FileField ( attribute = '<STR_LIT:image>' , default = True ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , u'<STR_LIT>' ) <EOL> field_2 = FileField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , u'<STR_LIT>' ) <EOL> bit = MediaBit . objects . get ( pk = <NUM_LIT:1> ) <EOL> bit . image = '<STR_LIT>' <EOL> bundle = Bundle ( obj = bit ) <EOL> field_3 = FileField ( attribute = '<STR_LIT:image>' , default = True ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , None ) <EOL> bit . image = None <EOL> bundle = Bundle ( obj = bit ) <EOL> field_4 = FileField ( attribute = '<STR_LIT:image>' , null = True ) <EOL> self . assertEqual ( field_4 . dehydrate ( bundle ) , None ) <EOL> class IntegerFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = IntegerField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = IntegerField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = IntegerField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = IntegerField ( default = <NUM_LIT> ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , <NUM_LIT> ) <EOL> field_2 = IntegerField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , <NUM_LIT:20> ) <EOL> field_3 = IntegerField ( default = <NUM_LIT> ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , <NUM_LIT> ) <EOL> class FloatFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = FloatField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = FloatField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = FloatField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:float>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = FloatField ( default = <NUM_LIT:20> ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , <NUM_LIT> ) <EOL> field_2 = IntegerField ( default = <NUM_LIT> ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , <NUM_LIT> ) <EOL> class DecimalFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = DecimalField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = DecimalField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = DecimalField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = DecimalField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> field_2 = DecimalField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> field_3 = DecimalField ( default = <NUM_LIT> ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> def test_hydrate ( self ) : <EOL> bundle = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> field_1 = DecimalField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . hydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> field_2 = DecimalField ( default = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . hydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> bundle = Bundle ( data = { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> field_3 = DecimalField ( ) <EOL> field_3 . instance_name = '<STR_LIT:foo>' <EOL> self . assertEqual ( field_3 . hydrate ( bundle ) , Decimal ( '<STR_LIT>' ) ) <EOL> bundle = Bundle ( data = { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> field_4 = DecimalField ( attribute = '<STR_LIT:foo>' ) <EOL> field_4 . instance_name = '<STR_LIT:foo>' <EOL> self . assertRaises ( ApiFieldError , field_4 . hydrate , bundle ) <EOL> def test_model_resource_correct_association ( self ) : <EOL> api_field = ModelResource . api_field_from_django_field ( models . DecimalField ( ) ) <EOL> self . assertEqual ( api_field , DecimalField ) <EOL> class ListFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = ListField ( ) <EOL> self . assertEqual ( field_1 . help_text , "<STR_LIT>" ) <EOL> field_2 = ListField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = ListField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:list>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ListField ( default = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> field_2 = ListField ( default = [ '<STR_LIT:abc>' ] ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , [ '<STR_LIT:abc>' ] ) <EOL> class DictFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = DictField ( ) <EOL> self . assertEqual ( field_1 . help_text , "<STR_LIT>" ) <EOL> field_2 = DictField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = DictField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = DictField ( default = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> field_2 = DictField ( default = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> class BooleanFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = BooleanField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = BooleanField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = BooleanField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = BooleanField ( attribute = '<STR_LIT>' , default = False ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , True ) <EOL> field_2 = BooleanField ( default = True ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , True ) <EOL> class TimeFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = TimeField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = TimeField ( help_text = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = TimeField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:time>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = TimeField ( attribute = '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> field_2 = TimeField ( default = datetime . time ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , datetime . time ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> field_3 = TimeField ( attribute = '<STR_LIT>' ) <EOL> note . created_string = '<STR_LIT>' <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , datetime . time ( <NUM_LIT> , <NUM_LIT:6> ) ) <EOL> note . created_string = '<STR_LIT>' <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , datetime . time ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> note . created_string = '<STR_LIT:hello>' <EOL> self . assertRaises ( ApiFieldError , field_3 . dehydrate , bundle ) <EOL> def test_hydrate ( self ) : <EOL> bundle_1 = Bundle ( data = { '<STR_LIT:time>' : '<STR_LIT>' } ) <EOL> field_1 = TimeField ( attribute = '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT:time>' <EOL> self . assertEqual ( field_1 . hydrate ( bundle_1 ) , datetime . time ( <NUM_LIT:3> , <NUM_LIT> ) ) <EOL> bundle_2 = Bundle ( ) <EOL> field_2 = TimeField ( default = datetime . time ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_2 . hydrate ( bundle_2 ) , datetime . time ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> bundle_3 = Bundle ( data = { '<STR_LIT:time>' : '<STR_LIT>' } ) <EOL> field_3 = TimeField ( attribute = '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT:time>' <EOL> self . assertEqual ( field_3 . hydrate ( bundle_3 ) , datetime . time ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:11> ) ) <EOL> bundle_4 = Bundle ( data = { '<STR_LIT:time>' : '<STR_LIT>' } ) <EOL> field_4 = TimeField ( attribute = '<STR_LIT>' ) <EOL> field_4 . instance_name = '<STR_LIT:time>' <EOL> self . assertEqual ( field_4 . hydrate ( bundle_4 ) , datetime . time ( <NUM_LIT:7> , <NUM_LIT> ) ) <EOL> bundle_5 = Bundle ( data = { '<STR_LIT:time>' : None } ) <EOL> field_5 = TimeField ( attribute = '<STR_LIT>' , null = True ) <EOL> field_5 . instance_name = '<STR_LIT:time>' <EOL> self . assertEqual ( field_5 . hydrate ( bundle_5 ) , None ) <EOL> class DateFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = CharField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = CharField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = DateField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT:date>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = DateField ( attribute = '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> field_2 = DateField ( default = datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> note . created_string = '<STR_LIT>' <EOL> field_3 = DateField ( attribute = '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:2> ) ) <EOL> def test_hydrate ( self ) : <EOL> bundle_1 = Bundle ( data = { <EOL> '<STR_LIT:date>' : '<STR_LIT>' , <EOL> } ) <EOL> field_1 = DateField ( attribute = '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT:date>' <EOL> self . assertEqual ( field_1 . hydrate ( bundle_1 ) , datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:12> ) ) <EOL> bundle_2 = Bundle ( ) <EOL> field_2 = DateField ( default = datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> field_2 . instance_name = '<STR_LIT:date>' <EOL> self . assertEqual ( field_2 . hydrate ( bundle_2 ) , datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> bundle_3 = Bundle ( data = { <EOL> '<STR_LIT:date>' : '<STR_LIT>' , <EOL> } ) <EOL> field_3 = DateField ( attribute = '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT:date>' <EOL> self . assertEqual ( field_3 . hydrate ( bundle_3 ) , datetime . date ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:12> ) ) <EOL> bundle_4 = Bundle ( data = { <EOL> '<STR_LIT:date>' : '<STR_LIT>' , <EOL> } ) <EOL> field_4 = DateField ( attribute = '<STR_LIT>' ) <EOL> field_4 . instance_name = '<STR_LIT:date>' <EOL> self . assertEqual ( field_4 . hydrate ( bundle_4 ) , datetime . date ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> bundle_5 = Bundle ( data = { <EOL> '<STR_LIT:date>' : None , <EOL> } ) <EOL> field_5 = DateField ( attribute = '<STR_LIT>' , null = True ) <EOL> field_5 . instance_name = '<STR_LIT:date>' <EOL> self . assertEqual ( field_5 . hydrate ( bundle_5 ) , None ) <EOL> def test_model_resource_correct_association ( self ) : <EOL> api_field = ModelResource . api_field_from_django_field ( models . DateField ( ) ) <EOL> self . assertEqual ( api_field , DateField ) <EOL> class DateTimeFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = CharField ( ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = CharField ( help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = DateTimeField ( ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = DateTimeField ( attribute = '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> field_2 = DateTimeField ( default = aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:7> ) ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:7> ) ) <EOL> note . created_string = '<STR_LIT>' <EOL> field_3 = DateTimeField ( attribute = '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> def test_hydrate ( self ) : <EOL> bundle_1 = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> field_1 = DateTimeField ( attribute = '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_1 . hydrate ( bundle_1 ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:12> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> bundle_2 = Bundle ( ) <EOL> field_2 = DateTimeField ( default = aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_2 . hydrate ( bundle_2 ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> bundle_3 = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> field_3 = DateTimeField ( attribute = '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_3 . hydrate ( bundle_3 ) , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> , tzinfo = tzoffset ( None , - <NUM_LIT> ) ) ) <EOL> bundle_4 = Bundle ( data = { <EOL> '<STR_LIT>' : None , <EOL> } ) <EOL> field_4 = DateField ( attribute = '<STR_LIT>' , null = True ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_4 . hydrate ( bundle_4 ) , None ) <EOL> bundle_5 = Bundle ( data = { '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> field_5 = DateTimeField ( ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_5 . hydrate , bundle_5 ) <EOL> bundle_6 = Bundle ( data = { '<STR_LIT>' : [ '<STR_LIT:a>' , '<STR_LIT:list>' , '<STR_LIT>' , '<STR_LIT:to>' , '<STR_LIT>' ] } ) <EOL> field_6 = DateTimeField ( ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_6 . hydrate , bundle_6 ) <EOL> def test_model_resource_correct_association ( self ) : <EOL> api_field = ModelResource . api_field_from_django_field ( models . DateTimeField ( ) ) <EOL> self . assertEqual ( api_field , DateTimeField ) <EOL> class UserResource ( ModelResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = User . objects . all ( ) <EOL> filtering = { <EOL> '<STR_LIT:id>' : ALL , <EOL> '<STR_LIT:username>' : ALL , <EOL> } <EOL> def get_resource_uri ( self , bundle_or_obj = None , url_name = '<STR_LIT>' ) : <EOL> if bundle_or_obj is None : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' % bundle_or_obj . obj . id <EOL> class ToOneFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_init ( self ) : <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_1 . to , UserResource ) , True ) <EOL> self . assertEqual ( field_1 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . related_name , None ) <EOL> self . assertEqual ( field_1 . null , False ) <EOL> self . assertEqual ( field_1 . full , False ) <EOL> self . assertEqual ( field_1 . readonly , False ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = ToOneField ( UserResource , '<STR_LIT>' , null = True , help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_2 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_2 . to , UserResource ) , True ) <EOL> self . assertEqual ( field_2 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . related_name , None ) <EOL> self . assertEqual ( field_2 . null , True ) <EOL> self . assertEqual ( field_2 . full , False ) <EOL> self . assertEqual ( field_2 . readonly , False ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> field_3 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_3 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_3 . to , UserResource ) , True ) <EOL> self . assertEqual ( field_3 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . related_name , None ) <EOL> self . assertEqual ( field_3 . null , True ) <EOL> self . assertEqual ( field_3 . default , <NUM_LIT:1> ) <EOL> self . assertEqual ( field_3 . full , False ) <EOL> self . assertEqual ( field_3 . readonly , False ) <EOL> self . assertEqual ( field_3 . help_text , '<STR_LIT>' ) <EOL> field_4 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" ) <EOL> self . assertEqual ( field_4 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_4 . to , UserResource ) , True ) <EOL> self . assertEqual ( field_4 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_4 . related_name , None ) <EOL> self . assertEqual ( field_4 . null , True ) <EOL> self . assertEqual ( field_4 . default , <NUM_LIT:1> ) <EOL> self . assertEqual ( field_4 . full , False ) <EOL> self . assertEqual ( field_4 . readonly , True ) <EOL> self . assertEqual ( field_4 . help_text , '<STR_LIT>' ) <EOL> field_5 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT:list>" ) <EOL> self . assertEqual ( field_5 . use_in , '<STR_LIT:list>' ) <EOL> field_6 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT>" ) <EOL> self . assertEqual ( field_6 . use_in , '<STR_LIT>' ) <EOL> def use_in_callable ( x ) : <EOL> return True <EOL> field_7 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = use_in_callable ) <EOL> self . assertTrue ( field_7 . use_in is use_in_callable ) <EOL> field_8 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT:foo>" ) <EOL> self . assertEqual ( field_8 . use_in , '<STR_LIT:all>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_has_default ( self ) : <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . has_default ( ) , False ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> ) <EOL> self . assertEqual ( field_1 . has_default ( ) , True ) <EOL> def test_default ( self ) : <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( field_1 . default , NOT_PROVIDED ) ) <EOL> field_2 = ToOneField ( UserResource , '<STR_LIT>' , default = <NUM_LIT:1> ) <EOL> self . assertEqual ( field_2 . default , <NUM_LIT:1> ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note ( ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertRaises ( ApiFieldError , field_1 . dehydrate , bundle ) <EOL> field_2 = ToOneField ( UserResource , '<STR_LIT>' , null = True ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , None ) <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" <EOL> bundle = Bundle ( obj = note , request = request ) <EOL> field_3 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle ) , '<STR_LIT>' ) <EOL> field_4 = ToOneField ( UserResource , '<STR_LIT>' , full = True ) <EOL> user_bundle = field_4 . dehydrate ( bundle ) <EOL> self . assertEqual ( isinstance ( user_bundle , Bundle ) , True ) <EOL> self . assertEqual ( user_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( user_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> def test_dehydrate_with_callable ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ToOneField ( UserResource , lambda bundle : User . objects . get ( pk = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , '<STR_LIT>' ) <EOL> field_2 = ToManyField ( UserResource , lambda bundle : User . objects . filter ( pk = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( field_2 . dehydrate ( bundle ) , [ '<STR_LIT>' ] ) <EOL> field_3 = ToOneField ( UserResource , lambda bundle : None ) <EOL> self . assertRaises ( ApiFieldError , field_3 . dehydrate , bundle ) <EOL> def test_dehydrate_full_detail_list ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> request = MockRequest ( ) <EOL> bundle = Bundle ( obj = note , request = request ) <EOL> request . path = "<STR_LIT>" <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' , full = True , full_list = False ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , '<STR_LIT>' ) <EOL> request . path = "<STR_LIT>" <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' , full = True , full_detail = False ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle , for_list = False ) , '<STR_LIT>' ) <EOL> def test_hydrate ( self ) : <EOL> note = Note ( ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> self . assertRaises ( ApiFieldError , field_1 . hydrate , bundle ) <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_2 = ToOneField ( UserResource , '<STR_LIT>' , null = True ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = None <EOL> self . assertEqual ( field_2 . hydrate ( bundle ) , None ) <EOL> field_3 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_3 . hydrate , bundle ) <EOL> field_3 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertRaises ( NotFound , field_3 . hydrate , bundle ) <EOL> field_4 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> fk_bundle = field_4 . hydrate ( bundle ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> field_5 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:username>' : u'<STR_LIT>' , <EOL> '<STR_LIT:email>' : u'<STR_LIT>' , <EOL> '<STR_LIT:password>' : u'<STR_LIT>' , <EOL> } <EOL> fk_bundle = field_5 . hydrate ( bundle ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> field_6 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> bundle . data [ '<STR_LIT>' ] = { <EOL> u'<STR_LIT:username>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:email>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:password>' : u'<STR_LIT>' , <EOL> } <EOL> fk_bundle = field_6 . hydrate ( bundle ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> note = Note . objects . create ( <EOL> title = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> content = '<STR_LIT>' <EOL> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_7 = ToOneField ( UserResource , '<STR_LIT>' , null = True ) <EOL> field_7 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_7 . hydrate ( bundle ) , None ) <EOL> field_8 = ToOneField ( UserResource , '<STR_LIT>' , null = True ) <EOL> field_8 . instance_name = '<STR_LIT>' <EOL> fk_bundle = field_8 . hydrate ( bundle ) <EOL> self . assertEqual ( field_8 . hydrate ( bundle ) , None ) <EOL> field_9 = ToOneField ( UserResource , '<STR_LIT>' , null = True ) <EOL> field_9 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_9 . hydrate ( bundle ) , None ) <EOL> field_10 = ToOneField ( UserResource , '<STR_LIT>' , blank = True ) <EOL> field_10 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_10 . hydrate ( bundle ) , None ) <EOL> bundle . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> field_11 = ToOneField ( UserResource , '<STR_LIT>' , blank = True ) <EOL> field_11 . instance_name = '<STR_LIT>' <EOL> fk_bundle = field_11 . hydrate ( bundle ) <EOL> self . assertEqual ( fk_bundle . obj . username , '<STR_LIT>' ) <EOL> field_12 = ToOneField ( UserResource , '<STR_LIT>' , readonly = True ) <EOL> field_12 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_12 . hydrate ( bundle ) , None ) <EOL> field_13 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_13 . instance_name = '<STR_LIT>' <EOL> bundle . related_obj = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle . related_name = '<STR_LIT>' <EOL> fk_bundle = field_13 . hydrate ( bundle ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> def test_resource_from_uri ( self ) : <EOL> ur = UserResource ( ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_uri ( ur , '<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_uri ( ur , '<STR_LIT>' , related_obj = '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . related_obj , None ) <EOL> self . assertEqual ( fk_bundle . related_name , None ) <EOL> def test_resource_from_data ( self ) : <EOL> ur = UserResource ( ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_data ( ur , { <EOL> '<STR_LIT:username>' : u'<STR_LIT>' , <EOL> '<STR_LIT:email>' : u'<STR_LIT>' , <EOL> '<STR_LIT:password>' : u'<STR_LIT>' , <EOL> } ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_data ( ur , { <EOL> '<STR_LIT:username>' : u'<STR_LIT>' , <EOL> '<STR_LIT:email>' : u'<STR_LIT>' , <EOL> '<STR_LIT:password>' : u'<STR_LIT>' , <EOL> } , related_obj = '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . related_obj , '<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . related_name , '<STR_LIT>' ) <EOL> def test_resource_from_pk ( self ) : <EOL> user = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> ur = UserResource ( ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_pk ( ur , user ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:username>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . obj . email , u'<STR_LIT>' ) <EOL> fk_bundle = field_1 . resource_from_pk ( ur , user , related_obj = '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> self . assertEqual ( fk_bundle . related_obj , None ) <EOL> self . assertEqual ( fk_bundle . related_name , None ) <EOL> def test_traversed_attribute_dehydrate ( self ) : <EOL> user = User . objects . get ( pk = <NUM_LIT:1> ) <EOL> note = Note . objects . create ( author = user ) <EOL> mediabit = MediaBit ( note = note ) <EOL> bundle = Bundle ( obj = mediabit ) <EOL> field_1 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , '<STR_LIT>' ) <EOL> field_2 = ToOneField ( UserResource , '<STR_LIT>' ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_2 . hydrate , bundle ) <EOL> class SubjectResource ( ModelResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Subject . objects . all ( ) <EOL> def get_resource_uri ( self , bundle_or_obj = None , url_name = '<STR_LIT>' ) : <EOL> if bundle_or_obj is None : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' % bundle_or_obj . obj . id <EOL> class MediaBitResource ( ModelResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = MediaBit . objects . all ( ) <EOL> def get_resource_uri ( self , bundle_or_obj = None , url_name = '<STR_LIT>' ) : <EOL> if bundle_or_obj is None : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' % bundle_or_obj . obj . id <EOL> class ToManyFieldTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . note_1 = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . note_2 = Note . objects . get ( pk = <NUM_LIT:2> ) <EOL> self . note_3 = Note . objects . get ( pk = <NUM_LIT:3> ) <EOL> self . subject_1 = Subject . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> url = '<STR_LIT>' <EOL> ) <EOL> self . subject_2 = Subject . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> url = '<STR_LIT>' <EOL> ) <EOL> self . subject_3 = Subject . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> url = '<STR_LIT>' <EOL> ) <EOL> self . note_1 . subjects . add ( self . subject_1 ) <EOL> self . note_1 . subjects . add ( self . subject_2 ) <EOL> self . note_2 . subjects . add ( self . subject_1 ) <EOL> self . note_2 . subjects . add ( self . subject_3 ) <EOL> def test_init ( self ) : <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_1 . to , SubjectResource ) , True ) <EOL> self . assertEqual ( field_1 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . related_name , None ) <EOL> self . assertEqual ( field_1 . null , False ) <EOL> self . assertEqual ( field_1 . full , False ) <EOL> self . assertEqual ( field_1 . readonly , False ) <EOL> self . assertEqual ( field_1 . help_text , '<STR_LIT>' ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , null = True , help_text = '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_2 . to , SubjectResource ) , True ) <EOL> self . assertEqual ( field_2 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_2 . related_name , None ) <EOL> self . assertEqual ( field_2 . null , True ) <EOL> self . assertEqual ( field_2 . full , False ) <EOL> self . assertEqual ( field_2 . readonly , False ) <EOL> self . assertEqual ( field_2 . help_text , '<STR_LIT>' ) <EOL> field_3 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , help_text = '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_3 . to , SubjectResource ) , True ) <EOL> self . assertEqual ( field_3 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_3 . related_name , None ) <EOL> self . assertEqual ( field_3 . null , True ) <EOL> self . assertEqual ( field_3 . default , <NUM_LIT:1> ) <EOL> self . assertEqual ( field_3 . full , False ) <EOL> self . assertEqual ( field_3 . readonly , False ) <EOL> self . assertEqual ( field_3 . help_text , '<STR_LIT>' ) <EOL> field_4 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = '<STR_LIT>' ) <EOL> self . assertEqual ( field_4 . instance_name , None ) <EOL> self . assertEqual ( issubclass ( field_4 . to , SubjectResource ) , True ) <EOL> self . assertEqual ( field_4 . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( field_4 . related_name , None ) <EOL> self . assertEqual ( field_4 . null , True ) <EOL> self . assertEqual ( field_4 . default , <NUM_LIT:1> ) <EOL> self . assertEqual ( field_4 . full , False ) <EOL> self . assertEqual ( field_4 . readonly , True ) <EOL> self . assertEqual ( field_4 . help_text , '<STR_LIT>' ) <EOL> field_5 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT:list>" ) <EOL> self . assertEqual ( field_5 . use_in , '<STR_LIT:list>' ) <EOL> field_6 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT>" ) <EOL> self . assertEqual ( field_6 . use_in , '<STR_LIT>' ) <EOL> def use_in_callable ( x ) : <EOL> return True <EOL> field_7 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = use_in_callable ) <EOL> self . assertTrue ( field_7 . use_in is use_in_callable ) <EOL> field_8 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> , null = True , readonly = True , help_text = "<STR_LIT>" , use_in = "<STR_LIT:foo>" ) <EOL> self . assertEqual ( field_8 . use_in , '<STR_LIT:all>' ) <EOL> def test_dehydrated_type ( self ) : <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . dehydrated_type , '<STR_LIT>' ) <EOL> def test_has_default ( self ) : <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> self . assertEqual ( field_1 . has_default ( ) , False ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> ) <EOL> self . assertEqual ( field_2 . has_default ( ) , True ) <EOL> def test_default ( self ) : <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( field_1 . default , NOT_PROVIDED ) ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , default = <NUM_LIT:1> ) <EOL> self . assertEqual ( field_2 . default , <NUM_LIT:1> ) <EOL> def test_dehydrate ( self ) : <EOL> note = Note ( ) <EOL> bundle_1 = Bundle ( obj = note ) <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> with self . assertRaises ( ApiFieldError ) : <EOL> field_1 . dehydrate ( bundle_1 ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , null = True ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_2 . dehydrate ( bundle_1 ) , [ ] ) <EOL> field_3 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> bundle_3 = Bundle ( obj = self . note_1 ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle_3 ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_4 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_4 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_4 . dehydrate ( bundle_4 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_5 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> bundle_5 = Bundle ( obj = self . note_2 ) <EOL> self . assertEqual ( field_5 . dehydrate ( bundle_5 ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_6 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> bundle_6 = Bundle ( obj = self . note_3 ) <EOL> self . assertEqual ( field_6 . dehydrate ( bundle_6 ) , [ ] ) <EOL> field_7 = ToManyField ( SubjectResource , None ) <EOL> field_7 . instance_name = '<STR_LIT>' <EOL> bundle_7 = Bundle ( obj = self . note_3 ) <EOL> with self . assertRaises ( ApiFieldError ) : <EOL> field_7 . dehydrate ( bundle_7 ) <EOL> def test_dehydrate_full_detail_list ( self ) : <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_detail = False ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_1 = Bundle ( obj = self . note_1 , request = request ) <EOL> self . assertEqual ( field_1 . dehydrate ( bundle_1 , for_list = False ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_detail = False ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" <EOL> bundle_2 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_2 . dehydrate ( bundle_2 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_3 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_list = False ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" <EOL> bundle_3 = Bundle ( obj = self . note_1 , request = request ) <EOL> self . assertEqual ( field_3 . dehydrate ( bundle_3 ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_4 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_list = False ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_4 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_4 . dehydrate ( bundle_4 , for_list = False ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_5 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_list = lambda x : True ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" <EOL> bundle_5 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_5 . dehydrate ( bundle_5 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_6 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_list = lambda x : False ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" <EOL> bundle_6 = Bundle ( obj = self . note_1 , request = request ) <EOL> self . assertEqual ( field_6 . dehydrate ( bundle_6 ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_7 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_detail = lambda x : True ) <EOL> field_7 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_7 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_7 . dehydrate ( bundle_7 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_8 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_detail = lambda x : False ) <EOL> field_8 . instance_name = '<STR_LIT>' <EOL> request = MockRequest ( ) <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_8 = Bundle ( obj = self . note_1 , request = request ) <EOL> self . assertEqual ( field_8 . dehydrate ( bundle_8 , for_list = False ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_9 = ToManyField ( SubjectResource , '<STR_LIT>' , full = True , full_detail = True ) <EOL> field_9 . instance_name = '<STR_LIT>' <EOL> request = HttpRequest ( ) <EOL> request . method = "<STR_LIT:GET>" <EOL> request . GET = { "<STR_LIT:foo>" : "<STR_LIT:bar>" } <EOL> request . META [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> request . path = "<STR_LIT>" % { '<STR_LIT>' : self . note_1 . pk } <EOL> bundle_9 = Bundle ( obj = self . note_1 , request = request ) <EOL> subject_bundle_list = field_9 . dehydrate ( bundle_9 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:0> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( isinstance ( subject_bundle_list [ <NUM_LIT:1> ] , Bundle ) , True ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> def test_dehydrate_with_callable ( self ) : <EOL> bundle_1 = Bundle ( obj = self . note_2 ) <EOL> field_1 = ToManyField ( SubjectResource , attribute = lambda bundle : Subject . objects . filter ( notes = bundle . obj , name__startswith = '<STR_LIT>' ) ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_1 . dehydrate ( bundle_1 ) , [ '<STR_LIT>' ] ) <EOL> def test_hydrate ( self ) : <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle = Bundle ( obj = note ) <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_1 . hydrate_m2m , bundle ) <EOL> field_2 = ToManyField ( SubjectResource , '<STR_LIT>' , null = True ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> empty_bundle = Bundle ( ) <EOL> self . assertEqual ( field_2 . hydrate_m2m ( empty_bundle ) , [ ] ) <EOL> field_3 = ToManyField ( SubjectResource , '<STR_LIT>' , null = True ) <EOL> field_3 . instance_name = '<STR_LIT>' <EOL> bundle_3 = Bundle ( data = { '<STR_LIT>' : [ ] } ) <EOL> self . assertEqual ( field_3 . hydrate_m2m ( bundle_3 ) , [ ] ) <EOL> field_4 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> bundle_4 = Bundle ( data = { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> self . assertRaises ( ApiFieldError , field_4 . hydrate_m2m , bundle_4 ) <EOL> field_4 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_4 . instance_name = '<STR_LIT>' <EOL> bundle_4 = Bundle ( data = { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> self . assertRaises ( NotFound , field_4 . hydrate_m2m , bundle_4 ) <EOL> field_5 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_5 . instance_name = '<STR_LIT>' <EOL> bundle_5 = Bundle ( data = { '<STR_LIT>' : [ '<STR_LIT>' ] } ) <EOL> subject_bundle_list = field_5 . hydrate_m2m ( bundle_5 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> field_6 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_6 . instance_name = '<STR_LIT>' <EOL> bundle_6 = Bundle ( data = { '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT:url>' : u'<STR_LIT>' , <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT:url>' : u'<STR_LIT>' , <EOL> } , <EOL> ] } ) <EOL> subject_bundle_list = field_6 . hydrate_m2m ( bundle_6 ) <EOL> self . assertEqual ( len ( subject_bundle_list ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_7 = ToManyField ( SubjectResource , '<STR_LIT>' , blank = True ) <EOL> field_7 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_7 . hydrate ( bundle_6 ) , None ) <EOL> field_8 = ToManyField ( SubjectResource , '<STR_LIT>' , blank = True ) <EOL> field_8 . instance_name = '<STR_LIT>' <EOL> subject_bundle_list_2 = field_8 . hydrate_m2m ( bundle_6 ) <EOL> self . assertEqual ( len ( subject_bundle_list_2 ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:0> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:0> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:0> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:0> ] . obj . url , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:1> ] . data [ '<STR_LIT:name>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:1> ] . data [ '<STR_LIT:url>' ] , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:1> ] . obj . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( subject_bundle_list_2 [ <NUM_LIT:1> ] . obj . url , u'<STR_LIT>' ) <EOL> field_9 = ToManyField ( SubjectResource , '<STR_LIT>' , readonly = True ) <EOL> field_9 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_9 . hydrate ( bundle_6 ) , None ) <EOL> field_10 = ToManyField ( MediaBitResource , '<STR_LIT>' , related_name = '<STR_LIT>' ) <EOL> field_10 . instance_name = '<STR_LIT>' <EOL> note_1 = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> bundle_10 = Bundle ( obj = note_1 , data = { '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } , <EOL> ] } ) <EOL> media_bundle_list = field_10 . hydrate_m2m ( bundle_10 ) <EOL> self . assertEqual ( len ( media_bundle_list ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( media_bundle_list [ <NUM_LIT:0> ] . obj . title , u'<STR_LIT>' ) <EOL> def test_traversed_attribute_dehydrate ( self ) : <EOL> mediabit = MediaBit ( id = <NUM_LIT:1> , note = self . note_1 ) <EOL> bundle = Bundle ( obj = mediabit ) <EOL> field_1 = ToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> field_1 . instance_name = '<STR_LIT>' <EOL> self . assertEqual ( field_1 . dehydrate ( bundle ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> field_2 = ToOneField ( SubjectResource , '<STR_LIT>' ) <EOL> field_2 . instance_name = '<STR_LIT>' <EOL> self . assertRaises ( ApiFieldError , field_2 . hydrate , bundle ) </s>
