<s> import unittest , yaml , twitterwrapper <EOL> from functools import partial <EOL> class DummyConnection : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . result = dict ( ) <EOL> def FetchUrl ( self , url , ** other_params ) : <EOL> self . lastUrl = url <EOL> self . lastParams = other_params <EOL> return self . get_result ( ) <EOL> def PrefixURL ( self , url ) : <EOL> return url <EOL> def _BuildUrl ( self , url ) : <EOL> return url <EOL> def set_result ( self , result ) : <EOL> self . result = result <EOL> def get_result ( self ) : <EOL> return self . result <EOL> def is_url ( self , url ) : <EOL> return self . lastUrl == url <EOL> class ApiMethodTests ( unittest . TestCase ) : <EOL> API_FILE = "<STR_LIT>" <EOL> FIXTURE_FILE = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> with open ( self . API_FILE ) as f : <EOL> specification = yaml . load ( f ) <EOL> self . dummy = DummyConnection ( ) <EOL> self . api = twitterwrapper . Api ( specification = specification , connection = self . dummy ) <EOL> self . _load_fixture ( self . FIXTURE_FILE ) <EOL> def _load_fixture ( self , fixture ) : <EOL> with open ( fixture ) as f : <EOL> self . fixture = yaml . load ( f ) <EOL> return self . fixture <EOL> def assertUrl ( self , url ) : <EOL> self . assertTrue ( self . dummy . is_url ( url ) ) <EOL> def assertInstanceOf ( self , a , t ) : <EOL> self . assertTrue ( isinstance ( a , t ) ) <EOL> class YAMLLoadingTests ( ApiMethodTests ) : <EOL> """<STR_LIT>""" <EOL> API_FILE = "<STR_LIT>" <EOL> def test_shallow_loading ( self ) : <EOL> self . assertTrue ( hasattr ( self . api , '<STR_LIT>' ) ) <EOL> self . api . shallow_method ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_nested_loading ( self ) : <EOL> parent = self . api . nested_methods <EOL> parent . nested_1 ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> parent . nested_2 ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> parent . nested_3 ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_very_nested_loading ( self ) : <EOL> parent = self . api . very_nested_methods <EOL> parent . nested_1 . very_nested ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> parent . nested_2 . very_nested ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_inherit_model ( self ) : <EOL> self . assertInstanceOf ( self . api . inherited_model ( ) , twitterwrapper . models . Status ) <EOL> self . assertInstanceOf ( self . api . inherited_model . descendent ( ) , twitterwrapper . models . Status ) <EOL> def test_overwrite_model ( self ) : <EOL> self . assertInstanceOf ( self . api . not_inherited_model ( ) , twitterwrapper . models . Status ) <EOL> self . assertInstanceOf ( self . api . not_inherited_model . descendent ( ) , twitterwrapper . models . User ) <EOL> self . assertInstanceOf ( self . api . not_inherited_model ( ) , twitterwrapper . models . Status ) <EOL> self . assertInstanceOf ( self . api . not_inherited_model . emancipated_descendent ( ) , dict ) <EOL> def test_inherit_doc ( self ) : <EOL> self . assertEqual ( self . api . inherited_model . __doc__ , '<STR_LIT>' ) <EOL> self . assertEqual ( self . api . inherited_model . descendent . __doc__ , "<STR_LIT>" ) <EOL> def test_dont_inherit_others ( self ) : <EOL> parent = self . api . not_inheriting_others <EOL> child = parent . descendent <EOL> parent ( <NUM_LIT:1> , some_param = <NUM_LIT:0> ) <EOL> parent_url = self . dummy . lastUrl <EOL> self . assertTrue ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> self . assertTrue ( "<STR_LIT>" in self . dummy . lastParams [ "<STR_LIT>" ] ) <EOL> self . assertTrue ( "<STR_LIT>" in self . dummy . lastParams [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <NUM_LIT:0> ) <EOL> child ( <NUM_LIT:1> , some_param = <NUM_LIT:0> ) <EOL> self . assertFalse ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> self . assertTrue ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> self . assertFalse ( "<STR_LIT>" in self . dummy . lastParams [ "<STR_LIT>" ] ) <EOL> self . assertTrue ( "<STR_LIT>" in self . dummy . lastParams [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , <NUM_LIT:0> ) <EOL> def test_dont_inherit_url ( self ) : <EOL> self . api . not_inheriting_url ( ) <EOL> self . assertRaises ( TypeError , self . api . not_inheriting_url . descendent ) <EOL> class RequestTests ( ApiMethodTests ) : <EOL> """<STR_LIT>""" <EOL> API_FILE = "<STR_LIT>" <EOL> def test_basic ( self ) : <EOL> self . api . basic ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( self . dummy . lastParams [ "<STR_LIT>" ] , dict ( ) ) <EOL> self . assertFalse ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> def test_basic_post ( self ) : <EOL> self . api . post_basic ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( self . dummy . lastParams [ "<STR_LIT>" ] , dict ( ) ) <EOL> self . assertFalse ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> def test_extra_params ( self ) : <EOL> self . api . basic ( param = "<STR_LIT:hello>" ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( <EOL> self . dummy . lastParams [ "<STR_LIT>" ] , <EOL> { "<STR_LIT>" : "<STR_LIT:hello>" } ) <EOL> def test_extra_params_post ( self ) : <EOL> self . api . post_basic ( param = "<STR_LIT:hello>" ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( <EOL> self . dummy . lastParams [ "<STR_LIT>" ] , <EOL> { "<STR_LIT>" : "<STR_LIT:hello>" } ) <EOL> def test_url_matching ( self ) : <EOL> self . api . url_with_matches ( a = "<STR_LIT>" , b = "<STR_LIT:hello>" ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_callable_parent ( self ) : <EOL> self . api . callable_parent ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . api . callable_parent . child ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_not_callable_parent ( self ) : <EOL> self . assertRaises ( TypeError , self . api . not_callable_parent ) <EOL> self . api . not_callable_parent . child ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_plural_singular_results ( self ) : <EOL> self . dummy . set_result ( self . fixture [ "<STR_LIT:status>" ] ) <EOL> self . assertTrue ( isinstance ( self . api . test_status ( ) , twitterwrapper . models . Status ) ) <EOL> self . dummy . set_result ( self . fixture [ "<STR_LIT>" ] ) <EOL> result = self . api . test_status ( ) <EOL> self . assertTrue ( isinstance ( result , list ) ) <EOL> for s in result : <EOL> self . assertTrue ( isinstance ( s , twitterwrapper . models . Status ) ) <EOL> def test_default_param_id ( self ) : <EOL> self . api . with_default_param_id ( <NUM_LIT> ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( <EOL> self . dummy . lastParams [ "<STR_LIT>" ] , <EOL> { "<STR_LIT:id>" : <NUM_LIT> } <EOL> ) <EOL> def test_default_param_other ( self ) : <EOL> self . api . with_default_param ( "<STR_LIT>" ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( <EOL> self . dummy . lastParams [ "<STR_LIT>" ] , <EOL> { "<STR_LIT>" : "<STR_LIT>" } <EOL> ) <EOL> def test_default_param_in_url ( self ) : <EOL> self . api . with_default_param_in_url ( "<STR_LIT>" ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> class ModelBlessingTests ( ApiMethodTests ) : <EOL> """<STR_LIT>""" <EOL> API_FILE = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> ApiMethodTests . setUp ( self ) <EOL> self . dummy . set_result ( self . fixture [ "<STR_LIT:status>" ] ) <EOL> self . status = self . api . test_status ( ) <EOL> def test_attachment_shallow ( self ) : <EOL> self . status . shallow_call ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEquals ( self . dummy . lastParams [ "<STR_LIT>" ] , dict ( ) ) <EOL> self . assertFalse ( "<STR_LIT>" in self . dummy . lastParams ) <EOL> def test_attachment_deep ( self ) : <EOL> self . status . deep_call_parent . deep_call_child ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> def test_container_id_shallow ( self ) : <EOL> self . status . post_with_container_id ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , self . status . id ) <EOL> self . status . get_with_container_id ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , self . status . id ) <EOL> def test_container_id_deep ( self ) : <EOL> self . status . deep_call_parent . deep_post_with_container_id ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , self . status . id ) <EOL> self . status . deep_call_parent . deep_get_with_container_id ( ) <EOL> self . assertUrl ( "<STR_LIT>" ) <EOL> self . assertEqual ( self . dummy . lastParams [ "<STR_LIT>" ] [ "<STR_LIT>" ] , self . status . id ) <EOL> def test_id_in_url ( self ) : <EOL> self . status . should_insert_id ( ) <EOL> self . assertUrl ( "<STR_LIT>" % self . status . id ) <EOL> def test_other_in_url ( self ) : <EOL> self . status . should_insert_text ( ) <EOL> self . assertUrl ( "<STR_LIT>" % self . status . text ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> loader = unittest . TestLoader ( ) <EOL> suite = loader . loadTestsFromTestCase ( YAMLLoadingTests ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) <EOL> suite = loader . loadTestsFromTestCase ( RequestTests ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) <EOL> suite = loader . loadTestsFromTestCase ( ModelBlessingTests ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
