<s> import base64 <EOL> import copy <EOL> import datetime <EOL> from decimal import Decimal <EOL> import django <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . core . cache import cache <EOL> from django . core . exceptions import FieldError , MultipleObjectsReturned <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from django import forms <EOL> from django . http import HttpRequest , QueryDict , Http404 <EOL> from django . test import TestCase <EOL> from django . utils import dateformat <EOL> from django . utils import simplejson as json <EOL> from tastypie . authentication import BasicAuthentication <EOL> from tastypie . authorization import Authorization <EOL> from tastypie . bundle import Bundle <EOL> from tastypie . exceptions import InvalidFilterError , InvalidSortError , ImmediateHttpResponse , BadRequest , NotFound <EOL> from tastypie import fields <EOL> from tastypie . paginator import Paginator <EOL> from tastypie . resources import Resource , ModelResource , ALL , ALL_WITH_RELATIONS , convert_post_to_put , convert_post_to_patch <EOL> from tastypie . serializers import Serializer <EOL> from tastypie . throttle import CacheThrottle <EOL> from tastypie . utils import aware_datetime , make_naive , now <EOL> from tastypie . validation import Validation , FormValidation <EOL> from core . models import Note , NoteWithEditor , Subject , MediaBit , AutoNowNote <EOL> from core . tests . mocks import MockRequest <EOL> from core . utils import SimpleHandler <EOL> class CustomSerializer ( Serializer ) : <EOL> pass <EOL> class TestObject ( object ) : <EOL> name = None <EOL> view_count = None <EOL> date_joined = None <EOL> class BasicResource ( Resource ) : <EOL> name = fields . CharField ( attribute = '<STR_LIT:name>' ) <EOL> view_count = fields . IntegerField ( attribute = '<STR_LIT>' , default = <NUM_LIT:0> ) <EOL> date_joined = fields . DateTimeField ( null = True ) <EOL> class Meta : <EOL> object_class = TestObject <EOL> resource_name = '<STR_LIT>' <EOL> def dehydrate_date_joined ( self , bundle ) : <EOL> if getattr ( bundle . obj , '<STR_LIT>' , None ) is not None : <EOL> return bundle . obj . date_joined <EOL> if bundle . data . get ( '<STR_LIT>' ) is not None : <EOL> return bundle . data . get ( '<STR_LIT>' ) <EOL> return aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:0> ) <EOL> def hydrate_date_joined ( self , bundle ) : <EOL> bundle . obj . date_joined = bundle . data [ '<STR_LIT>' ] <EOL> return bundle <EOL> class AnotherBasicResource ( BasicResource ) : <EOL> name = fields . CharField ( attribute = '<STR_LIT:name>' ) <EOL> view_count = fields . IntegerField ( attribute = '<STR_LIT>' , default = <NUM_LIT:0> ) <EOL> date_joined = fields . DateField ( attribute = '<STR_LIT>' ) <EOL> is_active = fields . BooleanField ( attribute = '<STR_LIT>' , default = True ) <EOL> aliases = fields . ListField ( attribute = '<STR_LIT>' , null = True ) <EOL> meta = fields . DictField ( attribute = '<STR_LIT>' , null = True ) <EOL> owed = fields . DecimalField ( attribute = '<STR_LIT>' , null = True ) <EOL> class Meta : <EOL> object_class = TestObject <EOL> resource_name = '<STR_LIT>' <EOL> def dehydrate ( self , bundle ) : <EOL> if hasattr ( bundle . obj , '<STR_LIT:bar>' ) : <EOL> bundle . data [ '<STR_LIT:bar>' ] = bundle . obj . bar <EOL> bundle . data [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> bundle . data [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> bundle . data [ '<STR_LIT>' ] = Decimal ( '<STR_LIT>' ) <EOL> return bundle <EOL> def hydrate ( self , bundle ) : <EOL> if '<STR_LIT:bar>' in bundle . data : <EOL> bundle . obj . bar = '<STR_LIT>' <EOL> return bundle <EOL> class NoUriBasicResource ( BasicResource ) : <EOL> name = fields . CharField ( attribute = '<STR_LIT:name>' ) <EOL> view_count = fields . IntegerField ( attribute = '<STR_LIT>' , default = <NUM_LIT:0> ) <EOL> date_joined = fields . DateTimeField ( null = True ) <EOL> class Meta : <EOL> object_class = TestObject <EOL> include_resource_uri = False <EOL> class NullableNameResource ( Resource ) : <EOL> name = fields . CharField ( attribute = '<STR_LIT:name>' , null = True ) <EOL> class Meta : <EOL> object_class = TestObject <EOL> resource_name = '<STR_LIT>' <EOL> class MangledBasicResource ( BasicResource ) : <EOL> class Meta : <EOL> object_class = TestObject <EOL> resource_name = '<STR_LIT>' <EOL> def alter_list_data_to_serialize ( self , request , data_dict ) : <EOL> if isinstance ( data_dict , dict ) : <EOL> if '<STR_LIT>' in data_dict : <EOL> del ( data_dict [ '<STR_LIT>' ] ) <EOL> data_dict [ '<STR_LIT>' ] = copy . copy ( data_dict [ '<STR_LIT>' ] ) <EOL> del ( data_dict [ '<STR_LIT>' ] ) <EOL> return data_dict <EOL> def alter_deserialized_detail_data ( self , request , bundle_or_list ) : <EOL> if isinstance ( bundle_or_list , Bundle ) : <EOL> bundle_or_list . data [ '<STR_LIT:user>' ] = request . user <EOL> elif isinstance ( bundle_or_list , list ) : <EOL> for obj_data in bundle_or_list : <EOL> obj_data [ '<STR_LIT:user>' ] = request . user <EOL> return bundle_or_list <EOL> class MROBaseFieldResourceA ( Resource ) : <EOL> test = fields . CharField ( default = '<STR_LIT>' ) <EOL> class MROBaseFieldResourceB ( Resource ) : <EOL> test = fields . CharField ( default = '<STR_LIT>' ) <EOL> name = fields . CharField ( default = '<STR_LIT>' ) <EOL> class MROFieldResource ( MROBaseFieldResourceA , MROBaseFieldResourceB ) : <EOL> pass <EOL> class ConvertTestCase ( TestCase ) : <EOL> def test_to_put ( self ) : <EOL> request = HttpRequest ( ) <EOL> request . method = '<STR_LIT>' <EOL> request . _post = '<STR_LIT:foo>' <EOL> request . _files = '<STR_LIT:bar>' <EOL> request . POST = { <EOL> '<STR_LIT:test>' : '<STR_LIT>' <EOL> } <EOL> request . _read_started = False <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> modified = convert_post_to_put ( request ) <EOL> self . assertEqual ( modified . method , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( modified . _post ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( modified . _files ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( modified . POST , { '<STR_LIT:test>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( modified . PUT , { '<STR_LIT:test>' : '<STR_LIT>' } ) <EOL> def test_to_patch ( self ) : <EOL> request = HttpRequest ( ) <EOL> request . method = '<STR_LIT>' <EOL> request . _post = '<STR_LIT:foo>' <EOL> request . _files = '<STR_LIT:bar>' <EOL> request . POST = { <EOL> '<STR_LIT:test>' : '<STR_LIT>' <EOL> } <EOL> request . _read_started = False <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> modified = convert_post_to_patch ( request ) <EOL> self . assertEqual ( modified . method , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( modified . _post ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( modified . _files ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( modified . POST , { '<STR_LIT:test>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( modified . PATCH , { '<STR_LIT:test>' : '<STR_LIT>' } ) <EOL> class ResourceTestCase ( TestCase ) : <EOL> def test_fields ( self ) : <EOL> basic = BasicResource ( ) <EOL> self . assertEqual ( len ( basic . fields ) , <NUM_LIT:4> ) <EOL> self . assert_ ( '<STR_LIT:name>' in basic . fields ) <EOL> self . assertEqual ( isinstance ( basic . fields [ '<STR_LIT:name>' ] , fields . CharField ) , True ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT:name>' ] . _resource , basic . __class__ ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT:name>' ] . instance_name , '<STR_LIT:name>' ) <EOL> self . assert_ ( '<STR_LIT>' in basic . fields ) <EOL> self . assertEqual ( isinstance ( basic . fields [ '<STR_LIT>' ] , fields . IntegerField ) , True ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . _resource , basic . __class__ ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in basic . fields ) <EOL> self . assertEqual ( isinstance ( basic . fields [ '<STR_LIT>' ] , fields . DateTimeField ) , True ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . _resource , basic . __class__ ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in basic . fields ) <EOL> self . assertEqual ( isinstance ( basic . fields [ '<STR_LIT>' ] , fields . CharField ) , True ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . _resource , basic . __class__ ) <EOL> self . assertEqual ( basic . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( basic . _meta . resource_name , '<STR_LIT>' ) <EOL> another = AnotherBasicResource ( ) <EOL> self . assertEqual ( len ( another . fields ) , <NUM_LIT:8> ) <EOL> self . assert_ ( '<STR_LIT:name>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . name , fields . CharField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT:name>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT:name>' ] . instance_name , '<STR_LIT:name>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . view_count , fields . IntegerField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . date_joined , fields . DateField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . is_active , fields . BooleanField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . aliases , fields . ListField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . meta , fields . DictField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . owed , fields . DecimalField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in another . fields ) <EOL> self . assertEqual ( isinstance ( another . resource_uri , fields . CharField ) , True ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . _resource , another . __class__ ) <EOL> self . assertEqual ( another . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( another . _meta . resource_name , '<STR_LIT>' ) <EOL> nouri = NoUriBasicResource ( ) <EOL> self . assertEqual ( len ( nouri . fields ) , <NUM_LIT:3> ) <EOL> self . assert_ ( '<STR_LIT:name>' in nouri . fields ) <EOL> self . assertEqual ( isinstance ( nouri . name , fields . CharField ) , True ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT:name>' ] . _resource , nouri . __class__ ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT:name>' ] . instance_name , '<STR_LIT:name>' ) <EOL> self . assert_ ( '<STR_LIT>' in nouri . fields ) <EOL> self . assertEqual ( isinstance ( nouri . view_count , fields . IntegerField ) , True ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT>' ] . _resource , nouri . __class__ ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assert_ ( '<STR_LIT>' in nouri . fields ) <EOL> self . assertEqual ( isinstance ( nouri . date_joined , fields . DateTimeField ) , True ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT>' ] . _resource , nouri . __class__ ) <EOL> self . assertEqual ( nouri . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( nouri . _meta . resource_name , '<STR_LIT>' ) <EOL> def test_inheritance ( self ) : <EOL> mrofr = MROFieldResource ( ) <EOL> self . assertEqual ( len ( mrofr . fields ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( mrofr . fields [ '<STR_LIT:test>' ] . default , '<STR_LIT>' ) <EOL> self . assertEqual ( mrofr . fields [ '<STR_LIT:name>' ] . default , '<STR_LIT>' ) <EOL> def test_full_dehydrate ( self ) : <EOL> test_object_1 = TestObject ( ) <EOL> test_object_1 . name = '<STR_LIT>' <EOL> test_object_1 . view_count = <NUM_LIT:12> <EOL> test_object_1 . date_joined = aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> test_object_1 . foo = "<STR_LIT>" <EOL> basic = BasicResource ( ) <EOL> test_bundle_1 = basic . build_bundle ( obj = test_object_1 ) <EOL> self . assertEqual ( basic . name . value , None ) <EOL> self . assertEqual ( basic . view_count . value , None ) <EOL> self . assertEqual ( basic . date_joined . value , None ) <EOL> bundle_1 = basic . full_dehydrate ( test_bundle_1 ) <EOL> self . assertEqual ( bundle_1 . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( bundle_1 . data [ '<STR_LIT>' ] , <NUM_LIT:12> ) <EOL> self . assertEqual ( bundle_1 . data [ '<STR_LIT>' ] . year , <NUM_LIT> ) <EOL> self . assertEqual ( bundle_1 . data [ '<STR_LIT>' ] . day , <NUM_LIT:30> ) <EOL> self . assertEqual ( bundle_1 . data . get ( '<STR_LIT:bar>' ) , None ) <EOL> test_object_2 = TestObject ( ) <EOL> test_object_2 . name = '<STR_LIT>' <EOL> basic_2 = BasicResource ( ) <EOL> test_bundle_2 = basic_2 . build_bundle ( obj = test_object_2 ) <EOL> bundle_2 = basic_2 . full_dehydrate ( test_bundle_2 ) <EOL> self . assertEqual ( bundle_2 . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( bundle_2 . data [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( bundle_2 . data [ '<STR_LIT>' ] . year , <NUM_LIT> ) <EOL> self . assertEqual ( bundle_2 . data [ '<STR_LIT>' ] . day , <NUM_LIT> ) <EOL> test_object_3 = TestObject ( ) <EOL> test_object_3 . name = '<STR_LIT>' <EOL> test_object_3 . view_count = <NUM_LIT:5> <EOL> test_object_3 . created = aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> test_object_3 . is_active = False <EOL> test_object_3 . bar = "<STR_LIT>" <EOL> another_1 = AnotherBasicResource ( ) <EOL> test_bundle_3 = another_1 . build_bundle ( obj = test_object_3 ) <EOL> another_bundle_1 = another_1 . full_dehydrate ( test_bundle_3 ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] , <NUM_LIT:5> ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] . year , <NUM_LIT> ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] . day , <NUM_LIT> ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] , False ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT>' ] , Decimal ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( another_bundle_1 . data [ '<STR_LIT:bar>' ] , "<STR_LIT>" ) <EOL> def test_full_hydrate ( self ) : <EOL> basic = BasicResource ( ) <EOL> basic_bundle_1 = Bundle ( data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> } ) <EOL> hydrated = basic . full_hydrate ( basic_bundle_1 ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( hydrated . obj . name , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . obj . view_count , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . obj . date_joined , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> another = AnotherBasicResource ( ) <EOL> another_bundle_1 = Bundle ( data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : [ '<STR_LIT:test>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { '<STR_LIT:foo>' : '<STR_LIT:bar>' } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> hydrated = another . full_hydrate ( another_bundle_1 ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , [ '<STR_LIT:test>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . obj . name , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . obj . view_count , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . obj . date_joined , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( hasattr ( hydrated . obj , '<STR_LIT:bar>' ) , False ) <EOL> another_bundle_2 = Bundle ( data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> '<STR_LIT:bar>' : True , <EOL> } ) <EOL> hydrated = another . full_hydrate ( another_bundle_2 ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( hydrated . obj . name , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . obj . view_count , <NUM_LIT:6> ) <EOL> self . assertEqual ( hydrated . obj . date_joined , aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( hydrated . obj . bar , '<STR_LIT>' ) <EOL> nullable = NullableNameResource ( ) <EOL> obj = nullable . _meta . object_class ( ) <EOL> obj . name = "<STR_LIT>" <EOL> null_bundle = Bundle ( obj = obj , data = { '<STR_LIT:name>' : None } ) <EOL> hydrated = nullable . full_hydrate ( null_bundle ) <EOL> self . assertTrue ( hydrated . obj . name is None ) <EOL> obj = nullable . _meta . object_class ( ) <EOL> obj . name = "<STR_LIT>" <EOL> empty_null_bundle = Bundle ( obj = obj , data = { } ) <EOL> hydrated = nullable . full_hydrate ( empty_null_bundle ) <EOL> self . assertEquals ( hydrated . obj . name , "<STR_LIT>" ) <EOL> def test_obj_get_list ( self ) : <EOL> basic = BasicResource ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_get_list ) <EOL> def test_obj_delete_list ( self ) : <EOL> basic = BasicResource ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_delete_list ) <EOL> def test_obj_get ( self ) : <EOL> basic = BasicResource ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_get , pk = <NUM_LIT:1> ) <EOL> def test_obj_create ( self ) : <EOL> basic = BasicResource ( ) <EOL> bundle = Bundle ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_create , bundle ) <EOL> def test_obj_update ( self ) : <EOL> basic = BasicResource ( ) <EOL> bundle = Bundle ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_update , bundle ) <EOL> def test_obj_delete ( self ) : <EOL> basic = BasicResource ( ) <EOL> self . assertRaises ( NotImplementedError , basic . obj_delete ) <EOL> def test_rollback ( self ) : <EOL> basic = BasicResource ( ) <EOL> bundles_seen = [ ] <EOL> self . assertRaises ( NotImplementedError , basic . rollback , bundles_seen ) <EOL> def adjust_schema ( self , schema_dict ) : <EOL> for field , field_info in schema_dict [ '<STR_LIT>' ] . items ( ) : <EOL> if isinstance ( field_info [ '<STR_LIT:default>' ] , fields . NOT_PROVIDED ) : <EOL> schema_dict [ '<STR_LIT>' ] [ field ] [ '<STR_LIT:default>' ] = '<STR_LIT>' <EOL> return schema_dict <EOL> def test_build_schema ( self ) : <EOL> basic = BasicResource ( ) <EOL> schema = self . adjust_schema ( basic . build_schema ( ) ) <EOL> self . assertEqual ( schema , { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT>' : False <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT>' : False <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT:default>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False <EOL> } <EOL> } <EOL> } ) <EOL> basic = BasicResource ( ) <EOL> basic . _meta . ordering = [ '<STR_LIT>' , '<STR_LIT:name>' ] <EOL> basic . _meta . filtering = { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT:name>' : ALL } <EOL> schema = self . adjust_schema ( basic . build_schema ( ) ) <EOL> self . assertEqual ( schema , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> } ) <EOL> def test_subclassing ( self ) : <EOL> class CommonMeta : <EOL> default_format = '<STR_LIT>' <EOL> class MiniResource ( Resource ) : <EOL> abcd = fields . CharField ( default = '<STR_LIT>' ) <EOL> efgh = fields . IntegerField ( default = <NUM_LIT> ) <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> mini = MiniResource ( ) <EOL> self . assertEqual ( len ( mini . fields ) , <NUM_LIT:3> ) <EOL> class AnotherMiniResource ( MiniResource ) : <EOL> ijkl = fields . BooleanField ( default = True ) <EOL> class Meta ( CommonMeta ) : <EOL> resource_name = '<STR_LIT>' <EOL> another = AnotherMiniResource ( ) <EOL> self . assertEqual ( len ( another . fields ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( another . _meta . default_format , '<STR_LIT>' ) <EOL> def test_method_check ( self ) : <EOL> basic = BasicResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . method = '<STR_LIT:GET>' <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaises ( ImmediateHttpResponse , basic . method_check , request ) <EOL> try : <EOL> basic . method_check ( request ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertRaises ( ImmediateHttpResponse , basic . method_check , request , allowed = [ '<STR_LIT>' ] ) <EOL> try : <EOL> basic . method_check ( request , allowed = [ '<STR_LIT>' ] ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response [ '<STR_LIT>' ] , '<STR_LIT:POST>' ) <EOL> request_method = basic . method_check ( request , allowed = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_method , '<STR_LIT>' ) <EOL> request_method = basic . method_check ( request , allowed = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_method , '<STR_LIT>' ) <EOL> request = HttpRequest ( ) <EOL> request . method = '<STR_LIT:POST>' <EOL> request . POST = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaises ( ImmediateHttpResponse , basic . method_check , request , allowed = [ '<STR_LIT>' ] ) <EOL> try : <EOL> basic . method_check ( request , allowed = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> request_method = basic . method_check ( request , allowed = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( request_method , '<STR_LIT>' ) <EOL> def test_auth_check ( self ) : <EOL> basic = BasicResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> try : <EOL> basic . is_authenticated ( request ) <EOL> except : <EOL> self . fail ( ) <EOL> def test_create_response ( self ) : <EOL> basic = BasicResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> data = { '<STR_LIT:hello>' : '<STR_LIT>' } <EOL> output = basic . create_response ( request , data ) <EOL> self . assertEqual ( output . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( output . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> data = { '<STR_LIT>' : [ { '<STR_LIT:hello>' : '<STR_LIT>' , '<STR_LIT:abc>' : <NUM_LIT> } ] , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> } } <EOL> output = basic . create_response ( request , data ) <EOL> self . assertEqual ( output . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( output . content , '<STR_LIT>' ) <EOL> def test_mangled ( self ) : <EOL> mangled = MangledBasicResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . user = '<STR_LIT>' <EOL> data = Bundle ( data = { '<STR_LIT:hello>' : '<STR_LIT>' } ) <EOL> output = mangled . alter_deserialized_detail_data ( request , data ) <EOL> self . assertEqual ( output . data , { '<STR_LIT:hello>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' } ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> data = { '<STR_LIT>' : [ { '<STR_LIT:hello>' : '<STR_LIT>' , '<STR_LIT:abc>' : <NUM_LIT> } ] , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> } } <EOL> output = mangled . alter_list_data_to_serialize ( request , data ) <EOL> self . assertEqual ( output , { '<STR_LIT>' : [ { '<STR_LIT:abc>' : <NUM_LIT> , '<STR_LIT:hello>' : '<STR_LIT>' } ] } ) <EOL> class NoteResource ( ModelResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> authorization = Authorization ( ) <EOL> filtering = { <EOL> '<STR_LIT:content>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT:title>' : ALL , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> ordering = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> queryset = Note . objects . filter ( is_active = True ) <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 LightlyCustomNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> allowed_methods = [ '<STR_LIT>' ] <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> class TinyLimitNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> limit = <NUM_LIT:3> <EOL> resource_name = '<STR_LIT>' <EOL> allowed_methods = [ '<STR_LIT>' ] <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> class AlwaysDataNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> always_return_data = True <EOL> class VeryCustomNoteResource ( NoteResource ) : <EOL> author = fields . CharField ( attribute = '<STR_LIT>' ) <EOL> constant = fields . IntegerField ( default = <NUM_LIT:20> ) <EOL> class Meta : <EOL> limit = <NUM_LIT:50> <EOL> resource_name = '<STR_LIT>' <EOL> serializer = CustomSerializer ( ) <EOL> list_allowed_methods = [ '<STR_LIT>' ] <EOL> detail_allowed_methods = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> queryset = Note . objects . all ( ) <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class AutoNowNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = AutoNowNote . objects . filter ( is_active = True ) <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 CustomPaginator ( Paginator ) : <EOL> def page ( self ) : <EOL> data = super ( CustomPaginator , self ) . page ( ) <EOL> data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return data <EOL> class CustomPageNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> limit = <NUM_LIT:10> <EOL> resource_name = '<STR_LIT>' <EOL> paginator_class = CustomPaginator <EOL> queryset = Note . objects . all ( ) <EOL> class AlwaysUserNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> authorization = Authorization ( ) <EOL> def get_object_list ( self , request ) : <EOL> return super ( AlwaysUserNoteResource , self ) . get_object_list ( request ) . filter ( author = request . user ) <EOL> class UserResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = User . 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 DetailedNoteResource ( ModelResource ) : <EOL> user = fields . ForeignKey ( UserResource , '<STR_LIT>' ) <EOL> hello_world = fields . CharField ( default = '<STR_LIT>' ) <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> filtering = { <EOL> '<STR_LIT:content>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT:title>' : ALL , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : ALL , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } <EOL> ordering = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:user>' ] <EOL> queryset = Note . objects . filter ( is_active = True ) <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 DetailedNoteResourceWithHydrate ( DetailedNoteResource ) : <EOL> def hydrate ( self , bundle ) : <EOL> bundle . data [ '<STR_LIT:user>' ] = bundle . request . user <EOL> return bundle <EOL> class RequiredFKNoteResource ( ModelResource ) : <EOL> editor = fields . ForeignKey ( UserResource , '<STR_LIT>' ) <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = NoteWithEditor . objects . all ( ) <EOL> class ThrottledNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> throttle = CacheThrottle ( throttle_at = <NUM_LIT:2> , timeframe = <NUM_LIT:5> , expiration = <NUM_LIT:5> ) <EOL> class BasicAuthNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> authentication = BasicAuthentication ( ) <EOL> class NoUriNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> include_resource_uri = False <EOL> class WithAbsoluteURLNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . filter ( is_active = True ) <EOL> include_absolute_url = True <EOL> resource_name = '<STR_LIT>' <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 SubjectResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Subject . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> filtering = { <EOL> '<STR_LIT:name>' : ALL , <EOL> } <EOL> class RelatedNoteResource ( ModelResource ) : <EOL> author = fields . ForeignKey ( UserResource , '<STR_LIT>' ) <EOL> subjects = fields . ManyToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> filtering = { <EOL> '<STR_LIT>' : ALL , <EOL> '<STR_LIT>' : ALL_WITH_RELATIONS , <EOL> } <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class AnotherSubjectResource ( ModelResource ) : <EOL> notes = fields . ToManyField ( DetailedNoteResource , '<STR_LIT>' ) <EOL> class Meta : <EOL> queryset = Subject . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> excludes = [ '<STR_LIT>' ] <EOL> filtering = { <EOL> '<STR_LIT>' : ALL_WITH_RELATIONS , <EOL> } <EOL> class AnotherRelatedNoteResource ( ModelResource ) : <EOL> author = fields . ForeignKey ( UserResource , '<STR_LIT>' ) <EOL> subjects = fields . ManyToManyField ( SubjectResource , '<STR_LIT>' , full = True ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> filtering = { <EOL> '<STR_LIT>' : ALL , <EOL> '<STR_LIT>' : ALL_WITH_RELATIONS , <EOL> } <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class YetAnotherRelatedNoteResource ( ModelResource ) : <EOL> author = fields . ForeignKey ( UserResource , '<STR_LIT>' , full = True ) <EOL> subjects = fields . ManyToManyField ( SubjectResource , '<STR_LIT>' ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> filtering = { <EOL> '<STR_LIT>' : ALL , <EOL> '<STR_LIT>' : ALL_WITH_RELATIONS , <EOL> } <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class NullableRelatedNoteResource ( AnotherRelatedNoteResource ) : <EOL> author = fields . ForeignKey ( UserResource , '<STR_LIT>' , null = True ) <EOL> subjects = fields . ManyToManyField ( SubjectResource , '<STR_LIT>' , null = True ) <EOL> class NullableMediaBitResource ( ModelResource ) : <EOL> note = fields . ToOneField ( NoteResource , '<STR_LIT>' , null = True ) <EOL> class Meta : <EOL> queryset = MediaBit . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> class ReadOnlyRelatedNoteResource ( ModelResource ) : <EOL> author = fields . ToOneField ( UserResource , '<STR_LIT>' , readonly = True ) <EOL> my_property = fields . CharField ( attribute = '<STR_LIT>' , null = True , readonly = True ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> class BlankMediaBitResource ( ModelResource ) : <EOL> note = fields . ToOneField ( NoteResource , '<STR_LIT>' , blank = True ) <EOL> class Meta : <EOL> queryset = MediaBit . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> def hydrate_note ( self , bundle ) : <EOL> if not bundle . data . get ( '<STR_LIT>' ) : <EOL> bundle . obj . note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> return bundle <EOL> class TestOptionsResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> allowed_methods = [ '<STR_LIT>' ] <EOL> list_allowed_methods = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> class PerUserAuthorization ( Authorization ) : <EOL> def apply_limits ( self , request , object_list ) : <EOL> if request and hasattr ( request , '<STR_LIT:user>' ) : <EOL> if request . user . is_authenticated ( ) : <EOL> object_list = object_list . filter ( author = request . user ) <EOL> else : <EOL> object_list = object_list . none ( ) <EOL> return object_list <EOL> class PerUserNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . all ( ) <EOL> authorization = PerUserAuthorization ( ) <EOL> def apply_authorization_limits ( self , request , object_list ) : <EOL> if object_list . _result_cache is not None : <EOL> self . _pre_limits = len ( object_list . _result_cache ) <EOL> else : <EOL> self . _pre_limits = <NUM_LIT:0> <EOL> new_object_list = super ( PerUserNoteResource , self ) . apply_authorization_limits ( request , object_list ) <EOL> if object_list . _result_cache is not None : <EOL> self . _post_limits = len ( object_list . _result_cache ) <EOL> else : <EOL> self . _post_limits = <NUM_LIT:0> <EOL> return new_object_list . filter ( is_active = True ) <EOL> class PerObjectAuthorization ( Authorization ) : <EOL> def apply_limits ( self , request , object_list ) : <EOL> final_list = [ ] <EOL> for obj in object_list : <EOL> if '<STR_LIT>' in obj . title . lower ( ) : <EOL> final_list . append ( obj ) <EOL> return final_list <EOL> class PerObjectNoteResource ( NoteResource ) : <EOL> class Meta : <EOL> resource_name = '<STR_LIT>' <EOL> queryset = Note . objects . all ( ) <EOL> authorization = PerObjectAuthorization ( ) <EOL> filtering = { <EOL> '<STR_LIT>' : ALL , <EOL> } <EOL> def apply_authorization_limits ( self , request , object_list ) : <EOL> if object_list . _result_cache is not None : <EOL> self . _pre_limits = len ( object_list . _result_cache ) <EOL> else : <EOL> self . _pre_limits = <NUM_LIT:0> <EOL> new_object_list = super ( PerObjectNoteResource , self ) . apply_authorization_limits ( request , object_list ) <EOL> self . _post_limits = len ( object_list . _result_cache ) <EOL> return new_object_list <EOL> class ModelResourceTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( ModelResourceTestCase , self ) . setUp ( ) <EOL> self . note_1 = Note . objects . get ( pk = <NUM_LIT:1> ) <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 . note_1 . subjects . add ( self . subject_1 ) <EOL> self . note_1 . subjects . add ( self . subject_2 ) <EOL> def test_init ( self ) : <EOL> resource_1 = NoteResource ( ) <EOL> self . assertEqual ( len ( resource_1 . fields ) , <NUM_LIT:8> ) <EOL> self . assertNotEqual ( resource_1 . _meta . queryset , None ) <EOL> self . assertEqual ( resource_1 . _meta . resource_name , '<STR_LIT>' ) <EOL> self . assertEqual ( resource_1 . _meta . limit , <NUM_LIT:20> ) <EOL> self . assertEqual ( resource_1 . _meta . list_allowed_methods , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource_1 . _meta . detail_allowed_methods , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( isinstance ( resource_1 . _meta . serializer , Serializer ) , True ) <EOL> resource_2 = LightlyCustomNoteResource ( ) <EOL> self . assertEqual ( len ( resource_2 . fields ) , <NUM_LIT:8> ) <EOL> self . assertNotEqual ( resource_2 . _meta . queryset , None ) <EOL> self . assertEqual ( resource_2 . _meta . resource_name , '<STR_LIT>' ) <EOL> self . assertEqual ( resource_2 . _meta . limit , <NUM_LIT:20> ) <EOL> self . assertEqual ( resource_2 . _meta . list_allowed_methods , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource_2 . _meta . detail_allowed_methods , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( isinstance ( resource_2 . _meta . serializer , Serializer ) , True ) <EOL> resource_3 = VeryCustomNoteResource ( ) <EOL> self . assertEqual ( len ( resource_3 . fields ) , <NUM_LIT:7> ) <EOL> self . assertNotEqual ( resource_3 . _meta . queryset , None ) <EOL> self . assertEqual ( resource_3 . _meta . resource_name , '<STR_LIT>' ) <EOL> self . assertEqual ( resource_3 . _meta . limit , <NUM_LIT:50> ) <EOL> self . assertEqual ( resource_3 . _meta . list_allowed_methods , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource_3 . _meta . detail_allowed_methods , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( isinstance ( resource_3 . _meta . serializer , CustomSerializer ) , True ) <EOL> resource_4 = NoUriNoteResource ( ) <EOL> self . assertEqual ( resource_4 . _meta . resource_name , '<STR_LIT>' ) <EOL> resource_5 = TestOptionsResource ( ) <EOL> self . assertEqual ( resource_5 . _meta . allowed_methods , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource_5 . _meta . list_allowed_methods , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource_5 . _meta . detail_allowed_methods , [ '<STR_LIT>' ] ) <EOL> resource_6 = CustomPageNoteResource ( ) <EOL> self . assertEqual ( resource_6 . _meta . paginator_class , CustomPaginator ) <EOL> def test_can_create ( self ) : <EOL> resource_1 = NoteResource ( ) <EOL> self . assertEqual ( resource_1 . can_create ( ) , True ) <EOL> resource_2 = LightlyCustomNoteResource ( ) <EOL> self . assertEqual ( resource_2 . can_create ( ) , False ) <EOL> def test_can_update ( self ) : <EOL> resource_1 = NoteResource ( ) <EOL> self . assertEqual ( resource_1 . can_update ( ) , True ) <EOL> resource_2 = LightlyCustomNoteResource ( ) <EOL> self . assertEqual ( resource_2 . can_update ( ) , False ) <EOL> resource_3 = TestOptionsResource ( ) <EOL> self . assertEqual ( resource_3 . can_update ( ) , True ) <EOL> def test_can_delete ( self ) : <EOL> resource_1 = NoteResource ( ) <EOL> self . assertEqual ( resource_1 . can_delete ( ) , True ) <EOL> resource_2 = LightlyCustomNoteResource ( ) <EOL> self . assertEqual ( resource_2 . can_delete ( ) , False ) <EOL> def test_fields ( self ) : <EOL> resource_1 = RelatedNoteResource ( ) <EOL> self . assertEqual ( len ( resource_1 . fields ) , <NUM_LIT:8> ) <EOL> self . assert_ ( '<STR_LIT>' in resource_1 . fields ) <EOL> self . assertTrue ( isinstance ( resource_1 . fields [ '<STR_LIT>' ] , fields . ToOneField ) ) <EOL> self . assertEqual ( resource_1 . fields [ '<STR_LIT>' ] . _resource , resource_1 . __class__ ) <EOL> self . assertEqual ( resource_1 . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in resource_1 . fields ) <EOL> self . assertTrue ( isinstance ( resource_1 . fields [ '<STR_LIT>' ] , fields . ToManyField ) ) <EOL> self . assertEqual ( resource_1 . fields [ '<STR_LIT>' ] . _resource , resource_1 . __class__ ) <EOL> self . assertEqual ( resource_1 . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> annr = AutoNowNoteResource ( ) <EOL> self . assertEqual ( len ( annr . fields ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( sorted ( annr . fields . keys ( ) ) , [ '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT:content>' ] , fields . CharField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . attribute , '<STR_LIT:content>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . blank , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . _default , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . instance_name , '<STR_LIT:content>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:content>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] , fields . DateTimeField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . blank , False ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] . _default ( ) , datetime . datetime ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . null , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT:id>' ] , fields . IntegerField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . attribute , '<STR_LIT:id>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . blank , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . _default , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . instance_name , '<STR_LIT:id>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . unique , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:id>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] , fields . BooleanField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . blank , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . _default , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] , fields . CharField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . attribute , None ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . blank , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . _default , fields . NOT_PROVIDED ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . readonly , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] , fields . CharField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . blank , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . _default , fields . NOT_PROVIDED ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . unique , True ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT:title>' ] , fields . CharField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . attribute , '<STR_LIT:title>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . blank , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . _default , fields . NOT_PROVIDED ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . instance_name , '<STR_LIT:title>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT:title>' ] . value , None ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] , fields . DateTimeField ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . attribute , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . blank , True ) <EOL> self . assertTrue ( isinstance ( annr . fields [ '<STR_LIT>' ] . _default ( ) , datetime . datetime ) ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . instance_name , '<STR_LIT>' ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . null , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . readonly , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . unique , False ) <EOL> self . assertEqual ( annr . fields [ '<STR_LIT>' ] . value , None ) <EOL> def test_urls ( self ) : <EOL> resource = NoteResource ( api_name = '<STR_LIT>' ) <EOL> patterns = resource . urls <EOL> self . assertEqual ( len ( patterns ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( [ pattern . name for pattern in patterns ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , '<STR_LIT>' ) <EOL> self . assertEqual ( reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } ) , '<STR_LIT>' ) <EOL> resource = NoteResource ( ) <EOL> patterns = resource . urls <EOL> self . assertEqual ( len ( patterns ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( [ pattern . name for pattern in patterns ] , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( reverse ( '<STR_LIT>' , urlconf = '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) , '<STR_LIT>' ) <EOL> self . assertEqual ( reverse ( '<STR_LIT>' , urlconf = '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } ) , '<STR_LIT>' ) <EOL> def test_get_via_uri ( self ) : <EOL> resource = NoteResource ( api_name = '<STR_LIT>' ) <EOL> note_1 = resource . get_via_uri ( '<STR_LIT>' ) <EOL> self . assertEqual ( note_1 . pk , <NUM_LIT:1> ) <EOL> try : <EOL> should_fail = resource . get_via_uri ( '<STR_LIT>' ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except NotFound : <EOL> pass <EOL> try : <EOL> should_also_fail = resource . get_via_uri ( '<STR_LIT>' ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except MultipleObjectsReturned : <EOL> pass <EOL> request = HttpRequest ( ) <EOL> note_1 = resource . get_via_uri ( '<STR_LIT>' , request = request ) <EOL> self . assertEqual ( note_1 . pk , <NUM_LIT:1> ) <EOL> def test_determine_format ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT:application/json>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT:application/json>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT:foo>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT:application/json>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT:application/json>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT:application/json>' ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertEqual ( resource . determine_format ( request ) , '<STR_LIT>' ) <EOL> def adjust_schema ( self , schema_dict ) : <EOL> for field , field_info in schema_dict [ '<STR_LIT>' ] . items ( ) : <EOL> if isinstance ( field_info [ '<STR_LIT:default>' ] , fields . NOT_PROVIDED ) : <EOL> schema_dict [ '<STR_LIT>' ] [ field ] [ '<STR_LIT:default>' ] = '<STR_LIT>' <EOL> if isinstance ( field_info [ '<STR_LIT:default>' ] , ( datetime . datetime , datetime . date ) ) : <EOL> schema_dict [ '<STR_LIT>' ] [ field ] [ '<STR_LIT:default>' ] = '<STR_LIT>' <EOL> return schema_dict <EOL> def test_build_schema ( self ) : <EOL> related = RelatedNoteResource ( ) <EOL> schema = self . adjust_schema ( related . build_schema ( ) ) <EOL> self . assertEqual ( schema , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:content>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:blank>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> } ) <EOL> def test_build_filters ( self ) : <EOL> resource = NoteResource ( ) <EOL> self . assertEqual ( resource . build_filters ( ) , { } ) <EOL> self . assertEqual ( resource . build_filters ( filters = None ) , { } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { } ) <EOL> self . assertRaises ( InvalidFilterError , resource . build_filters , filters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT:foo>' } ) , { '<STR_LIT>' : [ '<STR_LIT:foo>' ] } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] } ) <EOL> self . assertEqual ( resource . build_filters ( filters = QueryDict ( '<STR_LIT>' ) ) , { '<STR_LIT>' : [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] } ) <EOL> self . assertEqual ( resource . build_filters ( filters = QueryDict ( '<STR_LIT>' ) ) , { '<STR_LIT>' : [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:true>' } ) , { '<STR_LIT>' : True } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:True>' } ) , { '<STR_LIT>' : True } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : True } ) , { '<STR_LIT>' : True } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:false>' } ) , { '<STR_LIT>' : False } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:False>' } ) , { '<STR_LIT>' : False } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : False } ) , { '<STR_LIT>' : False } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT>' } ) , { '<STR_LIT>' : None } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:none>' } ) , { '<STR_LIT>' : None } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : '<STR_LIT:None>' } ) , { '<STR_LIT>' : None } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { '<STR_LIT:title>' : None } ) , { '<STR_LIT>' : None } ) <EOL> self . assertEqual ( resource . build_filters ( filters = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resource_2 = DetailedNoteResource ( ) <EOL> filters_1 = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> } <EOL> self . assertEqual ( resource_2 . build_filters ( filters = filters_1 ) , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resource_3 = RelatedNoteResource ( ) <EOL> self . assertRaises ( InvalidFilterError , resource_3 . build_filters , filters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resource_3 . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRaises ( InvalidFilterError , resource_3 . build_filters , filters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRaises ( InvalidFilterError , resource_3 . build_filters , filters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resource_4 = AnotherSubjectResource ( ) <EOL> self . assertEqual ( resource_4 . build_filters ( filters = { '<STR_LIT>' : '<STR_LIT>' } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRaises ( InvalidFilterError , resource_4 . build_filters , filters = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_apply_sorting ( self ) : <EOL> resource = NoteResource ( ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = None ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> self . assertRaises ( InvalidSortError , resource . apply_sorting , object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> object_list = resource . obj_get_list ( ) <EOL> self . assertRaises ( InvalidSortError , resource . apply_sorting , object_list , options = { '<STR_LIT>' : '<STR_LIT:content>' } ) <EOL> object_list = resource . obj_get_list ( ) <EOL> self . assertRaises ( InvalidSortError , resource . apply_sorting , object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT:title>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> object_list = resource . obj_get_list ( ) <EOL> ordered_list = resource . apply_sorting ( object_list , options = { '<STR_LIT>' : [ '<STR_LIT:title>' , '<STR_LIT>' ] } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ] ) <EOL> resource_2 = DetailedNoteResource ( ) <EOL> object_list = resource_2 . obj_get_list ( ) <EOL> ordered_list = resource_2 . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> resource_2 = DetailedNoteResource ( ) <EOL> object_list = resource_2 . obj_get_list ( ) <EOL> ordered_list = resource_2 . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> try : <EOL> [ obj . id for obj in ordered_list ] <EOL> self . fail ( ) <EOL> except FieldError : <EOL> pass <EOL> resource_2 = DetailedNoteResource ( ) <EOL> object_list = resource_2 . obj_get_list ( ) <EOL> ordered_list = resource_2 . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> resource_2 = DetailedNoteResource ( ) <EOL> object_list = resource_2 . obj_get_list ( ) <EOL> ordered_list = resource_2 . apply_sorting ( object_list , options = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:6> , <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> resource_2 = DetailedNoteResource ( ) <EOL> object_list = resource_2 . obj_get_list ( ) <EOL> ordered_list = resource_2 . apply_sorting ( object_list , options = { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:title>' ] } ) <EOL> self . assertEqual ( [ obj . id for obj in ordered_list ] , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ] ) <EOL> def test_get_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:abc>' , '<STR_LIT>' : <NUM_LIT:1> } <EOL> try : <EOL> resp = resource . get_list ( request ) <EOL> self . fail ( ) <EOL> except BadRequest , e : <EOL> pass <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : - <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> } <EOL> try : <EOL> resp = resource . get_list ( request ) <EOL> self . fail ( ) <EOL> except BadRequest , e : <EOL> pass <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : - <NUM_LIT:1> } <EOL> try : <EOL> resp = resource . get_list ( request ) <EOL> self . fail ( ) <EOL> except BadRequest , e : <EOL> pass <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:100> , '<STR_LIT>' : <NUM_LIT:2> } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:title>' } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> new_note = Note . objects . create ( <EOL> title = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> created = aware_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> ) , <EOL> updated = aware_datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> ) , <EOL> ) <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' % make_naive ( new_note . updated ) . isoformat ( ) ) <EOL> resource = TinyLimitNoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . get_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_get_detail ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . get_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . get_detail ( request , pk = <NUM_LIT:2> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . get_detail ( request , pk = <NUM_LIT> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> def test_put_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = MockRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> request . raw_post_data = '<STR_LIT>' <EOL> resp = resource . put_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( Note . objects . filter ( is_active = True ) . count ( ) , <NUM_LIT:1> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , "<STR_LIT>" ) <EOL> always_resource = AlwaysDataNoteResource ( ) <EOL> resp = always_resource . put_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertTrue ( resp . content . startswith ( '<STR_LIT>' ) ) <EOL> def test_put_detail ( self ) : <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> resource = NoteResource ( ) <EOL> request = MockRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . raw_post_data = '<STR_LIT>' <EOL> resp = resource . put_detail ( request , pk = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:7> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , "<STR_LIT>" ) <EOL> request . raw_post_data = '<STR_LIT>' <EOL> resp = resource . put_detail ( request , pk = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:7> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , u'<STR_LIT>' ) <EOL> always_resource = AlwaysDataNoteResource ( ) <EOL> resp = always_resource . put_detail ( request , pk = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> data = json . loads ( resp . content ) <EOL> self . assertTrue ( "<STR_LIT:id>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:id>" ] , <NUM_LIT:10> ) <EOL> self . assertTrue ( "<STR_LIT:content>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:content>" ] , "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> self . assertTrue ( "<STR_LIT:title>" in data ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> new_note . author = User . objects . get ( username = '<STR_LIT>' ) <EOL> new_note . save ( ) <EOL> nullable_resource = NullableRelatedNoteResource ( ) <EOL> request = MockRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . raw_post_data = '<STR_LIT>' <EOL> resp = nullable_resource . put_detail ( request , pk = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:7> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . author , None ) <EOL> def test_post_list ( self ) : <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> resource = NoteResource ( ) <EOL> request = MockRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:POST>' <EOL> request . raw_post_data = '<STR_LIT>' <EOL> resp = resource . post_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:7> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , "<STR_LIT>" ) <EOL> always_resource = AlwaysDataNoteResource ( ) <EOL> resp = always_resource . post_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> data = json . loads ( resp . content ) <EOL> self . assertTrue ( "<STR_LIT:id>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:id>" ] , <NUM_LIT:8> ) <EOL> self . assertTrue ( "<STR_LIT:content>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:content>" ] , "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> self . assertTrue ( "<STR_LIT:title>" in data ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> def test_post_detail ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:POST>' <EOL> resp = resource . post_detail ( request , pk = <NUM_LIT:2> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> def test_delete_list ( self ) : <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> resp = resource . delete_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:2> ) <EOL> def test_delete_detail ( self ) : <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> resp = resource . delete_detail ( request , pk = <NUM_LIT:2> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:5> ) <EOL> def test_patch_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . _read_started = False <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . patch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( Note . objects . filter ( is_active = True ) . count ( ) , <NUM_LIT:4> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , "<STR_LIT>" ) <EOL> updated_note = Note . objects . get ( pk = <NUM_LIT:2> ) <EOL> self . assertEqual ( updated_note . content , "<STR_LIT>" ) <EOL> def test_patch_list_bad_resource_uri ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . _read_started = False <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . patch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:7> ) <EOL> new_note = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( new_note . content , "<STR_LIT>" ) <EOL> def test_patch_list_with_request_data ( self ) : <EOL> """<STR_LIT>""" <EOL> resource = DetailedNoteResourceWithHydrate ( ) <EOL> request = HttpRequest ( ) <EOL> request . user = User . objects . get ( username = '<STR_LIT>' ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . _read_started = False <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . patch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . filter ( author = request . user , slug = "<STR_LIT>" ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_patch_detail ( self ) : <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT>' <EOL> request . _read_started = False <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . patch_detail ( request , pk = <NUM_LIT:10> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp = resource . patch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( note . content , "<STR_LIT>" ) <EOL> self . assertEqual ( note . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . patch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Note . objects . count ( ) , <NUM_LIT:6> ) <EOL> new_note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( new_note . content , u'<STR_LIT>' ) <EOL> always_resource = AlwaysDataNoteResource ( ) <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = always_resource . patch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> data = json . loads ( resp . content ) <EOL> self . assertTrue ( "<STR_LIT:id>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:id>" ] , <NUM_LIT:1> ) <EOL> self . assertTrue ( "<STR_LIT:content>" in data ) <EOL> self . assertEqual ( data [ "<STR_LIT:content>" ] , u'<STR_LIT>' ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> self . assertTrue ( "<STR_LIT:title>" in data ) <EOL> self . assertTrue ( "<STR_LIT>" in data ) <EOL> def test_dispatch_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . dispatch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_dispatch_detail ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . dispatch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_dispatch ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . dispatch ( '<STR_LIT:list>' , request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . dispatch ( '<STR_LIT>' , request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request . META = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> request . _read_started = False <EOL> request . _raw_post_data = request . _body = '<STR_LIT>' <EOL> resp = resource . dispatch ( '<STR_LIT>' , request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . get ( pk = <NUM_LIT:1> ) . title , u'<STR_LIT>' ) <EOL> def test_build_bundle ( self ) : <EOL> resource = NoteResource ( ) <EOL> unpopulated_bundle = resource . build_bundle ( ) <EOL> self . assertTrue ( isinstance ( unpopulated_bundle , Bundle ) ) <EOL> self . assertEqual ( unpopulated_bundle . data , { } ) <EOL> populated_bundle = resource . build_bundle ( data = { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> self . assertTrue ( isinstance ( populated_bundle , Bundle ) ) <EOL> self . assertEqual ( populated_bundle . data , { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> req = HttpRequest ( ) <EOL> req . GET = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> populated_bundle_with_request = resource . build_bundle ( data = { '<STR_LIT:title>' : '<STR_LIT>' } , request = req ) <EOL> self . assertTrue ( isinstance ( populated_bundle_with_request , Bundle ) ) <EOL> self . assertEqual ( populated_bundle_with_request . data , { '<STR_LIT:title>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( populated_bundle_with_request . request . GET [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> def test_obj_get_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> object_list = resource . obj_get_list ( ) <EOL> self . assertEqual ( len ( object_list ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( object_list [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> notes = NoteResource ( ) . obj_get_list ( ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . is_active , True ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( notes [ <NUM_LIT:1> ] . is_active , True ) <EOL> self . assertEqual ( notes [ <NUM_LIT:1> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( notes [ <NUM_LIT:2> ] . is_active , True ) <EOL> self . assertEqual ( notes [ <NUM_LIT:2> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( notes [ <NUM_LIT:3> ] . is_active , True ) <EOL> self . assertEqual ( notes [ <NUM_LIT:3> ] . title , u"<STR_LIT>" ) <EOL> customs = VeryCustomNoteResource ( ) . obj_get_list ( ) <EOL> self . assertEqual ( len ( customs ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( customs [ <NUM_LIT:0> ] . is_active , True ) <EOL> self . assertEqual ( customs [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:0> ] . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:1> ] . is_active , True ) <EOL> self . assertEqual ( customs [ <NUM_LIT:1> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:1> ] . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:2> ] . is_active , False ) <EOL> self . assertEqual ( customs [ <NUM_LIT:2> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:2> ] . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:3> ] . is_active , True ) <EOL> self . assertEqual ( customs [ <NUM_LIT:3> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:3> ] . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:4> ] . is_active , False ) <EOL> self . assertEqual ( customs [ <NUM_LIT:4> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:4> ] . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( customs [ <NUM_LIT:5> ] . is_active , True ) <EOL> self . assertEqual ( customs [ <NUM_LIT:5> ] . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( customs [ <NUM_LIT:5> ] . author . username , u'<STR_LIT>' ) <EOL> mock_request = MockRequest ( ) <EOL> mock_request . GET [ '<STR_LIT:title>' ] = u"<STR_LIT>" <EOL> notes = NoteResource ( ) . obj_get_list ( request = mock_request ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . title , u"<STR_LIT>" ) <EOL> mock_request = MockRequest ( ) <EOL> mock_request . GET [ '<STR_LIT:title>' ] = u"<STR_LIT>" <EOL> notes = NoteResource ( ) . obj_get_list ( request = mock_request , title = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> def test_apply_filters ( self ) : <EOL> nr = NoteResource ( ) <EOL> mock_request = MockRequest ( ) <EOL> notes = nr . apply_filters ( mock_request , { } ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:4> ) <EOL> filters = { <EOL> '<STR_LIT:title>' : u"<STR_LIT>" <EOL> } <EOL> notes = nr . apply_filters ( mock_request , filters ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . title , u"<STR_LIT>" ) <EOL> filters = { <EOL> '<STR_LIT>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:30> ) , <EOL> } <EOL> notes = nr . apply_filters ( mock_request , filters ) <EOL> self . assertEqual ( len ( notes ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( notes [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( notes [ <NUM_LIT:1> ] . title , u'<STR_LIT>' ) <EOL> def test_obj_get ( self ) : <EOL> resource = NoteResource ( ) <EOL> obj = resource . obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertTrue ( isinstance ( obj , Note ) ) <EOL> self . assertEqual ( obj . title , u'<STR_LIT>' ) <EOL> obj = resource . obj_get ( slug = '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( obj , Note ) ) <EOL> self . assertEqual ( obj . title , u'<STR_LIT>' ) <EOL> note = NoteResource ( ) <EOL> note_obj = note . obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( note_obj . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( note_obj . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( note_obj . is_active , True ) <EOL> self . assertEqual ( note_obj . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( note_obj . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( note_obj . updated , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> custom = VeryCustomNoteResource ( ) <EOL> custom_obj = custom . obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( custom_obj . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( custom_obj . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( custom_obj . is_active , True ) <EOL> self . assertEqual ( custom_obj . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( custom_obj . title , u'<STR_LIT>' ) <EOL> related = RelatedNoteResource ( ) <EOL> related_obj = related . obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( related_obj . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( related_obj . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( related_obj . is_active , True ) <EOL> self . assertEqual ( related_obj . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( related_obj . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( list ( related_obj . subjects . values_list ( '<STR_LIT:id>' , flat = True ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_uri_fields ( self ) : <EOL> with_abs_url = WithAbsoluteURLNoteResource ( ) <EOL> with_abs_url_obj = with_abs_url . obj_get ( pk = <NUM_LIT:1> ) <EOL> with_abs_url_bundle = with_abs_url . build_bundle ( obj = with_abs_url_obj ) <EOL> abs_bundle = with_abs_url . full_dehydrate ( with_abs_url_bundle ) <EOL> self . assertEqual ( abs_bundle . data [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( abs_bundle . data [ '<STR_LIT>' ] , u'<STR_LIT>' ) <EOL> def test_jsonp_validation ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> try : <EOL> resp = resource . dispatch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . fail ( ) <EOL> except BadRequest , e : <EOL> pass <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . dispatch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_get_schema ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> old_created = resource . fields [ '<STR_LIT>' ] . _default <EOL> old_updated = resource . fields [ '<STR_LIT>' ] . _default <EOL> resource . fields [ '<STR_LIT>' ] . _default = aware_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> resource . fields [ '<STR_LIT>' ] . _default = aware_datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> resp = resource . get_schema ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> schema = { <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT:application/json>" , <EOL> "<STR_LIT>" : <NUM_LIT:20> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:content>" : { <EOL> "<STR_LIT:blank>" : True , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:blank>" : False , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT:id>" : { <EOL> "<STR_LIT:blank>" : True , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:blank>" : True , <EOL> "<STR_LIT:default>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:blank>" : False , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:blank>" : False , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT:title>" : { <EOL> "<STR_LIT:blank>" : False , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" , <EOL> "<STR_LIT>" : False <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:blank>" : False , <EOL> "<STR_LIT:default>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False <EOL> } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:content>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT:title>" : <NUM_LIT:1> <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT:title>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> } <EOL> self . assertEqual ( json . loads ( resp . content ) , schema ) <EOL> resource . fields [ '<STR_LIT>' ] . _default = old_created <EOL> resource . fields [ '<STR_LIT>' ] . _default = old_updated <EOL> def test_get_multiple ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . get_multiple ( request , pk_list = '<STR_LIT:1>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . get_multiple ( request , pk_list = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . get_multiple ( request , pk_list = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> resp = resource . get_multiple ( request , pk_list = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> def test_check_throttling ( self ) : <EOL> old_debug = settings . DEBUG <EOL> settings . DEBUG = False <EOL> resource = ThrottledNoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> resp = resource . dispatch ( '<STR_LIT:list>' , request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( cache . get ( '<STR_LIT>' ) ) , <NUM_LIT:1> ) <EOL> resp = resource . dispatch ( '<STR_LIT:list>' , request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( len ( cache . get ( '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> try : <EOL> resp = resource . dispatch ( '<STR_LIT:list>' , request ) <EOL> self . fail ( ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cache . get ( '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> try : <EOL> resp = resource . dispatch ( '<STR_LIT:list>' , request ) <EOL> self . fail ( ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cache . get ( '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( len ( cache . get ( '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> settings . DEBUG = old_debug <EOL> def test_generate_cache_key ( self ) : <EOL> resource = NoteResource ( ) <EOL> self . assertEqual ( resource . generate_cache_key ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( resource . generate_cache_key ( '<STR_LIT:abc>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( resource . generate_cache_key ( foo = '<STR_LIT:bar>' , moof = '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( resource . generate_cache_key ( '<STR_LIT:abc>' , '<STR_LIT>' , foo = '<STR_LIT:bar>' , moof = '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_cached_fetch_list ( self ) : <EOL> resource = NoteResource ( ) <EOL> object_list = resource . cached_obj_get_list ( ) <EOL> self . assertEqual ( len ( object_list ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( object_list [ <NUM_LIT:0> ] . title , u'<STR_LIT>' ) <EOL> def test_cached_fetch_detail ( self ) : <EOL> resource = NoteResource ( ) <EOL> obj = resource . cached_obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertTrue ( isinstance ( obj , Note ) ) <EOL> self . assertEqual ( obj . title , u'<STR_LIT>' ) <EOL> def test_configuration ( self ) : <EOL> note = NoteResource ( ) <EOL> self . assertEqual ( len ( note . fields ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( sorted ( note . fields . keys ( ) ) , [ '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( note . fields [ '<STR_LIT:content>' ] . default , '<STR_LIT>' ) <EOL> custom = VeryCustomNoteResource ( ) <EOL> self . assertEqual ( len ( custom . fields ) , <NUM_LIT:7> ) <EOL> self . assertEqual ( sorted ( custom . fields . keys ( ) ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' ] ) <EOL> no_uri = NoUriNoteResource ( ) <EOL> self . assertEqual ( len ( no_uri . fields ) , <NUM_LIT:7> ) <EOL> self . assertEqual ( sorted ( no_uri . fields . keys ( ) ) , [ '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' ] ) <EOL> with_abs_url = WithAbsoluteURLNoteResource ( ) <EOL> self . assertEqual ( len ( with_abs_url . fields ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( sorted ( with_abs_url . fields . keys ( ) ) , [ '<STR_LIT>' , '<STR_LIT:content>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' , '<STR_LIT>' ] ) <EOL> def test_obj_delete_list_custom_qs ( self ) : <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:6> ) <EOL> notes = NoteResource ( ) . obj_delete_list ( ) <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:2> ) <EOL> def test_obj_delete_list_basic_qs ( self ) : <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:6> ) <EOL> customs = VeryCustomNoteResource ( ) . obj_delete_list ( ) <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:0> ) <EOL> def test_obj_delete_list_non_queryset ( self ) : <EOL> class NonQuerysetNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> def apply_authorization_limits ( self , request , obj_list ) : <EOL> return tuple ( obj_list [ : <NUM_LIT:2> ] ) <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:6> ) <EOL> notes = NonQuerysetNoteResource ( ) . obj_delete_list ( ) <EOL> self . assertEqual ( len ( Note . objects . all ( ) ) , <NUM_LIT:4> ) <EOL> def test_obj_create ( self ) : <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = NoteResource ( ) <EOL> bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ) <EOL> note . obj_create ( bundle ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:7> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:7> ) <EOL> note = RelatedNoteResource ( ) <EOL> related_bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } ) <EOL> note . obj_create ( related_bundle ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:8> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( latest . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . subjects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( [ sub . id for sub in latest . subjects . all ( ) ] , [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:8> ) <EOL> note = AnotherRelatedNoteResource ( ) <EOL> related_bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ] , <EOL> } ) <EOL> note . obj_create ( related_bundle ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:9> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( latest . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . subjects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( [ sub . id for sub in latest . subjects . all ( ) ] , [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( User . objects . filter ( username = '<STR_LIT>' ) . count ( ) , <NUM_LIT:0> ) <EOL> note = YetAnotherRelatedNoteResource ( ) <EOL> related_bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : [ ] , <EOL> } ) <EOL> note . obj_create ( related_bundle ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:10> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( latest . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . subjects . all ( ) . count ( ) , <NUM_LIT:0> ) <EOL> note = RequiredFKNoteResource ( ) <EOL> related_bundle = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } , <EOL> } ) <EOL> note . obj_create ( related_bundle ) <EOL> latest = NoteWithEditor . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . editor . username , u'<STR_LIT>' ) <EOL> def test_obj_update ( self ) : <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = NoteResource ( ) <EOL> note_obj = note . obj_get ( pk = <NUM_LIT:1> ) <EOL> note_bundle = note . build_bundle ( obj = note_obj ) <EOL> note_bundle = note . full_dehydrate ( note_bundle ) <EOL> note_bundle . data [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> note . obj_update ( note_bundle , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> numero_uno = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( numero_uno . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . is_active , True ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = RelatedNoteResource ( ) <EOL> related_obj = note . obj_get ( pk = <NUM_LIT:1> ) <EOL> related_bundle = Bundle ( obj = related_obj , data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> } ) <EOL> note . obj_update ( related_bundle , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( latest . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . subjects . all ( ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( [ sub . id for sub in latest . subjects . all ( ) ] , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = AnotherRelatedNoteResource ( ) <EOL> related_obj = note . obj_get ( pk = <NUM_LIT:1> ) <EOL> related_bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ] , <EOL> } ) <EOL> note . obj_update ( related_bundle , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> latest = Note . objects . get ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( latest . title , u"<STR_LIT>" ) <EOL> self . assertEqual ( latest . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . is_active , True ) <EOL> self . assertEqual ( latest . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( latest . subjects . all ( ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( [ sub . id for sub in latest . subjects . all ( ) ] , [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = NoteResource ( ) <EOL> note_obj = note . obj_get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( note_obj . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( note_obj . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:30> , <NUM_LIT:20> , <NUM_LIT:5> ) ) <EOL> note_bundle = note . build_bundle ( obj = note_obj ) <EOL> note_bundle = note . full_dehydrate ( note_bundle ) <EOL> note_bundle . data [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> note_bundle . data [ '<STR_LIT>' ] = aware_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> note . obj_update ( note_bundle , pk = <NUM_LIT:1> , created = '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> numero_uno = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( numero_uno . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . created , aware_datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> note = NoteResource ( ) <EOL> note_bundle = note . build_bundle ( data = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:content>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) <EOL> self . assertRaises ( NotFound , note . obj_update , note_bundle , pk = <NUM_LIT:1> , created = '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> request = HttpRequest ( ) <EOL> request . user = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . assertEqual ( AlwaysUserNoteResource ( ) . get_object_list ( request ) . count ( ) , <NUM_LIT:2> ) <EOL> note = AlwaysUserNoteResource ( ) <EOL> note_obj = note . obj_get ( request , pk = <NUM_LIT:1> ) <EOL> note_bundle = note . build_bundle ( obj = note_obj ) <EOL> note_bundle = note . full_dehydrate ( note_bundle ) <EOL> note_bundle . data [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> note_bundle . request = request <EOL> note . obj_update ( note_bundle , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> numero_uno = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( numero_uno . title , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . slug , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . content , u'<STR_LIT>' ) <EOL> self . assertEqual ( numero_uno . is_active , True ) <EOL> self . assertEqual ( numero_uno . author . pk , request . user . pk ) <EOL> def test_obj_delete ( self ) : <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = NoteResource ( ) <EOL> note . obj_delete ( pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:5> ) <EOL> self . assertRaises ( Note . DoesNotExist , Note . objects . get , pk = <NUM_LIT:1> ) <EOL> note . obj_delete ( slug = '<STR_LIT>' ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:4> ) <EOL> self . assertRaises ( Note . DoesNotExist , Note . objects . get , slug = '<STR_LIT>' ) <EOL> def test_rollback ( self ) : <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> note = NoteResource ( ) <EOL> bundles_seen = [ ] <EOL> note . rollback ( bundles_seen ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:6> ) <EOL> bundles_seen = [ Bundle ( obj = Note . objects . get ( pk = <NUM_LIT:1> ) ) , Bundle ( obj = Note ( ) ) , Bundle ( ) ] <EOL> note . rollback ( bundles_seen ) <EOL> self . assertEqual ( Note . objects . all ( ) . count ( ) , <NUM_LIT:5> ) <EOL> def test_is_valid ( self ) : <EOL> note = NoteResource ( ) <EOL> bundle = Bundle ( data = { } ) <EOL> try : <EOL> note . is_valid ( bundle ) <EOL> except : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class NoteForm ( forms . Form ) : <EOL> title = forms . CharField ( max_length = <NUM_LIT:100> ) <EOL> slug = forms . CharField ( max_length = <NUM_LIT:50> ) <EOL> content = forms . CharField ( required = False , widget = forms . Textarea ) <EOL> is_active = forms . BooleanField ( ) <EOL> def clean ( self ) : <EOL> if not self . cleaned_data . get ( '<STR_LIT:content>' , '<STR_LIT>' ) : <EOL> raise forms . ValidationError ( '<STR_LIT>' ) <EOL> return self . cleaned_data <EOL> class ValidatedNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> validation = FormValidation ( form_class = NoteForm ) <EOL> class ValidatedXMLNoteResource ( ModelResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> validation = FormValidation ( form_class = NoteForm ) <EOL> default_format = '<STR_LIT>' <EOL> validated = ValidatedNoteResource ( ) <EOL> validated_xml = ValidatedXMLNoteResource ( ) <EOL> bundle = Bundle ( data = { } ) <EOL> self . assertFalse ( validated . is_valid ( bundle ) ) <EOL> self . assertEqual ( bundle . errors , { '<STR_LIT>' : { '<STR_LIT>' : [ u'<STR_LIT>' ] , '<STR_LIT>' : [ u'<STR_LIT>' ] , '<STR_LIT>' : [ u'<STR_LIT>' ] , '<STR_LIT:title>' : [ u'<STR_LIT>' ] } } ) <EOL> bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> self . assertFalse ( validated . is_valid ( bundle ) ) <EOL> self . assertEqual ( bundle . errors , { '<STR_LIT>' : { '<STR_LIT>' : [ u'<STR_LIT>' ] , '<STR_LIT>' : [ u'<STR_LIT>' ] } } ) <EOL> bundle = Bundle ( data = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> self . assertTrue ( validated . is_valid ( bundle ) ) <EOL> def test_self_referential ( self ) : <EOL> class SelfResource ( ModelResource ) : <EOL> me_baby_me = fields . ToOneField ( '<STR_LIT>' , '<STR_LIT>' , null = True ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> me_baby_me = SelfResource ( ) <EOL> self . assertEqual ( len ( me_baby_me . fields ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( me_baby_me . _meta . resource_name , '<STR_LIT>' ) <EOL> self . assertEqual ( me_baby_me . fields [ '<STR_LIT>' ] . to , '<STR_LIT>' ) <EOL> self . assertEqual ( me_baby_me . fields [ '<STR_LIT>' ] . to_class , SelfResource ) <EOL> class AnotherSelfResource ( SelfResource ) : <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> another_me_baby_me = AnotherSelfResource ( ) <EOL> self . assertEqual ( len ( another_me_baby_me . fields ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( another_me_baby_me . _meta . resource_name , '<STR_LIT>' ) <EOL> self . assertEqual ( another_me_baby_me . fields [ '<STR_LIT>' ] . to , '<STR_LIT>' ) <EOL> self . assertEqual ( another_me_baby_me . fields [ '<STR_LIT>' ] . to_class , AnotherSelfResource ) <EOL> def test_subclassing ( self ) : <EOL> class MiniResource ( ModelResource ) : <EOL> abcd = fields . CharField ( default = '<STR_LIT>' ) <EOL> efgh = fields . IntegerField ( default = <NUM_LIT> ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> mini = MiniResource ( ) <EOL> self . assertEqual ( len ( mini . fields ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( mini . _meta . queryset . all ( ) ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( mini . _meta . resource_name , '<STR_LIT>' ) <EOL> class AnotherMiniResource ( MiniResource ) : <EOL> ijkl = fields . BooleanField ( default = True ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> another = AnotherMiniResource ( ) <EOL> self . assertEqual ( len ( another . fields ) , <NUM_LIT:11> ) <EOL> self . assertEqual ( len ( another . _meta . queryset . all ( ) ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( another . _meta . resource_name , '<STR_LIT>' ) <EOL> class YetAnotherMiniResource ( MiniResource ) : <EOL> mnop = fields . FloatField ( default = True ) <EOL> class Meta : <EOL> queryset = Note . objects . all ( ) <EOL> resource_name = '<STR_LIT>' <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> include_absolute_url = True <EOL> yetanother = YetAnotherMiniResource ( ) <EOL> self . assertEqual ( len ( yetanother . fields ) , <NUM_LIT:5> ) <EOL> self . assertEqual ( sorted ( yetanother . fields . keys ( ) ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:title>' ] ) <EOL> self . assertEqual ( len ( yetanother . _meta . queryset . all ( ) ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( yetanother . _meta . resource_name , '<STR_LIT>' ) <EOL> def test_nullable_toone_full_hydrate ( self ) : <EOL> nrrnr = NullableRelatedNoteResource ( ) <EOL> bundle_1 = Bundle ( data = { <EOL> '<STR_LIT>' : [ ] , <EOL> } ) <EOL> hydrated1 = nrrnr . full_hydrate ( bundle_1 ) <EOL> self . assertEqual ( hydrated1 . data . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( hydrated1 . data [ '<STR_LIT>' ] , [ ] ) <EOL> def test_optional_required_data ( self ) : <EOL> nmbr = NullableMediaBitResource ( ) <EOL> bundle_1 = Bundle ( data = { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> } ) <EOL> try : <EOL> hydrated1 = nmbr . full_hydrate ( bundle_1 ) <EOL> self . fail ( ) <EOL> except Note . DoesNotExist : <EOL> pass <EOL> bmbr = BlankMediaBitResource ( ) <EOL> hydrated1 = bmbr . full_hydrate ( bundle_1 ) <EOL> self . assertEqual ( hydrated1 . obj . title , "<STR_LIT>" ) <EOL> self . assertEqual ( hydrated1 . obj . note . pk , <NUM_LIT:1> ) <EOL> def test_nullable_tomany_full_hydrate ( self ) : <EOL> nrrnr = NullableRelatedNoteResource ( ) <EOL> bundle_1 = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> } ) <EOL> hydrated = nrrnr . full_hydrate ( bundle_1 ) <EOL> hydrated = nrrnr . hydrate_m2m ( hydrated ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated . data [ '<STR_LIT>' ] , [ ] ) <EOL> bundle_2 = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> hydrated2 = nrrnr . full_hydrate ( bundle_2 ) <EOL> hydrated2 = nrrnr . hydrate_m2m ( hydrated2 ) <EOL> self . assertEqual ( hydrated2 . data [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( hydrated2 . data [ '<STR_LIT>' ] , [ ] ) <EOL> bundle_3 = Bundle ( data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> hydrated3 = nrrnr . obj_create ( bundle_2 ) <EOL> self . assertEqual ( hydrated2 . obj . author . username , u'<STR_LIT>' ) <EOL> self . assertEqual ( hydrated2 . obj . subjects . count ( ) , <NUM_LIT:0> ) <EOL> def test_per_user_authorization ( self ) : <EOL> from django . contrib . auth . models import AnonymousUser , User <EOL> punr = PerUserNoteResource ( ) <EOL> empty_request = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:GET>' : { } } ) <EOL> anony_request = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:user>' : AnonymousUser ( ) } ) <EOL> authed_request = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:user>' : User . objects . get ( username = '<STR_LIT>' ) } ) <EOL> authed_request2 = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:user>' : User . objects . get ( username = '<STR_LIT>' ) } ) <EOL> self . assertEqual ( punr . _meta . queryset . count ( ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( punr . apply_authorization_limits ( empty_request , punr . get_object_list ( empty_request ) ) . count ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( punr . _pre_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( punr . _post_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( punr . obj_get_list ( request = empty_request ) . count ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( punr . apply_authorization_limits ( anony_request , punr . get_object_list ( anony_request ) ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( punr . obj_get_list ( request = anony_request ) . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( punr . apply_authorization_limits ( authed_request , punr . get_object_list ( authed_request ) ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( punr . obj_get_list ( request = authed_request ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( punr . apply_authorization_limits ( authed_request2 , punr . get_object_list ( authed_request2 ) ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( punr . obj_get_list ( request = authed_request2 ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( list ( punr . apply_authorization_limits ( authed_request , punr . get_object_list ( authed_request ) ) . values_list ( '<STR_LIT:id>' , flat = True ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( list ( punr . apply_authorization_limits ( authed_request2 , punr . get_object_list ( authed_request2 ) ) . values_list ( '<STR_LIT:id>' , flat = True ) ) , [ <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> def test_per_object_authorization ( self ) : <EOL> ponr = PerObjectNoteResource ( ) <EOL> empty_request = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:GET>' : { } } ) <EOL> self . assertEqual ( ponr . _meta . queryset . count ( ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( ponr . get_object_list ( empty_request ) ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( ponr . apply_authorization_limits ( empty_request , ponr . get_object_list ( empty_request ) ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( ponr . _pre_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( ponr . _post_limits , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( ponr . obj_get_list ( request = empty_request ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( ponr . _pre_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( ponr . _post_limits , <NUM_LIT:6> ) <EOL> self . assertEqual ( len ( ponr . obj_get_list ( request = empty_request , is_active = True ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( ponr . _pre_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( ponr . _post_limits , <NUM_LIT:4> ) <EOL> def regression_test_per_object_detail ( self ) : <EOL> ponr = PerObjectNoteResource ( ) <EOL> empty_request = type ( '<STR_LIT>' , ( object , ) , { '<STR_LIT:GET>' : { } } ) <EOL> self . assertEqual ( ponr . _meta . queryset . count ( ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( isinstance ( ponr . obj_get ( request = empty_request , pk = <NUM_LIT:1> ) , Note ) ) <EOL> self . assertEqual ( ponr . obj_get ( request = empty_request , pk = <NUM_LIT:1> ) . pk , <NUM_LIT:1> ) <EOL> self . assertEqual ( ponr . _pre_limits , <NUM_LIT:0> ) <EOL> self . assertEqual ( ponr . _post_limits , <NUM_LIT:1> ) <EOL> try : <EOL> too_many = ponr . obj_get ( request = empty_request , is_active = True , pk__gte = <NUM_LIT:1> ) <EOL> self . fail ( ) <EOL> except MultipleObjectsReturned , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> try : <EOL> too_many = ponr . obj_get ( request = empty_request , pk = <NUM_LIT> ) <EOL> self . fail ( ) <EOL> except Note . DoesNotExist , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> def test_browser_cache ( self ) : <EOL> resource = NoteResource ( ) <EOL> request = MockRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertFalse ( resp . has_header ( '<STR_LIT>' ) ) <EOL> request . META = { '<STR_LIT>' : '<STR_LIT>' } <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertTrue ( resp . has_header ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( resp . _headers [ '<STR_LIT>' ] , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_custom_paginator ( self ) : <EOL> mock_request = MockRequest ( ) <EOL> customs = CustomPageNoteResource ( ) . get_list ( mock_request ) <EOL> data = json . loads ( customs . content ) <EOL> self . assertEqual ( len ( data ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_readonly_full_hydrate ( self ) : <EOL> rornr = ReadOnlyRelatedNoteResource ( ) <EOL> note = Note . objects . get ( pk = <NUM_LIT:1> ) <EOL> dbundle = Bundle ( obj = note ) <EOL> dehydrated = rornr . full_dehydrate ( dbundle ) <EOL> self . assertTrue ( '<STR_LIT>' in dehydrated . data ) <EOL> hbundle = Bundle ( obj = note , data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> } ) <EOL> hydrated = rornr . full_hydrate ( hbundle ) <EOL> self . assertEqual ( hydrated . obj . author . username , '<STR_LIT>' ) <EOL> hbundle_2 = Bundle ( obj = note , data = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : aware_datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> hydrated_2 = rornr . full_hydrate ( hbundle_2 ) <EOL> self . assertEqual ( hydrated_2 . obj . author . username , '<STR_LIT>' ) <EOL> class BasicAuthResourceTestCase ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_dispatch_list ( self ) : <EOL> resource = BasicAuthNoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> try : <EOL> resp = resource . dispatch_list ( request ) <EOL> self . fail ( ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request ) <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> john_doe = User . objects . get ( username = '<STR_LIT>' ) <EOL> john_doe . set_password ( '<STR_LIT>' ) <EOL> john_doe . save ( ) <EOL> request . META [ '<STR_LIT>' ] = '<STR_LIT>' % base64 . b64encode ( '<STR_LIT>' ) <EOL> resp = resource . dispatch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> def test_dispatch_detail ( self ) : <EOL> resource = BasicAuthNoteResource ( ) <EOL> request = HttpRequest ( ) <EOL> request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> request . method = '<STR_LIT:GET>' <EOL> try : <EOL> resp = resource . dispatch_detail ( request , pk = <NUM_LIT:1> ) <EOL> self . fail ( ) <EOL> except ImmediateHttpResponse , e : <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> resp = resource . wrap_view ( '<STR_LIT>' ) ( request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( e . response . status_code , <NUM_LIT> ) <EOL> john_doe = User . objects . get ( username = '<STR_LIT>' ) <EOL> john_doe . set_password ( '<STR_LIT>' ) <EOL> john_doe . save ( ) <EOL> request . META [ '<STR_LIT>' ] = '<STR_LIT>' % base64 . b64encode ( '<STR_LIT>' ) <EOL> resp = resource . dispatch_list ( request ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> class YouFail ( Exception ) : <EOL> pass <EOL> class BustedResource ( BasicResource ) : <EOL> def get_list ( self , request , ** kwargs ) : <EOL> raise YouFail ( "<STR_LIT>" ) <EOL> def get_detail ( self , request , ** kwargs ) : <EOL> raise NotFound ( "<STR_LIT>" ) <EOL> def post_list ( self , request , ** kwargs ) : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> class BustedResourceTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( BustedResourceTestCase , self ) . setUp ( ) <EOL> self . old_debug = settings . DEBUG <EOL> self . old_full_debug = getattr ( settings , '<STR_LIT>' , False ) <EOL> self . old_canned_error = getattr ( settings , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . old_broken_links = getattr ( settings , '<STR_LIT>' , False ) <EOL> self . resource = BustedResource ( ) <EOL> self . request = HttpRequest ( ) <EOL> self . request . GET = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . request . method = '<STR_LIT:GET>' <EOL> def tearDown ( self ) : <EOL> settings . DEBUG = self . old_debug <EOL> settings . TASTYPIE_FULL_DEBUG = self . old_full_debug <EOL> settings . TASTYPIE_CANNED_ERROR = self . old_canned_error <EOL> settings . SEND_BROKEN_LINK_EMAILS = self . old_broken_links <EOL> super ( BustedResourceTestCase , self ) . setUp ( ) <EOL> def test_debug_on_with_full ( self ) : <EOL> settings . DEBUG = True <EOL> settings . TASTYPIE_FULL_DEBUG = True <EOL> try : <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . fail ( ) <EOL> except YouFail : <EOL> pass <EOL> def test_debug_on_without_full ( self ) : <EOL> settings . DEBUG = True <EOL> settings . TASTYPIE_FULL_DEBUG = False <EOL> mail . outbox = [ ] <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> content = json . loads ( resp . content ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( len ( content [ '<STR_LIT>' ] ) > <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:0> ) <EOL> def test_debug_off ( self ) : <EOL> settings . DEBUG = False <EOL> settings . TASTYPIE_FULL_DEBUG = False <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> SimpleHandler . logged = [ ] <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( SimpleHandler . logged ) , <NUM_LIT:1> ) <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( SimpleHandler . logged ) , <NUM_LIT:1> ) <EOL> settings . TASTYPIE_CANNED_ERROR = "<STR_LIT>" <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( SimpleHandler . logged ) , <NUM_LIT:2> ) <EOL> SimpleHandler . logged = [ ] <EOL> else : <EOL> mail . outbox = [ ] <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> settings . SEND_BROKEN_LINK_EMAILS = True <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:2> ) <EOL> settings . TASTYPIE_CANNED_ERROR = "<STR_LIT>" <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:3> ) <EOL> mail . outbox = [ ] <EOL> def test_http404_raises_404 ( self ) : <EOL> self . request . method = '<STR_LIT:POST>' <EOL> resp = self . resource . wrap_view ( '<STR_LIT>' ) ( self . request , pk = <NUM_LIT:1> ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) </s>
