<s> """<STR_LIT>""" <EOL> import tests . appenginesdk <EOL> from google . appengine . ext import testbed <EOL> from google . apputils import basetest <EOL> from tests . simian . mac . common import test_base as test_base <EOL> from simian import settings <EOL> from simian . mac . common import auth <EOL> class GenericContainer ( test_base . GenericContainer ) : <EOL> """<STR_LIT>""" <EOL> class RequestHandlerTest ( test_base . RequestHandlerTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( RequestHandlerTest , self ) . setUp ( ) <EOL> self . testbed = testbed . Testbed ( ) <EOL> self . testbed . setup_env ( <EOL> USER_EMAIL = '<STR_LIT>' , <EOL> USER_ID = '<STR_LIT>' , <EOL> USER_IS_ADMIN = '<STR_LIT:0>' , <EOL> DEFAULT_VERSION_HOSTNAME = '<STR_LIT>' ) <EOL> self . testbed . activate ( ) <EOL> self . testbed . init_datastore_v3_stub ( ) <EOL> self . testbed . init_memcache_stub ( ) <EOL> self . testbed . init_taskqueue_stub ( ) <EOL> self . testbed . init_user_stub ( ) <EOL> self . testbed . init_mail_stub ( ) <EOL> settings . ADMINS = [ '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> super ( RequestHandlerTest , self ) . tearDown ( ) <EOL> self . testbed . deactivate ( ) <EOL> def MockDoUserAuth ( self , user = None , is_admin = None , fail = False ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in self . _set_mock : <EOL> self . mox . StubOutWithMock ( auth , '<STR_LIT>' ) <EOL> self . _set_mock [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if fail : <EOL> if is_admin is None : <EOL> auth . DoUserAuth ( ) . AndRaise ( auth . NotAuthenticated ) <EOL> else : <EOL> auth . DoUserAuth ( is_admin = is_admin ) . AndRaise ( auth . NotAuthenticated ) <EOL> else : <EOL> if is_admin is None : <EOL> auth . DoUserAuth ( ) . AndReturn ( user ) <EOL> else : <EOL> auth . DoUserAuth ( is_admin = is_admin ) . AndReturn ( user ) <EOL> def MockDoOAuthAuth ( self , user = None , is_admin = None , fail = False ) : <EOL> """<STR_LIT>""" <EOL> if not '<STR_LIT>' in self . _set_mock : <EOL> self . mox . StubOutWithMock ( auth , '<STR_LIT>' ) <EOL> self . _set_mock [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if fail : <EOL> if is_admin is None : <EOL> auth . DoOAuthAuth ( ) . AndRaise ( auth . NotAuthenticated ) <EOL> else : <EOL> auth . DoOAuthAuth ( is_admin = is_admin ) . AndRaise ( auth . NotAuthenticated ) <EOL> else : <EOL> if is_admin is None : <EOL> auth . DoOAuthAuth ( ) . AndReturn ( user ) <EOL> else : <EOL> auth . DoOAuthAuth ( is_admin = is_admin ) . AndReturn ( user ) <EOL> def MockDoMunkiAuth ( self , fail = False , and_return = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> munki_auth_module = self . GetTestClassModule ( ) . gaeserver <EOL> if not hasattr ( munki_auth_module , '<STR_LIT>' ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in self . _set_mock : <EOL> self . mox . StubOutWithMock ( munki_auth_module , '<STR_LIT>' ) <EOL> self . _set_mock [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if fail : <EOL> self . GetTestClassModule ( ) . gaeserver . DoMunkiAuth ( ** kwargs ) . AndRaise ( <EOL> munki_auth_module . NotAuthenticated ) <EOL> else : <EOL> self . GetTestClassModule ( ) . gaeserver . DoMunkiAuth ( ** kwargs ) . AndReturn ( <EOL> and_return ) <EOL> def MockDoAnyAuth ( self , fail = False , and_return = None ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in self . _set_mock : <EOL> self . mox . StubOutWithMock ( auth , '<STR_LIT>' ) <EOL> self . _set_mock [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if fail : <EOL> auth . DoAnyAuth ( ) . AndRaise ( auth . NotAuthenticated ) <EOL> else : <EOL> auth . DoAnyAuth ( ) . AndReturn ( and_return ) <EOL> def MockModelStaticBase ( self , model_name , method_name , * args ) : <EOL> """<STR_LIT>""" <EOL> test_class_models = self . GetTestClassModule ( ) . models <EOL> model_class = getattr ( test_class_models , model_name ) <EOL> if '<STR_LIT>' % ( model_name , method_name ) not in self . _set_mock : <EOL> mock_model = self . mox . CreateMock ( getattr ( model_class , method_name ) ) <EOL> self . stubs . Set ( model_class , method_name , mock_model ) <EOL> self . _set_mock [ '<STR_LIT>' % ( model_name , method_name ) ] = mock_model <EOL> return getattr ( model_class , method_name ) ( * args ) <EOL> def MockModelStatic ( self , model_name , method_name , * args ) : <EOL> """<STR_LIT>""" <EOL> model = self . mox . CreateMockAnything ( ) <EOL> self . MockModelStaticBase ( model_name , method_name , * args ) . AndReturn ( model ) <EOL> return model <EOL> def MockModelStaticNone ( self , model_name , method_name , * args ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> self . MockModelStaticBase ( model_name , method_name , * args ) . AndReturn ( model ) <EOL> return model <EOL> def MockModel ( self , model_name , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> test_class_models = self . GetTestClassModule ( ) . models <EOL> if '<STR_LIT>' % model_name not in self . _set_mock : <EOL> self . mox . StubOutWithMock ( <EOL> getattr ( self . GetTestClassModule ( ) , '<STR_LIT>' ) , <EOL> model_name ) <EOL> for mock in self . _set_mock : <EOL> if mock . startswith ( '<STR_LIT>' % model_name ) : <EOL> self . stubs . Set ( <EOL> getattr ( test_class_models , model_name ) , <EOL> mock . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] , <EOL> self . _set_mock [ mock ] ) <EOL> self . _set_mock [ '<STR_LIT>' % model_name ] = <NUM_LIT:1> <EOL> model = self . mox . CreateMockAnything ( ) <EOL> getattr ( <EOL> self . GetTestClassModule ( ) . models , <EOL> model_name ) ( * args , ** kwargs ) . AndReturn ( model ) <EOL> return model <EOL> def main ( unused_argv ) : <EOL> basetest . main ( ) </s>
