<s> """<STR_LIT>""" <EOL> import datetime <EOL> import traceback <EOL> import unittest <EOL> import google <EOL> import mox <EOL> import webapp2 <EOL> from google . appengine . api import croninfo <EOL> from google . appengine . api import yaml_errors <EOL> from google . appengine . tools . devappserver2 import dispatcher <EOL> from google . appengine . tools . devappserver2 . admin import cron_handler <EOL> CRON_INFO_EXTERNAL = croninfo . CronInfoExternal ( cron = [ <EOL> croninfo . CronEntry ( <EOL> url = '<STR_LIT>' , <EOL> schedule = '<STR_LIT>' , <EOL> timezone = '<STR_LIT>' , <EOL> description = '<STR_LIT:description>' , <EOL> target = '<STR_LIT:version>' ) , <EOL> croninfo . CronEntry ( <EOL> url = '<STR_LIT>' , <EOL> schedule = '<STR_LIT>' , <EOL> description = '<STR_LIT:description>' ) , <EOL> ] ) <EOL> class CronHandlerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mox = mox . Mox ( ) <EOL> self . _pytz = cron_handler . pytz <EOL> def tearDown ( self ) : <EOL> cron_handler . pytz = self . _pytz <EOL> self . mox . UnsetStubs ( ) <EOL> def test_post ( self ) : <EOL> self . mox . StubOutWithMock ( cron_handler . CronHandler , '<STR_LIT>' ) <EOL> request = webapp2 . Request . blank ( '<STR_LIT>' , POST = { '<STR_LIT:url>' : '<STR_LIT>' } ) <EOL> response = webapp2 . Response ( ) <EOL> handler = cron_handler . CronHandler ( request , response ) <EOL> handler . dispatcher = self . mox . CreateMock ( dispatcher . Dispatcher ) <EOL> handler . dispatcher . add_request ( <EOL> method = '<STR_LIT:GET>' , <EOL> relative_url = '<STR_LIT>' , <EOL> headers = [ ( '<STR_LIT>' , '<STR_LIT:true>' ) ] , <EOL> body = '<STR_LIT>' , <EOL> source_ip = '<STR_LIT>' ) . AndReturn ( <EOL> dispatcher . ResponseTuple ( '<STR_LIT>' , [ ] , '<STR_LIT>' ) ) <EOL> self . mox . ReplayAll ( ) <EOL> handler . post ( ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_int ) <EOL> def test_get_with_pytz ( self , pytz = object ( ) ) : <EOL> cron_handler . pytz = pytz <EOL> jobs = object ( ) <EOL> request = webapp2 . Request . blank ( '<STR_LIT>' ) <EOL> response = webapp2 . Response ( ) <EOL> handler = cron_handler . CronHandler ( request , response ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> handler . _get_cron_jobs ( ) . AndReturn ( jobs ) <EOL> handler . render ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : bool ( pytz ) , '<STR_LIT>' : jobs } ) . AndReturn ( <EOL> '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> handler . get ( ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . body ) <EOL> def test_get_without_pytz ( self ) : <EOL> self . test_get_with_pytz ( pytz = None ) <EOL> def test_get_with_invalid_cron_yaml ( self ) : <EOL> cron_handler . pytz = None <EOL> request = webapp2 . Request . blank ( '<STR_LIT>' ) <EOL> response = webapp2 . Response ( ) <EOL> handler = cron_handler . CronHandler ( request , response ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> self . mox . StubOutWithMock ( traceback , '<STR_LIT>' ) <EOL> handler . _get_cron_jobs ( ) . AndRaise ( yaml_errors . Error ) <EOL> traceback . format_exc ( ) . AndReturn ( '<STR_LIT>' ) <EOL> handler . render ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : False , '<STR_LIT>' : '<STR_LIT>' } ) . AndReturn ( '<STR_LIT>' ) <EOL> self . mox . ReplayAll ( ) <EOL> handler . get ( ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( '<STR_LIT>' , response . body ) <EOL> @ unittest . skipIf ( cron_handler . pytz is None , '<STR_LIT>' ) <EOL> def test_get_cron_jobs_with_pytz ( self ) : <EOL> handler = cron_handler . CronHandler ( None , None ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> handler . _parse_cron_yaml ( ) . AndReturn ( CRON_INFO_EXTERNAL ) <EOL> self . mox . ReplayAll ( ) <EOL> cron_jobs = handler . _get_cron_jobs ( ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( cron_jobs ) ) <EOL> next_runs = [ cron_jobs [ <NUM_LIT:0> ] . pop ( '<STR_LIT>' ) , cron_jobs [ <NUM_LIT:1> ] . pop ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( CRON_INFO_EXTERNAL . cron [ <NUM_LIT:0> ] . ToDict ( ) , cron_jobs [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( CRON_INFO_EXTERNAL . cron [ <NUM_LIT:1> ] . ToDict ( ) , cron_jobs [ <NUM_LIT:1> ] ) <EOL> for next_run in next_runs : <EOL> self . assertEqual ( <NUM_LIT:3> , len ( next_run ) ) <EOL> for run in next_run : <EOL> datetime . datetime . strptime ( run [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_get_cron_jobs_without_pytz ( self ) : <EOL> cron_handler . pytz = None <EOL> handler = cron_handler . CronHandler ( None , None ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> handler . _parse_cron_yaml ( ) . AndReturn ( CRON_INFO_EXTERNAL ) <EOL> self . mox . ReplayAll ( ) <EOL> cron_jobs = handler . _get_cron_jobs ( ) <EOL> self . mox . VerifyAll ( ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( cron_jobs ) ) <EOL> self . assertEqual ( CRON_INFO_EXTERNAL . cron [ <NUM_LIT:0> ] . ToDict ( ) , cron_jobs [ <NUM_LIT:0> ] ) <EOL> next_run = cron_jobs [ <NUM_LIT:1> ] . pop ( '<STR_LIT>' ) <EOL> self . assertEqual ( CRON_INFO_EXTERNAL . cron [ <NUM_LIT:1> ] . ToDict ( ) , cron_jobs [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( next_run ) ) <EOL> for run in next_run : <EOL> datetime . datetime . strptime ( run [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_get_cron_jobs_no_cron_yaml ( self ) : <EOL> cron_handler . pytz = None <EOL> handler = cron_handler . CronHandler ( None , None ) <EOL> self . mox . StubOutWithMock ( handler , '<STR_LIT>' ) <EOL> handler . _parse_cron_yaml ( ) . AndReturn ( None ) <EOL> self . mox . ReplayAll ( ) <EOL> self . assertEqual ( [ ] , handler . _get_cron_jobs ( ) ) <EOL> self . mox . VerifyAll ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
