def mock_resource_with(filename, resource_type):
 VALID_RESOURCES = ['html', 'txt']
 if (resource_type not in VALID_RESOURCES):
  raise Exception(('Mocked resource must be one of: %s' % ', '.join(VALID_RESOURCES)))
 subfolder = ('text' if (resource_type == 'txt') else 'html')
 resource_path = os.path.join(TEST_DIR, ('data/%s/%s.%s' % (subfolder, filename, resource_type)))
 with open(resource_path, 'r') as f:
  return f.read()

def mock_resource_with ( filename , resource_type ) : VALID_RESOURCES = [ 'html' , 'txt' ] if ( resource_type not in VALID_RESOURCES ) : raise Exception ( ( 'Mocked resource must be one of: %s' % ', ' . join ( VALID_RESOURCES ) ) ) subfolder = ( 'text' if ( resource_type == 'txt' ) else 'html' ) resource_path = os . path . join ( TEST_DIR , ( 'data/%s/%s.%s' % ( subfolder , filename , resource_type ) ) ) with open ( resource_path , 'r' ) as f : return f . read ( )
mocks an http request by pulling text from a pre-downloaded file .