<s> import json <EOL> import unittest <EOL> from tests import SmsApiTestCase <EOL> from smsapi . responses import ApiResponse , ApiError <EOL> class ApiResponseTestCase ( SmsApiTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( ApiResponseTestCase , self ) . setUp ( ) <EOL> class HttpResponse ( object ) : <EOL> def __init__ ( self ) : <EOL> self . data = None <EOL> def read ( self ) : <EOL> return self . data <EOL> def getcode ( self ) : <EOL> return <NUM_LIT:200> <EOL> def geturl ( self ) : <EOL> return '<STR_LIT>' <EOL> self . response_obj = HttpResponse ( ) <EOL> def test_single_response ( self ) : <EOL> data = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . response_obj . data = json . dumps ( data ) <EOL> result = ApiResponse ( self . response_obj ) <EOL> self . assertEqual ( result . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( result . k1 , '<STR_LIT>' ) <EOL> self . assertEqual ( result . k1 , '<STR_LIT>' ) <EOL> def test_list_response ( self ) : <EOL> data = [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> ] <EOL> self . response_obj . data = json . dumps ( data ) <EOL> result = ApiResponse ( self . response_obj ) <EOL> self . assertEqual ( result . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( result . k1 , '<STR_LIT>' ) <EOL> self . assertEqual ( result . k2 , '<STR_LIT>' ) <EOL> for r in result : <EOL> self . assertEqual ( r . k1 , '<STR_LIT>' ) <EOL> self . assertEqual ( r . k2 , '<STR_LIT>' ) <EOL> def test_response_with_list ( self ) : <EOL> data = { '<STR_LIT:list>' : [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> ] } <EOL> self . response_obj . data = json . dumps ( data ) <EOL> result = ApiResponse ( self . response_obj ) <EOL> self . assertEqual ( result . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( result . k1 , '<STR_LIT>' ) <EOL> self . assertEqual ( result . k2 , '<STR_LIT>' ) <EOL> for r in result : <EOL> self . assertEqual ( r . k1 , '<STR_LIT>' ) <EOL> self . assertEqual ( r . k2 , '<STR_LIT>' ) <EOL> def test_responses_empty_list ( self ) : <EOL> data = { '<STR_LIT:count>' : <NUM_LIT:1> , '<STR_LIT:list>' : [ ] } <EOL> self . response_obj . data = json . dumps ( data ) <EOL> result = ApiResponse ( self . response_obj ) <EOL> self . assertEqual ( result . count , <NUM_LIT:1> ) <EOL> def test_error_response ( self ) : <EOL> data = { '<STR_LIT:error>' : '<STR_LIT>' } <EOL> self . response_obj . data = json . dumps ( data ) <EOL> self . assertRaises ( ApiError , ApiResponse , self . response_obj ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( ApiResponseTestCase ) ) <EOL> return suite </s>
