<s> from django . http import HttpRequest <EOL> from django . test import TestCase <EOL> from django . utils import simplejson as json <EOL> class ViewsTestCase ( TestCase ) : <EOL> def test_gets ( self ) : <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT>' ] , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:20> ) <EOL> self . assertEqual ( len ( deserialized [ '<STR_LIT>' ] ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( [ obj [ '<STR_LIT:title>' ] for obj in deserialized [ '<STR_LIT>' ] ] , [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:12> ) <EOL> self . assertEqual ( deserialized [ '<STR_LIT:title>' ] , u'<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> deserialized = json . loads ( resp . content ) <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( deserialized [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( [ obj [ '<STR_LIT:title>' ] for obj in deserialized [ '<STR_LIT>' ] ] , [ u'<STR_LIT>' , u'<STR_LIT>' ] ) <EOL> def test_posts ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _raw_post_data = post_data <EOL> resp = self . client . post ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp [ '<STR_LIT:location>' ] , '<STR_LIT>' ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> obj = json . loads ( resp . content ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_puts ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _raw_post_data = post_data <EOL> resp = self . client . put ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> resp = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> obj = json . loads ( resp . content ) <EOL> self . assertEqual ( obj [ '<STR_LIT:content>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( obj [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( obj [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> def test_api_field_error ( self ) : <EOL> request = HttpRequest ( ) <EOL> post_data = '<STR_LIT>' <EOL> request . _raw_post_data = post_data <EOL> resp = self . client . post ( '<STR_LIT>' , data = post_data , content_type = '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , "<STR_LIT>" ) <EOL> def test_options ( self ) : <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT:GET>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content , allows ) <EOL> resp = self . client . options ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> allows = '<STR_LIT:GET>' <EOL> self . assertEqual ( resp [ '<STR_LIT>' ] , allows ) <EOL> self . assertEqual ( resp . content , allows ) </s>
