<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import unittest <EOL> from flexmock import flexmock <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> from api_tests import urlfetch <EOL> from common import constants <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ) <EOL> from google . appengine . api import urlfetch as google_urlfetch <EOL> class FakeGoodResponse : <EOL> def __init__ ( self ) : <EOL> self . status_code = constants . HTTP_OK <EOL> class FakeBadResponse : <EOL> def __init__ ( self ) : <EOL> self . status_code = constants . HTTP_NOTFOUND <EOL> class TestUrlfetch ( unittest . TestCase ) : <EOL> def test_fetch ( self ) : <EOL> mock = flexmock ( google_urlfetch ) <EOL> mock . should_receive ( "<STR_LIT>" ) . and_return ( FakeGoodResponse ( ) ) <EOL> results = urlfetch . fetch ( "<STR_LIT>" ) <EOL> self . assertEquals ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:0> ] ) , constants . NUM_SAMPLES ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:1> ] ) , <NUM_LIT:0> ) <EOL> mock . should_receive ( "<STR_LIT>" ) . and_raise ( Exception ( "<STR_LIT>" ) ) <EOL> results = urlfetch . fetch ( "<STR_LIT>" ) <EOL> self . assertEquals ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:0> ] ) , constants . NUM_SAMPLES ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:1> ] ) , constants . NUM_SAMPLES ) <EOL> mock . should_receive ( "<STR_LIT>" ) . and_return ( FakeBadResponse ( ) ) <EOL> results = urlfetch . fetch ( "<STR_LIT>" ) <EOL> self . assertEquals ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:0> ] ) , constants . NUM_SAMPLES ) <EOL> self . assertEquals ( len ( results [ <NUM_LIT:1> ] ) , constants . NUM_SAMPLES ) </s>
