# Path: helpers/google_api.py
# class GoogleAPIException(Exception):
# def oauth2_flow(**kwargs):
# def http_from_oauth2(auth_json):
# def user_info(auth_json):
# def drive_service():
# def list_drive_files(auth_json, query="", page_token=None):
# def get_worksheets(auth_json, spreadsheet_key):
# def get_cell_data(auth_json, spreadsheet_key, worksheet_key, limit=None):
# def create_spreadsheet(auth_json, title=""):
# def create_worksheet(auth_json, spreadsheet_key):
# def save_data(auth_json, spreadsheet_key, worksheet_key, data=[[]]):
# def _key(heading):
# def _val(val):    #::::....|...                       ___(_)
# 
# Path: tests/utils.py
# class MockHttp(object):
#     def __init__(self, cache=None, timeout=None, proxy_info=None, ca_certs=None, disable_ssl_certificate_validation=False):
#         pass
# 
#     def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
# 
#         # Response for oAuth2 Handshake
#         if 'https://accounts.google.com/o/oauth2/token' in uri:
#             return httplib2.Response({'status': '200'}), load_data('oauth2_token.json')
# 
#         # Response for user info API
#         if 'https://www.googleapis.com/oauth2/v2/userinfo' in uri:
#             return httplib2.Response({'status': '200'}), load_data('user_info.json')
# 
#         # Response for Drive API discovery
#         if 'https://www.googleapis.com/discovery/v1/apis/drive/v2/rest' in uri:
#             return httplib2.Response({'status': '200'}), load_data('discovery_drive.json')
# 
#         # Response for files list
#         if 'https://www.googleapis.com/drive/v2/files' in uri:
#             return httplib2.Response({'status': '200'}), load_data('list_files.json')
# 
#         # Response for worksheets list
#         if 'https://spreadsheets.google.com/feeds/worksheets/dummy_key/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets.xml')
# 
#         # Response for worksheets list not found
#         if 'https://spreadsheets.google.com/feeds/worksheets/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_not_found.xml')
# 
#         # Response for worksheets list with bad format
#         if 'https://spreadsheets.google.com/feeds/worksheets/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_bad_format.xml')
# 
#         # Response for worksheet cells
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/dummy_id/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells.xml')
# 
#         # Response for worksheet cells not found
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_not_found.xml')
# 
#         # Response for worksheet cells with bad format
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_bad_format.xml')
# 
#         logging.error("No MockHTTP response for request to '%s'" % uri)
#         return httplib2.Response({}), ''


import os
import unittest
from helpers import google_api
from oauth2client.client import OAuth2WebServerFlow
from tests.utils import MockHttp
# -*- coding: utf-8 -*-


USER_AUTH_JSON="""
{
    "access_token":  "XXX",
    "client_id":     "XXX",
    "client_secret": "XXX",
    "refresh_token": "XXX",
    "token_expiry":  "2015-00-00T00:00:00Z",
    "token_uri":     "http://example.com",

# Path: helpers/google_api.py
# class GoogleAPIException(Exception):
# def oauth2_flow(**kwargs):
# def http_from_oauth2(auth_json):
# def user_info(auth_json):
# def drive_service():
# def list_drive_files(auth_json, query="", page_token=None):
# def get_worksheets(auth_json, spreadsheet_key):
# def get_cell_data(auth_json, spreadsheet_key, worksheet_key, limit=None):
# def create_spreadsheet(auth_json, title=""):
# def create_worksheet(auth_json, spreadsheet_key):
# def save_data(auth_json, spreadsheet_key, worksheet_key, data=[[]]):
# def _key(heading):
# def _val(val):    #::::....|...                       ___(_)
# 
# Path: tests/utils.py
# class MockHttp(object):
#     def __init__(self, cache=None, timeout=None, proxy_info=None, ca_certs=None, disable_ssl_certificate_validation=False):
#         pass
# 
#     def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
# 
#         # Response for oAuth2 Handshake
#         if 'https://accounts.google.com/o/oauth2/token' in uri:
#             return httplib2.Response({'status': '200'}), load_data('oauth2_token.json')
# 
#         # Response for user info API
#         if 'https://www.googleapis.com/oauth2/v2/userinfo' in uri:
#             return httplib2.Response({'status': '200'}), load_data('user_info.json')
# 
#         # Response for Drive API discovery
#         if 'https://www.googleapis.com/discovery/v1/apis/drive/v2/rest' in uri:
#             return httplib2.Response({'status': '200'}), load_data('discovery_drive.json')
# 
#         # Response for files list
#         if 'https://www.googleapis.com/drive/v2/files' in uri:
#             return httplib2.Response({'status': '200'}), load_data('list_files.json')
# 
#         # Response for worksheets list
#         if 'https://spreadsheets.google.com/feeds/worksheets/dummy_key/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets.xml')
# 
#         # Response for worksheets list not found
#         if 'https://spreadsheets.google.com/feeds/worksheets/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_not_found.xml')
# 
#         # Response for worksheets list with bad format
#         if 'https://spreadsheets.google.com/feeds/worksheets/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheets_bad_format.xml')
# 
#         # Response for worksheet cells
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/dummy_id/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells.xml')
# 
#         # Response for worksheet cells not found
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/not_found/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_not_found.xml')
# 
#         # Response for worksheet cells with bad format
#         if 'https://spreadsheets.google.com/feeds/list/dummy_key/bad_format/private/full' in uri:
#             return httplib2.Response({'status': '200'}), load_data('worksheet_cells_bad_format.xml')
# 
#         logging.error("No MockHTTP response for request to '%s'" % uri)
#         return httplib2.Response({}), ''


# Path: tests/test_helpers/test_google_api.py
import os
import unittest
from helpers import google_api
from oauth2client.client import OAuth2WebServerFlow
from tests.utils import MockHttp

# -*- coding: utf-8 -*-


USER_AUTH_JSON="""
{
    "access_token":  "XXX",
    "client_id":     "XXX",
    "client_secret": "XXX",
    "refresh_token": "XXX",
    "token_expiry":  "2015-00-00T00:00:00Z",
    "token_uri":     "http://example.com",

    "user_agent":    "XXX",