<s> import unittest <EOL> try : <EOL> import itty <EOL> from restless . it import IttyResource <EOL> except ImportError : <EOL> itty = None <EOL> IttyResource = object <EOL> from restless . utils import json <EOL> from . fakes import FakeHttpRequest <EOL> class ItTestResource ( IttyResource ) : <EOL> fake_db = [ ] <EOL> def fake_init ( self ) : <EOL> self . __class__ . fake_db = [ <EOL> { "<STR_LIT:id>" : <NUM_LIT:2> , "<STR_LIT:title>" : '<STR_LIT>' } , <EOL> { "<STR_LIT:id>" : <NUM_LIT:4> , "<STR_LIT:title>" : '<STR_LIT>' } , <EOL> { "<STR_LIT:id>" : <NUM_LIT:5> , "<STR_LIT:title>" : '<STR_LIT>' } , <EOL> ] <EOL> def list ( self ) : <EOL> return self . fake_db <EOL> def detail ( self , pk ) : <EOL> for item in self . fake_db : <EOL> if item [ '<STR_LIT:id>' ] == pk : <EOL> return item <EOL> def create ( self ) : <EOL> self . fake_db . append ( self . data ) <EOL> @ unittest . skipIf ( not itty , "<STR_LIT>" ) <EOL> class IttyResourceTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IttyResourceTestCase , self ) . setUp ( ) <EOL> self . res = ItTestResource ( ) <EOL> self . res . fake_init ( ) <EOL> def test_as_list ( self ) : <EOL> list_endpoint = ItTestResource . as_list ( ) <EOL> request = FakeHttpRequest ( '<STR_LIT:GET>' ) <EOL> resp = list_endpoint ( request ) <EOL> self . assertEqual ( resp . content_type , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( resp . output ) , { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:id>' : <NUM_LIT:2> , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } , <EOL> { <EOL> '<STR_LIT:id>' : <NUM_LIT:4> , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } , <EOL> { <EOL> '<STR_LIT:id>' : <NUM_LIT:5> , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> } ) <EOL> def test_as_detail ( self ) : <EOL> detail_endpoint = ItTestResource . as_detail ( ) <EOL> request = FakeHttpRequest ( '<STR_LIT:GET>' ) <EOL> resp = detail_endpoint ( request , <NUM_LIT:4> ) <EOL> self . assertEqual ( resp . content_type , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . status , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( resp . output ) , { <EOL> '<STR_LIT:id>' : <NUM_LIT:4> , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } ) <EOL> def test_is_debug ( self ) : <EOL> self . assertFalse ( self . res . is_debug ( ) ) <EOL> self . res . debug = True <EOL> self . addCleanup ( setattr , self . res , '<STR_LIT>' , False ) <EOL> self . assertTrue ( self . res . is_debug ( ) ) <EOL> def test_build_response ( self ) : <EOL> resp = self . res . build_response ( '<STR_LIT>' , status = <NUM_LIT> ) <EOL> self . assertEqual ( resp . status , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_type , '<STR_LIT:application/json>' ) <EOL> self . assertEqual ( resp . output , '<STR_LIT>' ) <EOL> def test_setup_urls ( self ) : <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT:GET>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT:POST>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> ItTestResource . setup_urls ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT:GET>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT:POST>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( itty . REQUEST_MAPPINGS [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( itty . REQUEST_MAPPINGS [ '<STR_LIT:GET>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( itty . REQUEST_MAPPINGS [ '<STR_LIT:GET>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) </s>
