<s> """<STR_LIT>""" <EOL> import httplib <EOL> import json <EOL> import os <EOL> import unittest <EOL> import google <EOL> import mox <EOL> from google . appengine . tools . devappserver2 . endpoints import discovery_api_proxy <EOL> from google . appengine . tools . devappserver2 . endpoints import test_utils <EOL> class DiscoveryApiProxyTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _common_setup ( ) <EOL> self . mox = mox . Mox ( ) <EOL> def tearDown ( self ) : <EOL> self . mox . UnsetStubs ( ) <EOL> def _common_setup ( self ) : <EOL> self . discovery_api = discovery_api_proxy . DiscoveryApiProxy ( ) <EOL> api_config_file = os . path . join ( os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' ) <EOL> with open ( api_config_file , '<STR_LIT:r>' ) as api_file : <EOL> api_config = api_file . read ( ) <EOL> self . api_config_dict = json . loads ( api_config ) <EOL> def connection_response ( self ) : <EOL> return self . _response <EOL> def prepare_discovery_request ( self , status_code , body ) : <EOL> self . mox . StubOutWithMock ( httplib . HTTPSConnection , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( httplib . HTTPSConnection , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( httplib . HTTPSConnection , '<STR_LIT>' ) <EOL> httplib . HTTPSConnection . request ( mox . IsA ( basestring ) , mox . IsA ( basestring ) , <EOL> mox . IgnoreArg ( ) , mox . IsA ( dict ) ) <EOL> httplib . HTTPSConnection . getresponse ( ) . AndReturn ( <EOL> test_utils . MockConnectionResponse ( status_code , body ) ) <EOL> httplib . HTTPSConnection . close ( ) <EOL> def test_generate_discovery_doc_rest ( self ) : <EOL> body = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . prepare_discovery_request ( <NUM_LIT:200> , json . dumps ( body ) ) <EOL> self . mox . ReplayAll ( ) <EOL> doc = self . discovery_api . generate_discovery_doc ( <EOL> self . api_config_dict , '<STR_LIT>' ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertTrue ( doc ) <EOL> api_config = json . loads ( doc ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> api_config [ '<STR_LIT>' ] ) <EOL> def test_generate_discovery_doc_rpc ( self ) : <EOL> body = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . prepare_discovery_request ( <NUM_LIT:200> , json . dumps ( body ) ) <EOL> self . mox . ReplayAll ( ) <EOL> doc = self . discovery_api . generate_discovery_doc ( <EOL> self . api_config_dict , '<STR_LIT>' ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertTrue ( doc ) <EOL> api_config = json . loads ( doc ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> api_config [ '<STR_LIT>' ] ) <EOL> def test_generate_discovery_doc_invalid_format ( self ) : <EOL> self . _response = test_utils . MockConnectionResponse ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , <EOL> self . discovery_api . generate_discovery_doc , <EOL> self . api_config_dict , '<STR_LIT>' ) <EOL> def test_generate_discovery_doc_bad_api_config ( self ) : <EOL> self . prepare_discovery_request ( <NUM_LIT> , None ) <EOL> self . mox . ReplayAll ( ) <EOL> doc = self . discovery_api . generate_discovery_doc ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertIsNone ( doc ) <EOL> def test_get_static_file_existing ( self ) : <EOL> body = '<STR_LIT>' <EOL> self . prepare_discovery_request ( <NUM_LIT:200> , body ) <EOL> self . mox . ReplayAll ( ) <EOL> response , response_body = self . discovery_api . get_static_file ( <EOL> '<STR_LIT>' ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status ) <EOL> self . assertEqual ( body , response_body ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
