<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import json <EOL> import os <EOL> import gflags as flags <EOL> from google . apputils import basetest <EOL> from googleapis . codegen import data_types <EOL> from googleapis . codegen import language_model <EOL> from googleapis . codegen . api import Api <EOL> from googleapis . codegen . api import AuthScope <EOL> from googleapis . codegen . api import Method <EOL> from googleapis . codegen . api import Resource <EOL> from googleapis . codegen . api import Schema <EOL> from googleapis . codegen . api_exception import ApiException <EOL> FLAGS = flags . FLAGS <EOL> class FakeLanguageModel ( language_model . LanguageModel ) : <EOL> def GetCodeTypeFromDictionary ( self , def_dict ) : <EOL> return def_dict . get ( '<STR_LIT:type>' ) <EOL> def ArrayOf ( self , unused_var , s ) : <EOL> return '<STR_LIT>' % s <EOL> class ApiTest ( basetest . TestCase ) : <EOL> _TEST_DISCOVERY_DOC = '<STR_LIT>' <EOL> _TEST_DISCOVERY_RPC_DOC = '<STR_LIT>' <EOL> _TEST_SHARED_TYPES_DOC = '<STR_LIT>' <EOL> def ApiFromDiscoveryDoc ( self , path ) : <EOL> """<STR_LIT>""" <EOL> f = open ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' , path ) ) <EOL> discovery_doc = json . loads ( f . read ( ) ) <EOL> f . close ( ) <EOL> return Api ( discovery_doc ) <EOL> def testLazySchemaForCreation ( self ) : <EOL> """<STR_LIT>""" <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> for schema in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertTrue ( isinstance ( api . _schemas [ schema ] , Schema ) ) <EOL> def SchemaRefInProperties ( self ) : <EOL> """<STR_LIT>""" <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> activity_schema = api . _schemas [ '<STR_LIT>' ] <EOL> for prop in activity_schema . values [ '<STR_LIT>' ] : <EOL> if prop . values [ '<STR_LIT>' ] == '<STR_LIT:object>' : <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> prop . object_type . values [ '<STR_LIT>' ] ) <EOL> def testMakeDefaultSchemaNameFromTheDictTag ( self ) : <EOL> """<STR_LIT>""" <EOL> discovery_doc = json . loads ( <EOL> """<STR_LIT>""" ) <EOL> gen = Api ( discovery_doc ) <EOL> self . assertTrue ( '<STR_LIT>' in gen . _schemas ) <EOL> self . assertTrue ( '<STR_LIT>' in gen . _schemas ) <EOL> def testUnknownHttpMethod ( self ) : <EOL> """<STR_LIT>""" <EOL> api = Api ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' , '<STR_LIT>' : { } } ) <EOL> unused_resource = Resource ( api , '<STR_LIT>' , { '<STR_LIT>' : { } } ) <EOL> self . assertRaises ( ApiException , <EOL> Method , api , '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } <EOL> } ) <EOL> def testRequiredParameterList ( self ) : <EOL> """<STR_LIT>""" <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> tests_executed = <NUM_LIT:0> <EOL> for resource in api . values [ '<STR_LIT>' ] : <EOL> if resource . values [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> for method in resource . values [ '<STR_LIT>' ] : <EOL> if method . required_parameters : <EOL> required_names = [ p . values [ '<STR_LIT>' ] <EOL> for p in method . required_parameters ] <EOL> self . assertEquals ( method . values [ '<STR_LIT>' ] , required_names ) <EOL> tests_executed += <NUM_LIT:1> <EOL> method = api . MethodByName ( '<STR_LIT>' ) <EOL> optional_names = set ( p . values [ '<STR_LIT>' ] <EOL> for p in method . optional_parameters ) <EOL> self . assertEquals ( set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> optional_names ) <EOL> tests_executed += <NUM_LIT:1> <EOL> self . assertEquals ( <NUM_LIT:7> , tests_executed ) <EOL> def testSchemaLoadingAsString ( self ) : <EOL> """<STR_LIT>""" <EOL> api = self . ApiFromDiscoveryDoc ( '<STR_LIT>' ) <EOL> self . assertEquals ( <NUM_LIT:4> , len ( api . _schemas ) ) <EOL> def testSubResources ( self ) : <EOL> """<STR_LIT>""" <EOL> def CountResourceTree ( resource ) : <EOL> ret = <NUM_LIT:0> <EOL> for r in resource . _resources : <EOL> ret += <NUM_LIT:1> + CountResourceTree ( r ) <EOL> return ret <EOL> api = self . ApiFromDiscoveryDoc ( '<STR_LIT>' ) <EOL> top_level_resources = <NUM_LIT:0> <EOL> total_resources = <NUM_LIT:0> <EOL> non_method_resources = <NUM_LIT:0> <EOL> have_sub_resources = <NUM_LIT:0> <EOL> have_sub_resources_and_methods = <NUM_LIT:0> <EOL> for r in api . _resources : <EOL> top_level_resources += <NUM_LIT:1> <EOL> total_resources += <NUM_LIT:1> + CountResourceTree ( r ) <EOL> if not r . _methods : <EOL> non_method_resources += <NUM_LIT:1> <EOL> if r . _resources : <EOL> have_sub_resources += <NUM_LIT:1> <EOL> if r . _resources and r . _methods : <EOL> have_sub_resources_and_methods += <NUM_LIT:1> <EOL> self . assertEquals ( <NUM_LIT> , total_resources ) <EOL> self . assertEquals ( <NUM_LIT:11> , top_level_resources ) <EOL> self . assertEquals ( <NUM_LIT:4> , non_method_resources ) <EOL> self . assertEquals ( <NUM_LIT:6> , have_sub_resources ) <EOL> self . assertEquals ( <NUM_LIT:2> , have_sub_resources_and_methods ) <EOL> def testParameters ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> delete = api . MethodByName ( '<STR_LIT>' ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( delete . query_parameters ) ) <EOL> self . assertEquals ( <NUM_LIT:3> , len ( delete . path_parameters ) ) <EOL> required_p = FindByWireName ( delete . values [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , required_p . location ) <EOL> post_id = FindByWireName ( delete . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT:path>' , post_id . location ) <EOL> def testEnums ( self ) : <EOL> gen = self . ApiFromDiscoveryDoc ( '<STR_LIT>' ) <EOL> m1 = gen . MethodByName ( '<STR_LIT>' ) <EOL> language = FindByWireName ( m1 . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> e = language . values [ '<STR_LIT>' ] <EOL> self . assertEquals ( m1 , e . parent ) <EOL> for name , value , desc in e . values [ '<STR_LIT>' ] : <EOL> self . assertTrue ( name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertTrue ( value in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertTrue ( desc in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> accuracy = FindByWireName ( m1 . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> e = accuracy . values [ '<STR_LIT>' ] <EOL> self . assertEquals ( m1 , e . parent ) <EOL> for name , value , desc in e . values [ '<STR_LIT>' ] : <EOL> self . assertTrue ( name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( value in [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ] ) <EOL> def testArrayParameter ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> search = api . MethodByName ( '<STR_LIT>' ) <EOL> filter_param = FindByWireName ( search . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( filter_param . data_type , <EOL> data_types . ArrayDataType ) ) <EOL> self . assertTrue ( isinstance ( filter_param . data_type . _base_type , <EOL> data_types . PrimitiveDataType ) ) <EOL> self . assertEquals ( '<STR_LIT:string>' , <EOL> filter_param . data_type . _base_type . values [ '<STR_LIT:type>' ] ) <EOL> def testRepeatedEnum ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> activities = FindByWireName ( api . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> list_method = FindByWireName ( activities . values [ '<STR_LIT>' ] , '<STR_LIT:list>' ) <EOL> options = [ p for p in list_method . values [ '<STR_LIT>' ] <EOL> if p . values [ '<STR_LIT>' ] == '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( options . data_type , data_types . ArrayDataType ) ) <EOL> self . assertTrue ( isinstance ( options . data_type . _base_type , data_types . Enum ) ) <EOL> self . assertEquals ( '<STR_LIT:string>' , options . data_type . _base_type . values [ '<STR_LIT:type>' ] ) <EOL> def testScopes ( self ) : <EOL> gen = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> scopes = gen . GetTemplateValue ( '<STR_LIT>' ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( scopes ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scopes [ <NUM_LIT:0> ] . GetTemplateValue ( '<STR_LIT:value>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scopes [ <NUM_LIT:0> ] . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scopes [ <NUM_LIT:1> ] . GetTemplateValue ( '<STR_LIT:value>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scopes [ <NUM_LIT:1> ] . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> def testAuthScope ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:description>' ) ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , { } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scope . GetTemplateValue ( '<STR_LIT:description>' ) ) <EOL> scope = AuthScope ( api , '<STR_LIT>' , { } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scope . GetTemplateValue ( '<STR_LIT:value>' ) ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scope . GetTemplateValue ( '<STR_LIT:value>' ) ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> scope = AuthScope ( api , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> scope = AuthScope ( api , '<STR_LIT>' , { } ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> scope = AuthScope ( api , '<STR_LIT:email>' , { } ) <EOL> self . assertEquals ( '<STR_LIT>' , scope . GetTemplateValue ( '<STR_LIT:name>' ) ) <EOL> def testPostVariations ( self ) : <EOL> gen = self . ApiFromDiscoveryDoc ( '<STR_LIT>' ) <EOL> r1 = FindByWireName ( gen . values [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> methods = r1 . values [ '<STR_LIT>' ] <EOL> m = FindByWireName ( methods , '<STR_LIT>' ) <EOL> self . assertIsNone ( m . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , m . values [ '<STR_LIT>' ] . class_name ) <EOL> m = FindByWireName ( methods , '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , m . values [ '<STR_LIT>' ] . class_name ) <EOL> self . assertEquals ( '<STR_LIT>' , m . values [ '<STR_LIT>' ] . class_name ) <EOL> m = FindByWireName ( methods , '<STR_LIT>' ) <EOL> self . assertIsNone ( m . values . get ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( isinstance ( m . values . get ( '<STR_LIT>' ) , data_types . Void ) ) <EOL> m = FindByWireName ( methods , '<STR_LIT>' ) <EOL> self . assertIsNone ( m . values . get ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( '<STR_LIT>' , m . values [ '<STR_LIT>' ] . class_name ) <EOL> m = FindByWireName ( methods , '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , m . values [ '<STR_LIT>' ] . class_name ) <EOL> self . assertTrue ( isinstance ( m . values . get ( '<STR_LIT>' ) , data_types . Void ) ) <EOL> def testSchemaParenting ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> for schema in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . assertIsNone ( api . _schemas [ schema ] . parent ) <EOL> for schema in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] : <EOL> self . assertTrue ( api . _schemas [ schema ] . parent ) <EOL> for name , schema in api . _schemas . items ( ) : <EOL> if schema . parent and schema . parent != api : <EOL> wire_name = schema . values [ '<STR_LIT>' ] <EOL> parent_wire_name = schema . parent . values [ '<STR_LIT>' ] <EOL> self . assertNotEquals ( name , parent_wire_name ) <EOL> self . assertTrue ( name . endswith ( '<STR_LIT:.>' . join ( [ parent_wire_name , wire_name ] ) ) ) <EOL> def testReadingRpcDiscovery ( self ) : <EOL> gen = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_RPC_DOC ) <EOL> self . assertEquals ( <NUM_LIT:0> , len ( gen . values [ '<STR_LIT>' ] ) ) <EOL> self . assertLess ( <NUM_LIT:5> , len ( gen . values [ '<STR_LIT>' ] ) ) <EOL> self . assertGreater ( <NUM_LIT:100> , len ( gen . values [ '<STR_LIT>' ] ) ) <EOL> for method in gen . values [ '<STR_LIT>' ] : <EOL> self . assertIsNotNone ( method . values [ '<STR_LIT:id>' ] ) <EOL> self . assertEquals ( '<STR_LIT:POST>' , method . values [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( method . values [ '<STR_LIT>' ] ) <EOL> def testNormalizeUrlComponents ( self ) : <EOL> googleapis_base = '<STR_LIT>' <EOL> def LoadApi ( discovery_dict ) : <EOL> d = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' } <EOL> d . update ( discovery_dict ) <EOL> api = Api ( d ) <EOL> return api <EOL> api = LoadApi ( { } ) <EOL> self . assertEquals ( googleapis_base , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> custom_path = '<STR_LIT>' <EOL> api = LoadApi ( { '<STR_LIT>' : custom_path } ) <EOL> self . assertEquals ( googleapis_base , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> custom_url = '<STR_LIT>' <EOL> api = LoadApi ( { '<STR_LIT>' : custom_url } ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : custom_url <EOL> } ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( ValueError , LoadApi , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRaises ( ValueError , LoadApi , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def testCanonicalName ( self ) : <EOL> d = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> api = Api ( d ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT:name>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . _class_name ) <EOL> def testNormalizeOwnerInformation ( self ) : <EOL> def LoadApi ( ** kwargs ) : <EOL> d = { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' } <EOL> d . update ( kwargs ) <EOL> return Api ( d ) <EOL> api = LoadApi ( ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( ownerName = '<STR_LIT>' , ownerDomain = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( ownerDomain = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( owner = '<STR_LIT>' , ownerDomain = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( servicePath = '<STR_LIT>' , <EOL> rootUrl = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( servicePath = '<STR_LIT>' , <EOL> rootUrl = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( servicePath = '<STR_LIT>' , <EOL> rootUrl = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> api = LoadApi ( servicePath = '<STR_LIT>' , <EOL> rootUrl = '<STR_LIT>' ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT>' ] ) <EOL> def testSharedTypes ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_SHARED_TYPES_DOC ) <EOL> api . VisitAll ( lambda o : o . SetLanguageModel ( language_model . LanguageModel ( ) ) ) <EOL> photos_feed_schema = api . _schemas [ '<STR_LIT>' ] <EOL> photo_schema = api . _schemas [ <EOL> '<STR_LIT>' ] <EOL> self . assertEquals ( '<STR_LIT>' , photos_feed_schema . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , photos_feed_schema . module . name ) <EOL> self . assertEquals ( '<STR_LIT>' , photo_schema . values [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( '<STR_LIT>' , photo_schema . module . name ) <EOL> self . assertEquals ( '<STR_LIT>' , photo_schema . module . path ) <EOL> def testMethods ( self ) : <EOL> api = self . ApiFromDiscoveryDoc ( self . _TEST_DISCOVERY_DOC ) <EOL> self . assertEquals ( api , api . top_level_methods [ <NUM_LIT:0> ] . parent ) <EOL> self . assertLess ( <NUM_LIT> , len ( api . all_methods ) ) <EOL> self . assertLess ( <NUM_LIT:0> , len ( api . top_level_methods ) ) <EOL> def testApiHasTitle ( self ) : <EOL> api_def = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { } } <EOL> api = Api ( api_def ) <EOL> self . assertEquals ( '<STR_LIT>' , api [ '<STR_LIT:title>' ] ) <EOL> def testExponentialBackoffDefault ( self ) : <EOL> discovery_doc = json . loads ( <EOL> """<STR_LIT>""" ) <EOL> api = Api ( discovery_doc ) <EOL> self . assertFalse ( api . values [ '<STR_LIT>' ] ) <EOL> discovery_doc2 = json . loads ( <EOL> """<STR_LIT>""" ) <EOL> api2 = Api ( discovery_doc2 ) <EOL> self . assertTrue ( api2 . values [ '<STR_LIT>' ] ) <EOL> class ApiModulesTest ( basetest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . discovery_doc = json . loads ( <EOL> """<STR_LIT>""" ) <EOL> self . language_model = FakeLanguageModel ( ) <EOL> def testModuleOwnerDomain ( self ) : <EOL> self . discovery_doc [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> api = Api ( self . discovery_doc ) <EOL> api . VisitAll ( lambda o : o . SetLanguageModel ( self . language_model ) ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] . path ) <EOL> def testModulePackagePath ( self ) : <EOL> self . discovery_doc [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> api = Api ( self . discovery_doc ) <EOL> api . VisitAll ( lambda o : o . SetLanguageModel ( self . language_model ) ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] . path ) <EOL> def testModuleOwnerDomainAndPackagePath ( self ) : <EOL> self . discovery_doc [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . discovery_doc [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> api = Api ( self . discovery_doc ) <EOL> api . VisitAll ( lambda o : o . SetLanguageModel ( self . language_model ) ) <EOL> self . assertEquals ( '<STR_LIT>' , api . values [ '<STR_LIT>' ] . path ) <EOL> def FindByWireName ( list_of_resource_or_method , wire_name ) : <EOL> """<STR_LIT>""" <EOL> for x in list_of_resource_or_method : <EOL> if x . values [ '<STR_LIT>' ] == wire_name : <EOL> return x <EOL> return None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> basetest . main ( ) </s>
